Explorar el Código

add sdk-bsp-cy8c624-infineon-evaluationkit

yangjie11 hace 2 años
padre
commit
0b9a368a5c
Se han modificado 100 ficheros con 34703 adiciones y 2 borrados
  1. 67 2
      README.md
  2. BIN
      documents/Infineon-PSOC_6_MCU_CY8C62X8_CY8C62XA-DataSheet-v18_00-EN.pdf
  3. BIN
      documents/images/Infineon.png
  4. BIN
      documents/images/small_20230323101130.png
  5. 1062 0
      project_0/.config
  6. 215 0
      project_0/.cproject
  7. 42 0
      project_0/.gitignore
  8. 28 0
      project_0/.project
  9. 58 0
      project_0/.settings/.OpenOCD.Debug.rttlaunch
  10. 2 0
      project_0/.settings/ilg.gnumcueclipse.managedbuild.cross.arm.prefs
  11. 14 0
      project_0/.settings/language.settings.xml
  12. 3 0
      project_0/.settings/org.eclipse.core.runtime.prefs
  13. 20 0
      project_0/.settings/projcfg.ini
  14. 65 0
      project_0/.settings/project.DAPLink.Debug.rttlaunch
  15. 58 0
      project_0/.settings/project.OpenOCD.Debug.rttlaunch
  16. 65 0
      project_0/.settings/test.DAPLink.Debug.rttlaunch
  17. 58 0
      project_0/.settings/test.Debug.rttlaunch
  18. 58 0
      project_0/.settings/test.OpenOCD.Debug.rttlaunch
  19. 21 0
      project_0/Kconfig
  20. 210 0
      project_0/LICENSE
  21. 104 0
      project_0/README.md
  22. 15 0
      project_0/SConscript
  23. 64 0
      project_0/SConstruct
  24. 16 0
      project_0/applications/SConscript
  25. 29 0
      project_0/applications/main.c
  26. 319 0
      project_0/board/Kconfig
  27. 40 0
      project_0/board/SConscript
  28. 25 0
      project_0/board/board.c
  29. 63 0
      project_0/board/board.h
  30. 247 0
      project_0/board/linker_scripts/link.icf
  31. 487 0
      project_0/board/linker_scripts/link.ld
  32. 277 0
      project_0/board/linker_scripts/link.sct
  33. 67 0
      project_0/board/ports/drv_rw007.c
  34. 37 0
      project_0/board/ports/fal_cfg.h
  35. 244 0
      project_0/board/ports/slider_sample.c
  36. 84 0
      project_0/board/ports/spi_sample.c
  37. BIN
      project_0/figures/board.png
  38. BIN
      project_0/figures/mdk_package.png
  39. BIN
      project_0/figures/studio1.png
  40. BIN
      project_0/figures/studio2.png
  41. BIN
      project_0/figures/studio3-build.png
  42. BIN
      project_0/figures/studio4-download.png
  43. 64 0
      project_0/libraries/HAL_Drivers/SConscript
  44. 135 0
      project_0/libraries/HAL_Drivers/drv_adc.c
  45. 54 0
      project_0/libraries/HAL_Drivers/drv_adc.h
  46. 121 0
      project_0/libraries/HAL_Drivers/drv_common.c
  47. 35 0
      project_0/libraries/HAL_Drivers/drv_common.h
  48. 181 0
      project_0/libraries/HAL_Drivers/drv_dac.c
  49. 59 0
      project_0/libraries/HAL_Drivers/drv_dac.h
  50. 427 0
      project_0/libraries/HAL_Drivers/drv_flash.c
  51. 30 0
      project_0/libraries/HAL_Drivers/drv_flash.h
  52. 341 0
      project_0/libraries/HAL_Drivers/drv_gpio.c
  53. 32 0
      project_0/libraries/HAL_Drivers/drv_gpio.h
  54. 344 0
      project_0/libraries/HAL_Drivers/drv_hwtimer.c
  55. 51 0
      project_0/libraries/HAL_Drivers/drv_hwtimer.h
  56. 174 0
      project_0/libraries/HAL_Drivers/drv_i2c.c
  57. 27 0
      project_0/libraries/HAL_Drivers/drv_log.h
  58. 281 0
      project_0/libraries/HAL_Drivers/drv_pwm.c
  59. 93 0
      project_0/libraries/HAL_Drivers/drv_pwm.h
  60. 167 0
      project_0/libraries/HAL_Drivers/drv_rtc.c
  61. 180 0
      project_0/libraries/HAL_Drivers/drv_soft_i2c.c
  62. 43 0
      project_0/libraries/HAL_Drivers/drv_soft_i2c.h
  63. 255 0
      project_0/libraries/HAL_Drivers/drv_spi.c
  64. 36 0
      project_0/libraries/HAL_Drivers/drv_spi.h
  65. 314 0
      project_0/libraries/HAL_Drivers/drv_uart.c
  66. 42 0
      project_0/libraries/HAL_Drivers/drv_uart.h
  67. 110 0
      project_0/libraries/HAL_Drivers/drv_wdt.c
  68. 31 0
      project_0/libraries/HAL_Drivers/drv_wdt.h
  69. 207 0
      project_0/libraries/HAL_Drivers/uart_config.h
  70. 195 0
      project_0/libraries/IFX_PSOC6_HAL/SConscript
  71. 1 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/.gitignore
  72. BIN
      project_0/libraries/IFX_PSOC6_HAL/capsense/COMPONENT_HARDFP/TOOLCHAIN_ARM/libcy_capsense.ar
  73. BIN
      project_0/libraries/IFX_PSOC6_HAL/capsense/COMPONENT_SOFTFP/TOOLCHAIN_ARM/libcy_capsense.ar
  74. 55 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/LICENSE
  75. 62 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/README.md
  76. 66 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/RELEASE.md
  77. 1229 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense.h
  78. 2333 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_centroid.c
  79. 123 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_centroid.h
  80. 869 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_common.h
  81. 1563 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_control.c
  82. 119 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_control.h
  83. 2151 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_csd_v2.c
  84. 101 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_csd_v2.h
  85. 1410 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_csx_v2.c
  86. 207 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_csx_v2.h
  87. 1006 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_filter.c
  88. 143 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_filter.h
  89. 1247 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_generator_v3.c
  90. 702 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_generator_v3.h
  91. 364 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_gesture_lib.h
  92. 629 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_lib.h
  93. 2226 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_processing.c
  94. 218 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_processing.h
  95. 708 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest.c
  96. 124 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest.h
  97. 4523 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest_v2.c
  98. 179 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest_v2.h
  99. 4007 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest_v3.c
  100. 145 0
      project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest_v3.h

+ 67 - 2
README.md

@@ -1,2 +1,67 @@
-# sdk-bsp-cy8c624-infineon-evaluationkit
-sdk-bsp-cy8c624-infineon-evaluationkit
+# Infineon Psoc6-evaluationkit-062S2 说明
+
+## 简介
+
+本文档为 `RT-Thread` 为 `PSoC6 CY8CKIT-062S2-43012`开发板提供的 BSP (板级支持包) 说明。
+
+主要内容如下:
+
+- 开发板资源介绍
+- BSP 快速上手
+- 进阶使用方法
+
+通过阅读快速上手章节开发者可以快速地上手该 BSP,将 RT-Thread 运行在开发板上。在进阶使用指南章节,将会介绍更多高级功能,帮助开发者利用 `RT-Thread` 驱动更多板载资源。
+
+## 开发板介绍
+
+`Psoc6-evaluationkit-062S2` 是 RT-Thread 联合英飞凌推出的一款集成32位双核CPU子系统( ARM Cortex-M4 和 ARM Cortex-M0)的开发板,其具有单周期乘法的150-MHz Arm Cortex-M4F CPU (浮点和存储器保护单元),100-MHz Cortex M0+ CPU,带单周期乘法和MPU,可以充分发挥 PSoC6 双核芯片性能。
+
+该开发板核心 **板载资源** 如下:
+
+- MCU:CY8C624ABZI-S2D44,Cortex-M4主频 150MHz,Cortex-M0主频 100MHz,2MB Flash 和 1MB SRAM
+      MCU手册更多详细信息请参考文档 [PSoC 6 MCU: CY8C62x8, CY8C62xA Datasheet (infineon.com)](https://www.infineon.com/dgdl/Infineon-PSOC_6_MCU_CY8C62X8_CY8C62XA-DataSheet-v17_00-EN.pdf?fileId=8ac78c8c7d0d8da4017d0ee7d03a70b1)
+- 板载资源:microSD card , 触摸滑条,Arduino 接口
+- 开发环境:ModusToolbox 2.0/MDK V5
+  	PSoC® Creator™ 下载链接 [ModusToolbox™ Software - Infineon Technologies](https://www.infineon.com/cms/en/design-support/tools/sdk/modustoolbox-software/)
+
+## 外设支持
+
+本 BSP 目前对外设的支持情况如下:
+
+| **片上外设** | **支持情况** | **备注** |
+| :----------: | :----------: | :------: |
+|  USB 转串口  |     支持     |  UART0   |
+|     GPIO     |     支持     |    —     |
+|     UART     |     支持     | UART0-5  |
+|    Touch     |     支持     | 触摸滑条 |
+
+## 使用 RT-Thread Studio 开发
+
+在 RT-Thread Studio 的 SDK 管理器中安装该 BSP 资源包,然后基于该资源包新建工程。
+
+### 编译下载
+
+* 点击 IDE 左上角的构建选项进行工程的编译。
+
+  ![](project_0\figures\studio3-build.png)
+
+* 当编译无错误警告时,点击 `Debug` 或 `Download` 选项进行调试/下载。
+
+  注:若点击下载并下载成功后串口终端无显示信息,请手动按下复位按键进行重启运行。
+
+  ![](project_0\figures\studio4-download.png)
+
+### 运行结果
+
+下载程序成功之后,系统会自动运行。打开终端工具串口助手,选择波特率为 115200。复位设备后,LED 将会以 500HZ 的频率闪烁,而且在终端上可以看到 `RT-Thread` 的输出信息:
+
+注:推荐使用串口调试助手如:`MobaXterm`
+
+```
+ \ | /
+- RT -     Thread Operating System
+ / | \     4.1.1 build Jul 25 2022 18:03:35
+ 2006 - 2022 Copyright by RT-Thread team
+msh >
+```
+

BIN
documents/Infineon-PSOC_6_MCU_CY8C62X8_CY8C62XA-DataSheet-v18_00-EN.pdf


BIN
documents/images/Infineon.png


BIN
documents/images/small_20230323101130.png


+ 1062 - 0
project_0/.config

@@ -0,0 +1,1062 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# RT-Thread Configuration
+#
+
+#
+# RT-Thread Kernel
+#
+CONFIG_RT_NAME_MAX=8
+# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
+# CONFIG_RT_USING_SMART is not set
+# CONFIG_RT_USING_SMP is not set
+CONFIG_RT_ALIGN_SIZE=8
+# CONFIG_RT_THREAD_PRIORITY_8 is not set
+CONFIG_RT_THREAD_PRIORITY_32=y
+# CONFIG_RT_THREAD_PRIORITY_256 is not set
+CONFIG_RT_THREAD_PRIORITY_MAX=32
+CONFIG_RT_TICK_PER_SECOND=1000
+CONFIG_RT_USING_OVERFLOW_CHECK=y
+CONFIG_RT_USING_HOOK=y
+CONFIG_RT_HOOK_USING_FUNC_PTR=y
+CONFIG_RT_USING_IDLE_HOOK=y
+CONFIG_RT_IDLE_HOOK_LIST_SIZE=4
+CONFIG_IDLE_THREAD_STACK_SIZE=256
+CONFIG_RT_USING_TIMER_SOFT=y
+CONFIG_RT_TIMER_THREAD_PRIO=4
+CONFIG_RT_TIMER_THREAD_STACK_SIZE=512
+
+#
+# kservice optimization
+#
+CONFIG_RT_KSERVICE_USING_STDLIB=y
+# CONFIG_RT_KSERVICE_USING_STDLIB_MEMORY is not set
+# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
+# CONFIG_RT_USING_TINY_FFS is not set
+# CONFIG_RT_KPRINTF_USING_LONGLONG is not set
+CONFIG_RT_DEBUG=y
+# CONFIG_RT_DEBUG_COLOR is not set
+# CONFIG_RT_DEBUG_INIT_CONFIG is not set
+# CONFIG_RT_DEBUG_THREAD_CONFIG is not set
+# CONFIG_RT_DEBUG_SCHEDULER_CONFIG is not set
+# CONFIG_RT_DEBUG_IPC_CONFIG is not set
+# CONFIG_RT_DEBUG_TIMER_CONFIG is not set
+# CONFIG_RT_DEBUG_IRQ_CONFIG is not set
+# CONFIG_RT_DEBUG_MEM_CONFIG is not set
+# CONFIG_RT_DEBUG_SLAB_CONFIG is not set
+# CONFIG_RT_DEBUG_MEMHEAP_CONFIG is not set
+# CONFIG_RT_DEBUG_MODULE_CONFIG is not set
+
+#
+# Inter-Thread communication
+#
+CONFIG_RT_USING_SEMAPHORE=y
+CONFIG_RT_USING_MUTEX=y
+CONFIG_RT_USING_EVENT=y
+CONFIG_RT_USING_MAILBOX=y
+CONFIG_RT_USING_MESSAGEQUEUE=y
+# CONFIG_RT_USING_SIGNALS is not set
+
+#
+# Memory Management
+#
+CONFIG_RT_PAGE_MAX_ORDER=11
+CONFIG_RT_USING_MEMPOOL=y
+CONFIG_RT_USING_SMALL_MEM=y
+# CONFIG_RT_USING_SLAB is not set
+# CONFIG_RT_USING_MEMHEAP is not set
+CONFIG_RT_USING_SMALL_MEM_AS_HEAP=y
+# CONFIG_RT_USING_MEMHEAP_AS_HEAP is not set
+# CONFIG_RT_USING_SLAB_AS_HEAP is not set
+# CONFIG_RT_USING_USERHEAP is not set
+# CONFIG_RT_USING_NOHEAP is not set
+# CONFIG_RT_USING_MEMTRACE is not set
+# CONFIG_RT_USING_HEAP_ISR is not set
+CONFIG_RT_USING_HEAP=y
+
+#
+# Kernel Device Object
+#
+CONFIG_RT_USING_DEVICE=y
+# CONFIG_RT_USING_DEVICE_OPS is not set
+# CONFIG_RT_USING_DM is not set
+# CONFIG_RT_USING_INTERRUPT_INFO is not set
+CONFIG_RT_USING_CONSOLE=y
+CONFIG_RT_CONSOLEBUF_SIZE=128
+CONFIG_RT_CONSOLE_DEVICE_NAME="uart6"
+CONFIG_RT_VER_NUM=0x50000
+# CONFIG_RT_USING_CACHE is not set
+# CONFIG_ARCH_ARM_BOOTWITH_FLUSH_CACHE is not set
+# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
+CONFIG_RT_USING_CPU_FFS=y
+CONFIG_ARCH_ARM=y
+CONFIG_ARCH_ARM_CORTEX_M=y
+CONFIG_ARCH_ARM_CORTEX_M4=y
+
+#
+# RT-Thread Components
+#
+CONFIG_RT_USING_COMPONENTS_INIT=y
+CONFIG_RT_USING_USER_MAIN=y
+CONFIG_RT_MAIN_THREAD_STACK_SIZE=2048
+CONFIG_RT_MAIN_THREAD_PRIORITY=10
+# CONFIG_RT_USING_LEGACY is not set
+CONFIG_RT_USING_MSH=y
+CONFIG_RT_USING_FINSH=y
+CONFIG_FINSH_USING_MSH=y
+CONFIG_FINSH_THREAD_NAME="tshell"
+CONFIG_FINSH_THREAD_PRIORITY=20
+CONFIG_FINSH_THREAD_STACK_SIZE=4096
+CONFIG_FINSH_USING_HISTORY=y
+CONFIG_FINSH_HISTORY_LINES=5
+CONFIG_FINSH_USING_SYMTAB=y
+CONFIG_FINSH_CMD_SIZE=80
+CONFIG_MSH_USING_BUILT_IN_COMMANDS=y
+CONFIG_FINSH_USING_DESCRIPTION=y
+# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
+# CONFIG_FINSH_USING_AUTH is not set
+CONFIG_FINSH_ARG_MAX=10
+# CONFIG_RT_USING_DFS is not set
+# CONFIG_RT_USING_FAL is not set
+
+#
+# Device Drivers
+#
+CONFIG_RT_USING_DEVICE_IPC=y
+CONFIG_RT_UNAMED_PIPE_NUMBER=64
+# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
+CONFIG_RT_USING_SERIAL=y
+CONFIG_RT_USING_SERIAL_V1=y
+# CONFIG_RT_USING_SERIAL_V2 is not set
+CONFIG_RT_SERIAL_USING_DMA=y
+CONFIG_RT_SERIAL_RB_BUFSZ=64
+# CONFIG_RT_USING_CAN is not set
+# CONFIG_RT_USING_HWTIMER is not set
+# CONFIG_RT_USING_CPUTIME is not set
+# CONFIG_RT_USING_I2C is not set
+# CONFIG_RT_USING_PHY is not set
+CONFIG_RT_USING_PIN=y
+# CONFIG_RT_USING_ADC is not set
+# CONFIG_RT_USING_DAC is not set
+# CONFIG_RT_USING_NULL is not set
+# CONFIG_RT_USING_ZERO is not set
+# CONFIG_RT_USING_RANDOM is not set
+# CONFIG_RT_USING_PWM is not set
+# CONFIG_RT_USING_MTD_NOR is not set
+# CONFIG_RT_USING_MTD_NAND is not set
+# CONFIG_RT_USING_PM is not set
+# CONFIG_RT_USING_FDT is not set
+# CONFIG_RT_USING_RTC is not set
+# CONFIG_RT_USING_SDIO is not set
+# CONFIG_RT_USING_SPI is not set
+# CONFIG_RT_USING_WDT is not set
+# CONFIG_RT_USING_AUDIO is not set
+# CONFIG_RT_USING_SENSOR is not set
+# CONFIG_RT_USING_TOUCH is not set
+# CONFIG_RT_USING_LCD is not set
+# CONFIG_RT_USING_HWCRYPTO is not set
+# CONFIG_RT_USING_PULSE_ENCODER is not set
+# CONFIG_RT_USING_INPUT_CAPTURE is not set
+# CONFIG_RT_USING_DEV_BUS is not set
+# CONFIG_RT_USING_WIFI is not set
+# CONFIG_RT_USING_VIRTIO is not set
+
+#
+# Using USB
+#
+# CONFIG_RT_USING_USB is not set
+# CONFIG_RT_USING_USB_HOST is not set
+# CONFIG_RT_USING_USB_DEVICE is not set
+
+#
+# C/C++ and POSIX layer
+#
+CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8
+
+#
+# POSIX (Portable Operating System Interface) layer
+#
+# CONFIG_RT_USING_POSIX_FS is not set
+# CONFIG_RT_USING_POSIX_DELAY is not set
+# CONFIG_RT_USING_POSIX_CLOCK is not set
+# CONFIG_RT_USING_POSIX_TIMER is not set
+# CONFIG_RT_USING_PTHREADS is not set
+# CONFIG_RT_USING_MODULE is not set
+
+#
+# Interprocess Communication (IPC)
+#
+# CONFIG_RT_USING_POSIX_PIPE is not set
+# CONFIG_RT_USING_POSIX_MESSAGE_QUEUE is not set
+# CONFIG_RT_USING_POSIX_MESSAGE_SEMAPHORE is not set
+
+#
+# Socket is in the 'Network' category
+#
+# CONFIG_RT_USING_CPLUSPLUS is not set
+
+#
+# Network
+#
+# CONFIG_RT_USING_SAL is not set
+# CONFIG_RT_USING_NETDEV is not set
+# CONFIG_RT_USING_LWIP is not set
+# CONFIG_RT_USING_AT is not set
+
+#
+# Utilities
+#
+# CONFIG_RT_USING_RYM is not set
+# CONFIG_RT_USING_ULOG is not set
+# CONFIG_RT_USING_UTEST is not set
+# CONFIG_RT_USING_VAR_EXPORT is not set
+# CONFIG_RT_USING_ADT is not set
+# CONFIG_RT_USING_RT_LINK is not set
+# CONFIG_RT_USING_VBUS is not set
+
+#
+# RT-Thread Utestcases
+#
+# CONFIG_RT_USING_UTESTCASES is not set
+
+#
+# RT-Thread online packages
+#
+
+#
+# IoT - internet of things
+#
+# CONFIG_PKG_USING_LWIP is not set
+# CONFIG_PKG_USING_LORAWAN_DRIVER is not set
+# CONFIG_PKG_USING_PAHOMQTT is not set
+# CONFIG_PKG_USING_UMQTT is not set
+# CONFIG_PKG_USING_WEBCLIENT is not set
+# CONFIG_PKG_USING_WEBNET is not set
+# CONFIG_PKG_USING_MONGOOSE is not set
+# CONFIG_PKG_USING_MYMQTT is not set
+# CONFIG_PKG_USING_KAWAII_MQTT is not set
+# CONFIG_PKG_USING_BC28_MQTT is not set
+# CONFIG_PKG_USING_WEBTERMINAL is not set
+# CONFIG_PKG_USING_LIBMODBUS is not set
+# CONFIG_PKG_USING_FREEMODBUS is not set
+# CONFIG_PKG_USING_NANOPB is not set
+
+#
+# Wi-Fi
+#
+
+#
+# Marvell WiFi
+#
+# CONFIG_PKG_USING_WLANMARVELL is not set
+
+#
+# Wiced WiFi
+#
+# CONFIG_PKG_USING_WLAN_WICED is not set
+# CONFIG_PKG_USING_RW007 is not set
+# CONFIG_PKG_USING_COAP is not set
+# CONFIG_PKG_USING_NOPOLL is not set
+# CONFIG_PKG_USING_NETUTILS is not set
+# CONFIG_PKG_USING_CMUX is not set
+# CONFIG_PKG_USING_PPP_DEVICE is not set
+# CONFIG_PKG_USING_AT_DEVICE is not set
+# CONFIG_PKG_USING_ATSRV_SOCKET is not set
+# CONFIG_PKG_USING_WIZNET is not set
+# CONFIG_PKG_USING_ZB_COORDINATOR is not set
+
+#
+# IoT Cloud
+#
+# CONFIG_PKG_USING_ONENET is not set
+# CONFIG_PKG_USING_GAGENT_CLOUD is not set
+# CONFIG_PKG_USING_ALI_IOTKIT is not set
+# CONFIG_PKG_USING_AZURE is not set
+# CONFIG_PKG_USING_TENCENT_IOT_EXPLORER is not set
+# CONFIG_PKG_USING_JIOT-C-SDK is not set
+# CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set
+# CONFIG_PKG_USING_JOYLINK is not set
+# CONFIG_PKG_USING_EZ_IOT_OS is not set
+# CONFIG_PKG_USING_IOTSHARP_SDK is not set
+# CONFIG_PKG_USING_NIMBLE is not set
+# CONFIG_PKG_USING_LLSYNC_SDK_ADAPTER is not set
+# CONFIG_PKG_USING_OTA_DOWNLOADER is not set
+# CONFIG_PKG_USING_IPMSG is not set
+# CONFIG_PKG_USING_LSSDP is not set
+# CONFIG_PKG_USING_AIRKISS_OPEN is not set
+# CONFIG_PKG_USING_LIBRWS is not set
+# CONFIG_PKG_USING_TCPSERVER is not set
+# CONFIG_PKG_USING_PROTOBUF_C is not set
+# CONFIG_PKG_USING_DLT645 is not set
+# CONFIG_PKG_USING_QXWZ is not set
+# CONFIG_PKG_USING_SMTP_CLIENT is not set
+# CONFIG_PKG_USING_ABUP_FOTA is not set
+# CONFIG_PKG_USING_LIBCURL2RTT is not set
+# CONFIG_PKG_USING_CAPNP is not set
+# CONFIG_PKG_USING_AGILE_TELNET is not set
+# CONFIG_PKG_USING_NMEALIB is not set
+# CONFIG_PKG_USING_PDULIB is not set
+# CONFIG_PKG_USING_BTSTACK is not set
+# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
+# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
+# CONFIG_PKG_USING_MAVLINK is not set
+# CONFIG_PKG_USING_BSAL is not set
+# CONFIG_PKG_USING_AGILE_MODBUS is not set
+# CONFIG_PKG_USING_AGILE_FTP is not set
+# CONFIG_PKG_USING_EMBEDDEDPROTO is not set
+# CONFIG_PKG_USING_RT_LINK_HW is not set
+# CONFIG_PKG_USING_RYANMQTT is not set
+# CONFIG_PKG_USING_RYANW5500 is not set
+# CONFIG_PKG_USING_LORA_PKT_FWD is not set
+# CONFIG_PKG_USING_LORA_GW_DRIVER_LIB is not set
+# CONFIG_PKG_USING_LORA_PKT_SNIFFER is not set
+# CONFIG_PKG_USING_HM is not set
+# CONFIG_PKG_USING_SMALL_MODBUS is not set
+# CONFIG_PKG_USING_NET_SERVER is not set
+# CONFIG_PKG_USING_ZFTP is not set
+# CONFIG_PKG_USING_WOL is not set
+
+#
+# security packages
+#
+# CONFIG_PKG_USING_MBEDTLS is not set
+# CONFIG_PKG_USING_LIBSODIUM is not set
+# CONFIG_PKG_USING_LIBHYDROGEN is not set
+# CONFIG_PKG_USING_TINYCRYPT is not set
+# CONFIG_PKG_USING_TFM is not set
+# CONFIG_PKG_USING_YD_CRYPTO is not set
+
+#
+# language packages
+#
+
+#
+# JSON: JavaScript Object Notation, a lightweight data-interchange format
+#
+# CONFIG_PKG_USING_CJSON is not set
+# CONFIG_PKG_USING_LJSON is not set
+# CONFIG_PKG_USING_RT_CJSON_TOOLS is not set
+# CONFIG_PKG_USING_RAPIDJSON is not set
+# CONFIG_PKG_USING_JSMN is not set
+# CONFIG_PKG_USING_AGILE_JSMN is not set
+# CONFIG_PKG_USING_PARSON is not set
+
+#
+# XML: Extensible Markup Language
+#
+# CONFIG_PKG_USING_SIMPLE_XML is not set
+# CONFIG_PKG_USING_EZXML is not set
+# CONFIG_PKG_USING_LUATOS_SOC is not set
+# CONFIG_PKG_USING_LUA is not set
+# CONFIG_PKG_USING_JERRYSCRIPT is not set
+# CONFIG_PKG_USING_MICROPYTHON is not set
+# CONFIG_PKG_USING_PIKASCRIPT is not set
+# CONFIG_PKG_USING_RTT_RUST is not set
+
+#
+# multimedia packages
+#
+
+#
+# LVGL: powerful and easy-to-use embedded GUI library
+#
+# CONFIG_PKG_USING_LVGL is not set
+# CONFIG_PKG_USING_LITTLEVGL2RTT is not set
+# CONFIG_PKG_USING_LV_MUSIC_DEMO is not set
+# CONFIG_PKG_USING_GUI_GUIDER_DEMO is not set
+
+#
+# u8g2: a monochrome graphic library
+#
+# CONFIG_PKG_USING_U8G2_OFFICIAL is not set
+# CONFIG_PKG_USING_U8G2 is not set
+# CONFIG_PKG_USING_OPENMV is not set
+# CONFIG_PKG_USING_MUPDF is not set
+# CONFIG_PKG_USING_STEMWIN is not set
+# CONFIG_PKG_USING_WAVPLAYER is not set
+# CONFIG_PKG_USING_TJPGD is not set
+# CONFIG_PKG_USING_PDFGEN is not set
+# CONFIG_PKG_USING_HELIX is not set
+# CONFIG_PKG_USING_AZUREGUIX is not set
+# CONFIG_PKG_USING_TOUCHGFX2RTT is not set
+# CONFIG_PKG_USING_NUEMWIN is not set
+# CONFIG_PKG_USING_MP3PLAYER is not set
+# CONFIG_PKG_USING_TINYJPEG is not set
+# CONFIG_PKG_USING_UGUI is not set
+
+#
+# PainterEngine: A cross-platform graphics application framework written in C language
+#
+# CONFIG_PKG_USING_PAINTERENGINE is not set
+# CONFIG_PKG_USING_PAINTERENGINE_AUX is not set
+# CONFIG_PKG_USING_MCURSES is not set
+# CONFIG_PKG_USING_TERMBOX is not set
+# CONFIG_PKG_USING_VT100 is not set
+# CONFIG_PKG_USING_QRCODE is not set
+# CONFIG_PKG_USING_GUIENGINE is not set
+# CONFIG_PKG_USING_PERSIMMON is not set
+
+#
+# tools packages
+#
+# CONFIG_PKG_USING_CMBACKTRACE is not set
+# CONFIG_PKG_USING_EASYFLASH is not set
+# CONFIG_PKG_USING_EASYLOGGER is not set
+# CONFIG_PKG_USING_SYSTEMVIEW is not set
+# CONFIG_PKG_USING_SEGGER_RTT is not set
+# CONFIG_PKG_USING_RTT_AUTO_EXE_CMD is not set
+# CONFIG_PKG_USING_RDB is not set
+# CONFIG_PKG_USING_ULOG_EASYFLASH is not set
+# CONFIG_PKG_USING_LOGMGR is not set
+# CONFIG_PKG_USING_ADBD is not set
+# CONFIG_PKG_USING_COREMARK is not set
+# CONFIG_PKG_USING_DHRYSTONE is not set
+# CONFIG_PKG_USING_MEMORYPERF is not set
+# CONFIG_PKG_USING_NR_MICRO_SHELL is not set
+# CONFIG_PKG_USING_CHINESE_FONT_LIBRARY is not set
+# CONFIG_PKG_USING_LUNAR_CALENDAR is not set
+# CONFIG_PKG_USING_BS8116A is not set
+# CONFIG_PKG_USING_GPS_RMC is not set
+# CONFIG_PKG_USING_URLENCODE is not set
+# CONFIG_PKG_USING_UMCN is not set
+# CONFIG_PKG_USING_LWRB2RTT is not set
+# CONFIG_PKG_USING_CPU_USAGE is not set
+# CONFIG_PKG_USING_GBK2UTF8 is not set
+# CONFIG_PKG_USING_VCONSOLE is not set
+# CONFIG_PKG_USING_KDB is not set
+# CONFIG_PKG_USING_WAMR is not set
+# CONFIG_PKG_USING_MICRO_XRCE_DDS_CLIENT is not set
+# CONFIG_PKG_USING_LWLOG is not set
+# CONFIG_PKG_USING_ANV_TRACE is not set
+# CONFIG_PKG_USING_ANV_MEMLEAK is not set
+# CONFIG_PKG_USING_ANV_TESTSUIT is not set
+# CONFIG_PKG_USING_ANV_BENCH is not set
+# CONFIG_PKG_USING_DEVMEM is not set
+# CONFIG_PKG_USING_REGEX is not set
+# CONFIG_PKG_USING_MEM_SANDBOX is not set
+# CONFIG_PKG_USING_SOLAR_TERMS is not set
+# CONFIG_PKG_USING_GAN_ZHI is not set
+# CONFIG_PKG_USING_FDT is not set
+# CONFIG_PKG_USING_CBOX is not set
+# CONFIG_PKG_USING_SNOWFLAKE is not set
+# CONFIG_PKG_USING_HASH_MATCH is not set
+# CONFIG_PKG_USING_ARMV7M_DWT_TOOL is not set
+# CONFIG_PKG_USING_VOFA_PLUS is not set
+
+#
+# system packages
+#
+
+#
+# enhanced kernel services
+#
+# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
+# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
+# CONFIG_PKG_USING_RT_VSNPRINTF_FULL is not set
+
+#
+# acceleration: Assembly language or algorithmic acceleration packages
+#
+# CONFIG_PKG_USING_QFPLIB_M0_FULL is not set
+# CONFIG_PKG_USING_QFPLIB_M0_TINY is not set
+# CONFIG_PKG_USING_QFPLIB_M3 is not set
+
+#
+# CMSIS: ARM Cortex-M Microcontroller Software Interface Standard
+#
+# CONFIG_PKG_USING_CMSIS_5 is not set
+# CONFIG_PKG_USING_CMSIS_RTOS1 is not set
+# CONFIG_PKG_USING_CMSIS_RTOS2 is not set
+
+#
+# Micrium: Micrium software products porting for RT-Thread
+#
+# CONFIG_PKG_USING_UCOSIII_WRAPPER is not set
+# CONFIG_PKG_USING_UCOSII_WRAPPER is not set
+# CONFIG_PKG_USING_UC_CRC is not set
+# CONFIG_PKG_USING_UC_CLK is not set
+# CONFIG_PKG_USING_UC_COMMON is not set
+# CONFIG_PKG_USING_UC_MODBUS is not set
+# CONFIG_PKG_USING_FREERTOS_WRAPPER is not set
+# CONFIG_PKG_USING_CAIRO is not set
+# CONFIG_PKG_USING_PIXMAN is not set
+# CONFIG_PKG_USING_PARTITION is not set
+# CONFIG_PKG_USING_PERF_COUNTER is not set
+# CONFIG_PKG_USING_FLASHDB is not set
+# CONFIG_PKG_USING_SQLITE is not set
+# CONFIG_PKG_USING_RTI is not set
+# CONFIG_PKG_USING_DFS_YAFFS is not set
+# CONFIG_PKG_USING_LITTLEFS is not set
+# CONFIG_PKG_USING_DFS_JFFS2 is not set
+# CONFIG_PKG_USING_DFS_UFFS is not set
+# CONFIG_PKG_USING_LWEXT4 is not set
+# CONFIG_PKG_USING_THREAD_POOL is not set
+# CONFIG_PKG_USING_ROBOTS is not set
+# CONFIG_PKG_USING_EV is not set
+# CONFIG_PKG_USING_SYSWATCH is not set
+# CONFIG_PKG_USING_SYS_LOAD_MONITOR is not set
+# CONFIG_PKG_USING_PLCCORE is not set
+# CONFIG_PKG_USING_RAMDISK is not set
+# CONFIG_PKG_USING_MININI is not set
+# CONFIG_PKG_USING_QBOOT is not set
+# CONFIG_PKG_USING_PPOOL is not set
+# CONFIG_PKG_USING_OPENAMP is not set
+# CONFIG_PKG_USING_LPM is not set
+# CONFIG_PKG_USING_TLSF is not set
+# CONFIG_PKG_USING_EVENT_RECORDER is not set
+# CONFIG_PKG_USING_ARM_2D is not set
+# CONFIG_PKG_USING_MCUBOOT is not set
+# CONFIG_PKG_USING_TINYUSB is not set
+# CONFIG_PKG_USING_CHERRYUSB is not set
+# CONFIG_PKG_USING_KMULTI_RTIMER is not set
+# CONFIG_PKG_USING_TFDB is not set
+# CONFIG_PKG_USING_QPC is not set
+# CONFIG_PKG_USING_AGILE_UPGRADE is not set
+# CONFIG_PKG_USING_FLASH_BLOB is not set
+
+#
+# peripheral libraries and drivers
+#
+
+#
+# sensors drivers
+#
+# CONFIG_PKG_USING_LSM6DSM is not set
+# CONFIG_PKG_USING_LSM6DSL is not set
+# CONFIG_PKG_USING_LPS22HB is not set
+# CONFIG_PKG_USING_HTS221 is not set
+# CONFIG_PKG_USING_LSM303AGR is not set
+# CONFIG_PKG_USING_BME280 is not set
+# CONFIG_PKG_USING_BME680 is not set
+# CONFIG_PKG_USING_BMA400 is not set
+# CONFIG_PKG_USING_BMI160_BMX160 is not set
+# CONFIG_PKG_USING_SPL0601 is not set
+# CONFIG_PKG_USING_MS5805 is not set
+# CONFIG_PKG_USING_DA270 is not set
+# CONFIG_PKG_USING_DF220 is not set
+# CONFIG_PKG_USING_HSHCAL001 is not set
+# CONFIG_PKG_USING_BH1750 is not set
+# CONFIG_PKG_USING_MPU6XXX is not set
+# CONFIG_PKG_USING_AHT10 is not set
+# CONFIG_PKG_USING_AP3216C is not set
+# CONFIG_PKG_USING_TSL4531 is not set
+# CONFIG_PKG_USING_DS18B20 is not set
+# CONFIG_PKG_USING_DHT11 is not set
+# CONFIG_PKG_USING_DHTXX is not set
+# CONFIG_PKG_USING_GY271 is not set
+# CONFIG_PKG_USING_GP2Y10 is not set
+# CONFIG_PKG_USING_SGP30 is not set
+# CONFIG_PKG_USING_HDC1000 is not set
+# CONFIG_PKG_USING_BMP180 is not set
+# CONFIG_PKG_USING_BMP280 is not set
+# CONFIG_PKG_USING_SHTC1 is not set
+# CONFIG_PKG_USING_BMI088 is not set
+# CONFIG_PKG_USING_HMC5883 is not set
+# CONFIG_PKG_USING_MAX6675 is not set
+# CONFIG_PKG_USING_TMP1075 is not set
+# CONFIG_PKG_USING_SR04 is not set
+# CONFIG_PKG_USING_CCS811 is not set
+# CONFIG_PKG_USING_PMSXX is not set
+# CONFIG_PKG_USING_RT3020 is not set
+# CONFIG_PKG_USING_MLX90632 is not set
+# CONFIG_PKG_USING_MLX90393 is not set
+# CONFIG_PKG_USING_MLX90392 is not set
+# CONFIG_PKG_USING_MLX90397 is not set
+# CONFIG_PKG_USING_MS5611 is not set
+# CONFIG_PKG_USING_MAX31865 is not set
+# CONFIG_PKG_USING_VL53L0X is not set
+# CONFIG_PKG_USING_INA260 is not set
+# CONFIG_PKG_USING_MAX30102 is not set
+# CONFIG_PKG_USING_INA226 is not set
+# CONFIG_PKG_USING_LIS2DH12 is not set
+# CONFIG_PKG_USING_HS300X is not set
+# CONFIG_PKG_USING_ZMOD4410 is not set
+# CONFIG_PKG_USING_ISL29035 is not set
+# CONFIG_PKG_USING_MMC3680KJ is not set
+# CONFIG_PKG_USING_QMP6989 is not set
+# CONFIG_PKG_USING_BALANCE is not set
+# CONFIG_PKG_USING_SHT2X is not set
+# CONFIG_PKG_USING_SHT3X is not set
+# CONFIG_PKG_USING_AD7746 is not set
+# CONFIG_PKG_USING_ADT74XX is not set
+# CONFIG_PKG_USING_MAX17048 is not set
+# CONFIG_PKG_USING_AS7341 is not set
+# CONFIG_PKG_USING_CW2015 is not set
+# CONFIG_PKG_USING_ICM20608 is not set
+# CONFIG_PKG_USING_PAJ7620 is not set
+# CONFIG_PKG_USING_STHS34PF80 is not set
+
+#
+# touch drivers
+#
+# CONFIG_PKG_USING_GT9147 is not set
+# CONFIG_PKG_USING_GT1151 is not set
+# CONFIG_PKG_USING_GT917S is not set
+# CONFIG_PKG_USING_GT911 is not set
+# CONFIG_PKG_USING_FT6206 is not set
+# CONFIG_PKG_USING_FT5426 is not set
+# CONFIG_PKG_USING_FT6236 is not set
+# CONFIG_PKG_USING_XPT2046_TOUCH is not set
+# CONFIG_PKG_USING_REALTEK_AMEBA is not set
+# CONFIG_PKG_USING_STM32_SDIO is not set
+# CONFIG_PKG_USING_ESP_IDF is not set
+# CONFIG_PKG_USING_BUTTON is not set
+# CONFIG_PKG_USING_PCF8574 is not set
+# CONFIG_PKG_USING_SX12XX is not set
+# CONFIG_PKG_USING_SIGNAL_LED is not set
+# CONFIG_PKG_USING_LEDBLINK is not set
+# CONFIG_PKG_USING_LITTLED is not set
+# CONFIG_PKG_USING_LKDGUI is not set
+# CONFIG_PKG_USING_NRF5X_SDK is not set
+# CONFIG_PKG_USING_NRFX is not set
+# CONFIG_PKG_USING_WM_LIBRARIES is not set
+
+#
+# Kendryte SDK
+#
+# CONFIG_PKG_USING_K210_SDK is not set
+# CONFIG_PKG_USING_KENDRYTE_SDK is not set
+# CONFIG_PKG_USING_INFRARED is not set
+# CONFIG_PKG_USING_MULTI_INFRARED is not set
+# CONFIG_PKG_USING_AGILE_BUTTON is not set
+# CONFIG_PKG_USING_AGILE_LED is not set
+# CONFIG_PKG_USING_AT24CXX is not set
+# CONFIG_PKG_USING_MOTIONDRIVER2RTT is not set
+# CONFIG_PKG_USING_PCA9685 is not set
+# CONFIG_PKG_USING_I2C_TOOLS is not set
+# CONFIG_PKG_USING_NRF24L01 is not set
+# CONFIG_PKG_USING_RPLIDAR is not set
+# CONFIG_PKG_USING_AS608 is not set
+# CONFIG_PKG_USING_RC522 is not set
+# CONFIG_PKG_USING_WS2812B is not set
+# CONFIG_PKG_USING_EMBARC_BSP is not set
+# CONFIG_PKG_USING_EXTERN_RTC_DRIVERS is not set
+# CONFIG_PKG_USING_MULTI_RTIMER is not set
+# CONFIG_PKG_USING_MAX7219 is not set
+# CONFIG_PKG_USING_BEEP is not set
+# CONFIG_PKG_USING_EASYBLINK is not set
+# CONFIG_PKG_USING_PMS_SERIES is not set
+# CONFIG_PKG_USING_CAN_YMODEM is not set
+# CONFIG_PKG_USING_LORA_RADIO_DRIVER is not set
+# CONFIG_PKG_USING_QLED is not set
+# CONFIG_PKG_USING_AGILE_CONSOLE is not set
+# CONFIG_PKG_USING_LD3320 is not set
+# CONFIG_PKG_USING_WK2124 is not set
+# CONFIG_PKG_USING_LY68L6400 is not set
+# CONFIG_PKG_USING_DM9051 is not set
+# CONFIG_PKG_USING_SSD1306 is not set
+# CONFIG_PKG_USING_QKEY is not set
+# CONFIG_PKG_USING_RS485 is not set
+# CONFIG_PKG_USING_RS232 is not set
+# CONFIG_PKG_USING_NES is not set
+# CONFIG_PKG_USING_VIRTUAL_SENSOR is not set
+# CONFIG_PKG_USING_VDEVICE is not set
+# CONFIG_PKG_USING_SGM706 is not set
+# CONFIG_PKG_USING_STM32WB55_SDK is not set
+# CONFIG_PKG_USING_RDA58XX is not set
+# CONFIG_PKG_USING_LIBNFC is not set
+# CONFIG_PKG_USING_MFOC is not set
+# CONFIG_PKG_USING_TMC51XX is not set
+# CONFIG_PKG_USING_TCA9534 is not set
+# CONFIG_PKG_USING_KOBUKI is not set
+# CONFIG_PKG_USING_ROSSERIAL is not set
+# CONFIG_PKG_USING_MICRO_ROS is not set
+# CONFIG_PKG_USING_MCP23008 is not set
+# CONFIG_PKG_USING_BLUETRUM_SDK is not set
+# CONFIG_PKG_USING_MISAKA_AT24CXX is not set
+# CONFIG_PKG_USING_MISAKA_RGB_BLING is not set
+# CONFIG_PKG_USING_LORA_MODEM_DRIVER is not set
+# CONFIG_PKG_USING_BL_MCU_SDK is not set
+# CONFIG_PKG_USING_SOFT_SERIAL is not set
+# CONFIG_PKG_USING_MB85RS16 is not set
+# CONFIG_PKG_USING_RFM300 is not set
+# CONFIG_PKG_USING_IO_INPUT_FILTER is not set
+# CONFIG_PKG_USING_RASPBERRYPI_PICO_SDK is not set
+# CONFIG_PKG_USING_LRF_NV7LIDAR is not set
+# CONFIG_PKG_USING_FINGERPRINT is not set
+
+#
+# AI packages
+#
+# CONFIG_PKG_USING_LIBANN is not set
+# CONFIG_PKG_USING_NNOM is not set
+# CONFIG_PKG_USING_ONNX_BACKEND is not set
+# CONFIG_PKG_USING_ONNX_PARSER is not set
+# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
+# CONFIG_PKG_USING_ELAPACK is not set
+# CONFIG_PKG_USING_ULAPACK is not set
+# CONFIG_PKG_USING_QUEST is not set
+# CONFIG_PKG_USING_NAXOS is not set
+
+#
+# Signal Processing and Control Algorithm Packages
+#
+# CONFIG_PKG_USING_FIRE_PID_CURVE is not set
+# CONFIG_PKG_USING_UKAL is not set
+
+#
+# miscellaneous packages
+#
+
+#
+# project laboratory
+#
+
+#
+# samples: kernel and components samples
+#
+# CONFIG_PKG_USING_KERNEL_SAMPLES is not set
+# CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set
+# CONFIG_PKG_USING_NETWORK_SAMPLES is not set
+# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
+
+#
+# entertainment: terminal games and other interesting software packages
+#
+# CONFIG_PKG_USING_CMATRIX is not set
+# CONFIG_PKG_USING_SL is not set
+# CONFIG_PKG_USING_CAL is not set
+# CONFIG_PKG_USING_ACLOCK is not set
+# CONFIG_PKG_USING_THREES is not set
+# CONFIG_PKG_USING_2048 is not set
+# CONFIG_PKG_USING_SNAKE is not set
+# CONFIG_PKG_USING_TETRIS is not set
+# CONFIG_PKG_USING_DONUT is not set
+# CONFIG_PKG_USING_COWSAY is not set
+# CONFIG_PKG_USING_LIBCSV is not set
+# CONFIG_PKG_USING_OPTPARSE is not set
+# CONFIG_PKG_USING_FASTLZ is not set
+# CONFIG_PKG_USING_MINILZO is not set
+# CONFIG_PKG_USING_QUICKLZ is not set
+# CONFIG_PKG_USING_LZMA is not set
+# CONFIG_PKG_USING_MULTIBUTTON is not set
+# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
+# CONFIG_PKG_USING_CANFESTIVAL is not set
+# CONFIG_PKG_USING_ZLIB is not set
+# CONFIG_PKG_USING_MINIZIP is not set
+# CONFIG_PKG_USING_HEATSHRINK is not set
+# CONFIG_PKG_USING_DSTR is not set
+# CONFIG_PKG_USING_TINYFRAME is not set
+# CONFIG_PKG_USING_KENDRYTE_DEMO is not set
+# CONFIG_PKG_USING_DIGITALCTRL is not set
+# CONFIG_PKG_USING_UPACKER is not set
+# CONFIG_PKG_USING_UPARAM is not set
+# CONFIG_PKG_USING_HELLO is not set
+# CONFIG_PKG_USING_VI is not set
+# CONFIG_PKG_USING_KI is not set
+# CONFIG_PKG_USING_ARMv7M_DWT is not set
+# CONFIG_PKG_USING_CRCLIB is not set
+# CONFIG_PKG_USING_LWGPS is not set
+# CONFIG_PKG_USING_STATE_MACHINE is not set
+# CONFIG_PKG_USING_DESIGN_PATTERN is not set
+# CONFIG_PKG_USING_CONTROLLER is not set
+# CONFIG_PKG_USING_PHASE_LOCKED_LOOP is not set
+# CONFIG_PKG_USING_MFBD is not set
+# CONFIG_PKG_USING_SLCAN2RTT is not set
+# CONFIG_PKG_USING_SOEM is not set
+# CONFIG_PKG_USING_QPARAM is not set
+# CONFIG_PKG_USING_CorevMCU_CLI is not set
+
+#
+# Arduino libraries
+#
+# CONFIG_PKG_USING_RTDUINO is not set
+
+#
+# Projects
+#
+# CONFIG_PKG_USING_ARDUINO_ULTRASOUND_RADAR is not set
+# CONFIG_PKG_USING_ARDUINO_SENSOR_KIT is not set
+# CONFIG_PKG_USING_ARDUINO_MATLAB_SUPPORT is not set
+
+#
+# Sensors
+#
+# CONFIG_PKG_USING_ARDUINO_SENSOR_DEVICE_DRIVERS is not set
+# CONFIG_PKG_USING_ARDUINO_CAPACITIVESENSOR is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ADXL375 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VL53L0X is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VL53L1X is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSOR is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VL6180X is not set
+# CONFIG_PKG_USING_ADAFRUIT_MAX31855 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX31865 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX31856 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX6675 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MLX90614 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LSM9DS1 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AHTX0 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LSM9DS0 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BMP280 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ADT7410 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BMP085 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BME680 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MCP9808 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MCP4728 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_INA219 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LTR390 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ADXL345 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_DHT is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MCP9600 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LSM6DS is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BNO055 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX1704X is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MMC56X3 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MLX90393 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MLX90395 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ICM20X is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_DPS310 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_HTS221 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SHT4X is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SHT31 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ADXL343 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BME280 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AS726X is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AMG88XX is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AM2320 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AM2315 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LTR329_LTR303 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BMP085_UNIFIED is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BMP183 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BMP183_UNIFIED is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BMP3XX is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MS8607 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LIS3MDL is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MLX90640 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MMA8451 is not set
+# CONFIG_PKG_USING_ADAFRUIT_MSA301 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MPL115A2 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BNO08X is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BNO08X_RVC is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LIS2MDL is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LSM303DLH_MAG is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LC709203F is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_CAP1188 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_CCS811 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_NAU7802 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LIS331 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LPS2X is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LPS35HW is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LSM303_ACCEL is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LIS3DH is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PCF8591 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MPL3115A2 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MPR121 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MPRLS is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MPU6050 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PCT2075 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PM25AQI is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_EMC2101 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_FXAS21002C is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SCD30 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_FXOS8700 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_HMC5883_UNIFIED is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SGP30 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TMP006 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TLA202X is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TCS34725 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SI7021 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SI1145 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SGP40 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SHTC3 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_HDC1000 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_HTU21DF is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AS7341 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_HTU31D is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSORLAB is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_INA260 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TMP007_LIBRARY is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_L3GD20 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TMP117 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TSC2007 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TSL2561 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TSL2591_LIBRARY is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VCNL4040 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VEML6070 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VEML6075 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VEML7700 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_LIS3DHTR is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_DHT is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_ADXL335 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_ADXL345 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_BME280 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_BMP280 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_H3LIS331DL is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_MMA7660 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_TSL2561 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_PAJ7620 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_VL53L0X is not set
+# CONFIG_PKG_USING_SEEED_ITG3200 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_SHT31 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_HP20X is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_DRV2605L is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_BBM150 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_HMC5883L is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_LSM303DLH is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_TCS3414CS is not set
+# CONFIG_PKG_USING_SEEED_MP503 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_BMP085 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_HIGHTEMP is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_VEML6070 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_SI1145 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_SHT35 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_AT42QT1070 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_LSM6DS3 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_HDC1000 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_HM3301 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_MCP9600 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_LTC2941 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_LDC1612 is not set
+
+#
+# Display
+#
+# CONFIG_PKG_USING_ARDUINO_U8G2 is not set
+# CONFIG_PKG_USING_SEEED_TM1637 is not set
+
+#
+# Timing
+#
+# CONFIG_PKG_USING_ARDUINO_MSTIMER2 is not set
+
+#
+# Data Processing
+#
+# CONFIG_PKG_USING_ARDUINO_KALMANFILTER is not set
+# CONFIG_PKG_USING_ARDUINO_ARDUINOJSON is not set
+
+#
+# Data Storage
+#
+
+#
+# Communication
+#
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PN532 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SI4713 is not set
+
+#
+# Device Control
+#
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PCF8574 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PCA9685 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_PCF85063TP is not set
+
+#
+# Other
+#
+
+#
+# Signal IO
+#
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BUSIO is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TCA8418 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MCP23017 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ADS1X15 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AW9523 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MCP3008 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MCP4725 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BD3491FS is not set
+
+#
+# Uncategorized
+#
+
+#
+# Privated Packages of RealThread
+#
+# CONFIG_PKG_USING_CODEC is not set
+# CONFIG_PKG_USING_PLAYER is not set
+# CONFIG_PKG_USING_MPLAYER is not set
+# CONFIG_PKG_USING_PERSIMMON_SRC is not set
+# CONFIG_PKG_USING_JS_PERSIMMON is not set
+# CONFIG_PKG_USING_JERRYSCRIPT_WIN32 is not set
+
+#
+# Network Utilities
+#
+# CONFIG_PKG_USING_WICED is not set
+# CONFIG_PKG_USING_CLOUDSDK is not set
+# CONFIG_PKG_USING_POWER_MANAGER is not set
+# CONFIG_PKG_USING_RT_OTA is not set
+# CONFIG_PKG_USING_RTINSIGHT is not set
+# CONFIG_PKG_USING_SMARTCONFIG is not set
+# CONFIG_PKG_USING_RTX is not set
+# CONFIG_RT_USING_TESTCASE is not set
+# CONFIG_PKG_USING_NGHTTP2 is not set
+# CONFIG_PKG_USING_AVS is not set
+# CONFIG_PKG_USING_ALI_LINKKIT is not set
+# CONFIG_PKG_USING_STS is not set
+# CONFIG_PKG_USING_DLMS is not set
+# CONFIG_PKG_USING_AUDIO_FRAMEWORK is not set
+# CONFIG_PKG_USING_ZBAR is not set
+# CONFIG_PKG_USING_MCF is not set
+# CONFIG_PKG_USING_URPC is not set
+# CONFIG_PKG_USING_DCM is not set
+# CONFIG_PKG_USING_EMQ is not set
+# CONFIG_PKG_USING_CFGM is not set
+# CONFIG_PKG_USING_RT_CMSIS_DAP is not set
+# CONFIG_PKG_USING_SMODULE is not set
+# CONFIG_PKG_USING_SNFD is not set
+# CONFIG_PKG_USING_UDBD is not set
+# CONFIG_PKG_USING_BENCHMARK is not set
+# CONFIG_PKG_USING_UBJSON is not set
+# CONFIG_PKG_USING_DATATYPE is not set
+# CONFIG_PKG_USING_FASTFS is not set
+# CONFIG_PKG_USING_RIL is not set
+# CONFIG_PKG_USING_WATCH_DCM_SVC is not set
+# CONFIG_PKG_USING_WATCH_APP_FWK is not set
+# CONFIG_PKG_USING_GUI_TEST is not set
+# CONFIG_PKG_USING_PMEM is not set
+# CONFIG_PKG_USING_LWRDP is not set
+# CONFIG_PKG_USING_MASAN is not set
+# CONFIG_PKG_USING_BSDIFF_LIB is not set
+# CONFIG_PKG_USING_PRC_DIFF is not set
+
+#
+# RT-Thread Smart
+#
+# CONFIG_PKG_USING_UKERNEL is not set
+# CONFIG_PKG_USING_TRACE_AGENT is not set
+CONFIG_SOC_FAMILY_IFX=y
+CONFIG_SOC_SERIES_IFX_PSOC62=y
+
+#
+# Hardware Drivers Config
+#
+CONFIG_SOC_CY8C624ALQI_S2D42=y
+
+#
+# Onboard Peripheral Drivers
+#
+CONFIG_BSP_USING_USB_TO_USART=y
+
+#
+# On-chip Peripheral Drivers
+#
+CONFIG_BSP_USING_GPIO=y
+CONFIG_BSP_USING_UART=y
+# CONFIG_BSP_USING_UART0 is not set
+# CONFIG_BSP_USING_UART1 is not set
+# CONFIG_BSP_USING_UART2 is not set
+# CONFIG_BSP_USING_UART3 is not set
+# CONFIG_BSP_USING_UART4 is not set
+# CONFIG_BSP_USING_UART5 is not set
+CONFIG_BSP_USING_UART6=y
+# CONFIG_BSP_USING_PWM is not set
+# CONFIG_BSP_USING_SPI is not set
+# CONFIG_BSP_USING_ADC is not set
+# CONFIG_BSP_USING_SDMMC is not set
+# CONFIG_BSP_USING_HW_I2C is not set
+# CONFIG_BSP_USING_I2C is not set
+# CONFIG_BSP_USING_RTC is not set
+# CONFIG_BSP_USING_ON_CHIP_FLASH is not set
+# CONFIG_BSP_USING_WDT is not set
+# CONFIG_BSP_USING_DAC is not set
+# CONFIG_BSP_USING_TIM is not set
+
+#
+# Board extended module Drivers
+#
+# CONFIG_BSP_USING_SLIDER is not set
+# CONFIG_BSP_USING_RW007 is not set

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 215 - 0
project_0/.cproject


+ 42 - 0
project_0/.gitignore

@@ -0,0 +1,42 @@
+*.pyc
+*.map
+*.dblite
+*.elf
+*.bin
+*.hex
+*.axf
+*.exe
+*.pdb
+*.idb
+*.ilk
+*.old
+build
+Debug
+documentation/html
+packages/
+*~
+*.o
+*.obj
+*.out
+*.bak
+*.dep
+*.lib
+*.i
+*.d
+.DS_Stor*
+.config 3
+.config 4
+.config 5
+Midea-X1
+*.uimg
+GPATH
+GRTAGS
+GTAGS
+.vscode
+JLinkLog.txt
+JLinkSettings.ini
+DebugConfig/
+RTE/
+settings/
+*.uvguix*
+cconfig.h

+ 28 - 0
project_0/.project

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+  <name>project</name>
+  <comment />
+  <projects>
+	</projects>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+      <triggers>clean,full,incremental,</triggers>
+      <arguments>
+			</arguments>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+      <triggers>full,incremental,</triggers>
+      <arguments>
+			</arguments>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.cdt.core.cnature</nature>
+    <nature>com.cypress.studio.app.cymodusnature</nature>
+    <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+    <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+  </natures>
+  <linkedResources />
+</projectDescription>

+ 58 - 0
project_0/.settings/.OpenOCD.Debug.rttlaunch

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.openocd.launchConfigurationType">
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doFirstReset" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doSecondReset" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbCLient" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbServer" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.enableSemihosting" value="true"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.firstResetType" value="init"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off&#13;&#10;set remotetimeout 15"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherOptions" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerExecutable" value="${debugger_install_path}/${openocd-infineon_debugger_relative_path}/bin/openocd.exe"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerOther" value="-s ../scripts -f interface/kitprog3.cfg -f target/psoc6_2m.cfg -c &quot;psoc6.cpu.cm4 configure -rtos auto -rtos-wipe-on-reset-halt 1&quot; -c &quot;gdb_port 3332&quot; -c &quot;psoc6 sflash_restrictions 1&quot; -c &quot;init; reset init&quot;"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTclPortNumber" value="6666"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherInitCommands" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherRunCommands" value="mon psoc6 reset_halt sysresetreq&#13;&#10;flushregs&#13;&#10;mon gdb_sync&#13;&#10;stepi"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.secondResetType" value="run"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.svdPath" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value="${workspace_loc:\dist_ide_project\Debug\rtthread.elf}"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU MCU OpenOCD"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
+<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value="${workspace_loc:\dist_ide_project\Debug\rtthread.elf}"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${rtt_gnu_gcc}/arm-none-eabi-gdb.exe"/>
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
+<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/rtthread.elf"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="1111"/>
+<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/1111"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="GBK"/>
+<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
+<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
+</launchConfiguration>

+ 2 - 0
project_0/.settings/ilg.gnumcueclipse.managedbuild.cross.arm.prefs

@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+toolchain.path.1287942917=${toolchain_install_path}/ARM/GNU_Tools_for_ARM_Embedded_Processors/5.4.1/bin

+ 14 - 0
project_0/.settings/language.settings.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project>
+	<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.553091094" name="Debug">
+		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
+			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
+			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
+			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
+			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1247487277005839356" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT ARM Cross GCC Built-in Compiler Settings " parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+				<language-scope id="org.eclipse.cdt.core.gcc"/>
+				<language-scope id="org.eclipse.cdt.core.g++"/>
+			</provider>
+		</extension>
+	</configuration>
+</project>

+ 3 - 0
project_0/.settings/org.eclipse.core.runtime.prefs

@@ -0,0 +1,3 @@
+content-types/enabled=true
+content-types/org.eclipse.cdt.core.asmSource/file-extensions=s
+eclipse.preferences.version=1

+ 20 - 0
project_0/.settings/projcfg.ini

@@ -0,0 +1,20 @@
+#RT-Thread Studio Project Configuration
+#Thu Mar 23 10:44:55 CST 2023
+project_type=rt-thread
+chip_name=CY8C624ABZI
+os_branch=full
+example_name=
+os_version=4.1.1
+selected_rtt_version=4.1.1
+cfg_version=v3.0
+board_base_nano_proj=False
+is_use_scons_build=True
+output_project_path=D\:\\RT-ThreadStudio\\workspace
+project_base_bsp=true
+hardware_adapter=KitProg3
+project_name=test
+is_base_example_project=False
+board_name=CY8C624-INFINEON-EVALUATIONKIT
+device_vendor=Infineon
+bsp_path=repo/Local/Board_Support_Packages/Infineon/CY8C624-INFINEON-EVALUATIONKIT/1.0.0(offline)
+bsp_version=1.0.0

+ 65 - 0
project_0/.settings/project.DAPLink.Debug.rttlaunch

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.pyocd.launchConfigurationType">
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.adapterName" value="DAP-LINK"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.binFlashStartAddress" value=""/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doContinue" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doDebugInRam" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doFirstReset" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doGdbServerAllocateConsole" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doSecondReset" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doStartGdbServer" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.enableSemihosting" value="true"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.firstResetType" value="init"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbClientOtherOptions" value=""/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerBusSpeed" value="12000000"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerConnectionAddress" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerDeviceName" value="cy8c64xA_cm4"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerEnableSemihosting" value="false"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerExecutable" value="E:\software\RT-ThreadStudio\repo\Extract\Debugger_Support_Packages\openocd\bin\openocd.exe"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerFlashMode" value="0"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerGdbPortNumber" value="3333"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerOther" value=""/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerTelnetPortNumber" value="4444"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.otherInitCommands" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.otherRunCommands" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.programMode" value="HEX"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.secondResetType" value="halt"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.svdPath" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU MCU PyOCD"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
+<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${rtt_gnu_gcc}/arm-none-eabi-gdb.exe"/>
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
+<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/rtthread.elf"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="dist_ide_project"/>
+<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/dist_ide_project"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.cdt.debug.core.sourceLocator"/>
+<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10;&lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
+<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="GBK"/>
+<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
+</launchConfiguration>

+ 58 - 0
project_0/.settings/project.OpenOCD.Debug.rttlaunch

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.openocd.launchConfigurationType">
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doFirstReset" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doSecondReset" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbCLient" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbServer" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.enableSemihosting" value="true"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.firstResetType" value="init"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off&#13;&#10;set remotetimeout 15"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherOptions" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerExecutable" value="${debugger_install_path}/${openocd-infineon_debugger_relative_path}/bin/openocd.exe"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerOther" value="-s ../scripts -f interface/kitprog3.cfg -f target/psoc6_2m.cfg -c &quot;psoc6.cpu.cm4 configure -rtos auto -rtos-wipe-on-reset-halt 1&quot; -c &quot;gdb_port 3332&quot; -c &quot;psoc6 sflash_restrictions 1&quot; -c &quot;init; reset init&quot;"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTclPortNumber" value="6666"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherInitCommands" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherRunCommands" value="mon psoc6 reset_halt sysresetreq&#13;&#10;flushregs&#13;&#10;mon gdb_sync&#13;&#10;stepi"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.secondResetType" value="run"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.svdPath" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU MCU OpenOCD"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
+<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="entry"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${rtt_gnu_gcc}/arm-none-eabi-gdb.exe"/>
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
+<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/rtthread.elf"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="project"/>
+<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/project"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="GBK"/>
+<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
+<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
+</launchConfiguration>

+ 65 - 0
project_0/.settings/test.DAPLink.Debug.rttlaunch

@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.pyocd.launchConfigurationType">
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.adapterName" value="DAP-LINK"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.binFlashStartAddress" value=""/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doContinue" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doDebugInRam" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doFirstReset" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doGdbServerAllocateConsole" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doSecondReset" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.doStartGdbServer" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.enableSemihosting" value="true"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.firstResetType" value="init"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbClientOtherOptions" value=""/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerBusSpeed" value="12000000"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerConnectionAddress" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerDeviceName" value="cy8c64xA_cm4"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerEnableSemihosting" value="false"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerExecutable" value="${debugger_install_path}/${daplink_debugger_relative_path}/pyocd.exe"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerFlashMode" value="0"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerGdbPortNumber" value="3333"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerOther" value="-s ../scripts -f interface/kitprog3.cfg -f target/psoc6_2m.cfg -c &quot;psoc6.cpu.cm4 configure -rtos auto -rtos-wipe-on-reset-halt 1&quot; -c &quot;gdb_port 3332&quot; -c &quot;psoc6 sflash_restrictions 1&quot; -c &quot;init; reset init&quot;"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.gdbServerTelnetPortNumber" value="4444"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.otherInitCommands" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.otherRunCommands" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.programMode" value="HEX"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.pyocd.secondResetType" value="halt"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.svdPath" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU MCU PyOCD"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
+<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${rtt_gnu_gcc}/arm-none-eabi-gdb.exe"/>
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
+<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/rtthread.elf"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="test"/>
+<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/test"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.cdt.debug.core.sourceLocator"/>
+<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10;&lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
+<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="GBK"/>
+<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
+</launchConfiguration>

+ 58 - 0
project_0/.settings/test.Debug.rttlaunch

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.openocd.launchConfigurationType">
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doFirstReset" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doSecondReset" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbCLient" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbServer" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.enableSemihosting" value="true"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.firstResetType" value="init"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off&#13;&#10;set remotetimeout 15"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherOptions" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerExecutable" value="${debugger_install_path}/${openocd-infineon_debugger_relative_path}/bin/openocd.exe"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerOther" value="-s ../scripts -f interface/kitprog3.cfg -f target/psoc6_2m.cfg -c &quot;psoc6.cpu.cm4 configure -rtos auto -rtos-wipe-on-reset-halt 1&quot; -c &quot;gdb_port 3332&quot; -c &quot;psoc6 sflash_restrictions 1&quot; -c &quot;init; reset init&quot;"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTclPortNumber" value="6666"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherInitCommands" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherRunCommands" value="mon psoc6 reset_halt sysresetreq&#13;&#10;flushregs&#13;&#10;mon gdb_sync&#13;&#10;stepi"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.secondResetType" value="run"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.svdPath" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value="${workspace_loc:\dist_ide_project\Debug\rtthread.elf}"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU MCU OpenOCD"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
+<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="main"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value="${workspace_loc:\dist_ide_project\Debug\rtthread.elf}"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${rtt_gnu_gcc}/arm-none-eabi-gdb.exe"/>
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
+<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/rtthread.elf"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="test"/>
+<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/test"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="GBK"/>
+<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
+<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
+</launchConfiguration>

+ 58 - 0
project_0/.settings/test.OpenOCD.Debug.rttlaunch

@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="ilg.gnumcueclipse.debug.gdbjtag.openocd.launchConfigurationType">
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doFirstReset" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doSecondReset" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbCLient" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.doStartGdbServer" value="true"/>
+<booleanAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.enableSemihosting" value="true"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.firstResetType" value="init"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off&#13;&#10;set remotetimeout 15"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbClientOtherOptions" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerExecutable" value="${debugger_install_path}/${openocd-infineon_debugger_relative_path}/bin/openocd.exe"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerOther" value="-s ../scripts -f interface/kitprog3.cfg -f target/psoc6_2m.cfg -c &quot;psoc6.cpu.cm4 configure -rtos auto -rtos-wipe-on-reset-halt 1&quot; -c &quot;gdb_port 3332&quot; -c &quot;psoc6 sflash_restrictions 1&quot; -c &quot;init; reset init&quot;"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTclPortNumber" value="6666"/>
+<intAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherInitCommands" value=""/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.otherRunCommands" value="mon psoc6 reset_halt sysresetreq&#13;&#10;flushregs&#13;&#10;mon gdb_sync&#13;&#10;stepi"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.openocd.secondResetType" value="run"/>
+<stringAttribute key="ilg.gnumcueclipse.debug.gdbjtag.svdPath" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU MCU OpenOCD"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
+<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="entry"/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value=""/>
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value=""/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
+<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${rtt_gnu_gcc}/arm-none-eabi-gdb.exe"/>
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false"/>
+<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/rtthread.elf"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="test"/>
+<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/test"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="4"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_ENCODING" value="GBK"/>
+<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#13;&#10;"/>
+<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
+</launchConfiguration>

+ 21 - 0
project_0/Kconfig

@@ -0,0 +1,21 @@
+mainmenu "RT-Thread Configuration"
+
+config BSP_DIR
+    string
+    option env="BSP_ROOT"
+    default "."
+
+config RTT_DIR
+    string
+    option env="RTT_ROOT"
+    default "rt-thread"
+
+config PKGS_DIR
+    string
+    option env="PKGS_ROOT"
+    default "packages"
+
+source "$RTT_DIR/Kconfig"
+source "$PKGS_DIR/Kconfig"
+source "libraries/Kconfig"
+source "board/Kconfig"

+ 210 - 0
project_0/LICENSE

@@ -0,0 +1,210 @@
+CYPRESS END USER LICENSE AGREEMENT
+
+PLEASE READ THIS END USER LICENSE AGREEMENT ("Agreement") CAREFULLY BEFORE
+DOWNLOADING, INSTALLING, COPYING, OR USING THIS SOFTWARE AND ACCOMPANYING
+DOCUMENTATION.  BY DOWNLOADING, INSTALLING, COPYING OR USING THE SOFTWARE,
+YOU ARE AGREEING TO BE BOUND BY THIS AGREEMENT.  IF YOU DO NOT AGREE TO ALL
+OF THE TERMS OF THIS AGREEMENT, PROMPTLY RETURN AND DO NOT USE THE SOFTWARE.
+IF YOU HAVE PURCHASED THIS LICENSE TO THE SOFTWARE, YOUR RIGHT TO RETURN THE
+SOFTWARE EXPIRES 30 DAYS AFTER YOUR PURCHASE AND APPLIES ONLY TO THE ORIGINAL
+PURCHASER.
+
+1. Definitions.
+
+    "Software" means this software and any accompanying documentation,
+      including any upgrades, updates, bug fixes or modified versions provided
+      to you by Cypress.
+
+    "Source Code" means software in human-readable form.
+
+    "Binary Code" means the software in binary code form such as object code or
+      an executable.
+
+    "Development Tools" means software that is intended to be installed on a
+      personal computer and used to create programming code for Firmware,
+      Drivers, or Host Applications.  Examples of Development Tools are
+      Cypress's PSoC Creator software, Cypress's WICED SDKs, and Cypress's
+      ModusToolbox software.
+
+    "Firmware" means software that executes on a Cypress hardware product.
+
+    "Driver" means software that enables the use of a Cypress hardware product
+      on a particular host operating system such as GNU/Linux, Windows, MacOS,
+      Android, and iOS.
+
+    "Host Application" means software that executes on a device other than a
+      Cypress hardware product in order to program, control, or communicate
+      with a Cypress hardware product.
+
+    "inf File" means a hardware setup information file (.inf file) created by
+      the Software to allow a Microsoft Windows operating system to install
+      the driver for a Cypress hardware product.
+
+2. License.  Subject to the terms and conditions of this Agreement, Cypress
+Semiconductor Corporation ("Cypress") and its suppliers grant to you a
+non-exclusive, non-transferable license under their copyright rights:
+
+    a. to use the Development Tools in object code form solely for the purpose
+       of creating Firmware, Drivers, Host Applications, and inf Files for
+       Cypress hardware products; and
+
+    b. (i) if provided in Source Code form, to copy, modify, and compile the
+           Firmware Source Code to create Firmware for execution on a Cypress
+           hardware product, and
+      (ii) to distribute Firmware in binary code form only, only when
+           installed onto a Cypress hardware product; and
+
+    c. (i) if provided in Source Code form, to copy, modify, and compile the
+           Driver Source Code to create one or more Drivers to enable the use
+           of a Cypress hardware product on a particular host operating
+           system, and
+      (ii) to distribute the Driver, in binary code form only, only when
+           installed on a device that includes the Cypress hardware product
+           that the Driver is intended to enable; and
+
+    d. (i) if provided in Source Code form, to copy, modify, and compile the
+           Host Application Source Code to create one or more Host
+           Applications to program, control, or communicate with a Cypress
+           hardware product, and
+      (ii) to distribute Host Applications, in binary code form only, only
+           when installed on a device that includes a Cypress hardware product
+           that the Host Application is intended to program, control, or
+           communicate with; and
+
+    e. to freely distribute any inf File.
+
+Any distribution of Software permitted under this Agreement must be made
+pursuant to your standard end user license agreement used for your proprietary
+(closed source) software products, such end user license agreement to include,
+at a minimum, provisions limiting your licensors' liability and prohibiting
+reverse engineering of the Software, consistent with such provisions in this
+Agreement.
+
+3. Free and Open Source Software.  Portions of the Software may be licensed
+under free and/or open source licenses such as the GNU General Public License
+or other licenses from third parties ("Third Party Software").  Third Party
+Software is subject to the applicable license agreement and not this
+Agreement.  If you are entitled to receive the source code from Cypress for
+any Third Party Software included with the Software, either the source code
+will  be included with the Software or you may obtain the source code at no
+charge from <http://www.cypress.com/go/opensource>.  The applicable license
+terms will accompany each source code package.  To review the license terms
+applicable to any Third Party Software for which Cypress is not required to
+provide you with source code, please see the Software's installation directory
+on your computer.
+
+4. Proprietary Rights; Ownership.  The Software, including all intellectual
+property rights therein, is and will remain the sole and exclusive property of
+Cypress or its suppliers.  Cypress retains ownership of the Source Code and
+any compiled version thereof.  Subject to Cypress' ownership of the underlying
+Software (including Source Code), you retain ownership of any modifications
+you make to the Source Code.  You agree not to remove any Cypress copyright or
+other notices from the Source Code and any modifications thereof.  You agree
+to keep the Source Code confidential.  Any reproduction, modification,
+translation, compilation, or representation of the Source Code except as
+permitted in Section 2 ("License") is prohibited without the express written
+permission of Cypress.  Except as otherwise expressly provided in this
+Agreement, you may not:
+    (i) modify, adapt, or create derivative works based upon the Software;
+   (ii) copy the Software;
+  (iii) except and only to the extent explicitly permitted by applicable
+        law despite this limitation, decompile, translate, reverse engineer,
+        disassemble or otherwise reduce the Software to human-readable form;
+        or
+   (iv) use the Software or any sample code other than for the Purpose.
+You hereby covenant that you will not assert any claim that the Software, or
+derivative works thereof created by or for Cypress, infringe any intellectual
+property right owned or controlled by you
+
+5. No Support.  Cypress may, but is not required to, provide technical support
+for the Software.
+
+6. Term and Termination.  This Agreement is effective until terminated, and
+either party may terminate this Agreement at any time with or without cause.
+This Agreement and your license rights under this Agreement will terminate
+immediately without notice from Cypress if you fail to comply with any
+provision of this Agreement.  Upon termination, you must destroy all copies of
+Software in your possession or control.  The following paragraphs shall
+survive any termination of this Agreement: "Free and Open Source Software,"
+"Proprietary Rights; Ownership," "Compliance With Law," "Disclaimer,"
+"Limitation of Liability," and "General."
+
+7. Compliance With Law.  Each party agrees to comply with all applicable laws,
+rules and regulations in connection with its activities under this Agreement.
+Without limiting the foregoing, the Software may be subject to export control
+laws and regulations of the United States and other countries.  You agree to
+comply strictly with all such laws and regulations and acknowledge that you
+have the responsibility to obtain licenses to export, re-export, or import the
+Software.
+
+8. Disclaimer.  TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, CYPRESS
+MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THE
+SOFTWARE, INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
+reserves the right to make changes to the Software without notice. Cypress
+does not assume any liability arising out of the application or use of
+Software or any product or circuit described in the Software.  It is the
+responsibility of the user of the Software to properly design, program, and
+test the functionality and safety of any application made of the Software and
+any resulting product.  Cypress does not authorize its Software or products
+for use in any products where a malfunction or failure of the Software or
+Cypress product may reasonably be expected to result in significant property
+damage, injury or death ("High Risk Product").  If you include any Software or
+Cypress product in a High Risk Product, you assume all risk of such use and
+agree to indemnify Cypress and its suppliers against all liability.  No
+computing device can be absolutely secure.  Therefore, despite security
+measures implemented in Cypress hardware or software products, Cypress does
+not assume any liability arising out of any security breach, such as
+unauthorized access to or use of a Cypress product.
+
+9. Limitation of Liability.  TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE
+LAW, IN NO EVENT WILL CYPRESS OR ITS SUPPLIERS, RESELLERS, OR DISTRIBUTORS BE
+LIABLE FOR ANY LOST REVENUE, PROFIT, OR DATA, OR FOR SPECIAL, INDIRECT,
+CONSEQUENTIAL, INCIDENTAL, OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS
+OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO THE USE OF OR
+INABILITY TO USE THE SOFTWARE EVEN IF CYPRESS OR ITS SUPPLIERS, RESELLERS, OR
+DISTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  IN NO
+EVENT SHALL CYPRESS' OR ITS SUPPLIERS', RESELLERS', OR DISTRIBUTORS' TOTAL
+LIABILITY TO YOU, WHETHER IN CONTRACT, TORT (INCLUDING NEGLIGENCE), OR
+OTHERWISE, EXCEED THE GREATER OF US$500 OR THE PRICE PAID BY YOU FOR THE
+SOFTWARE.  THE FOREGOING LIMITATIONS SHALL APPLY EVEN IF THE ABOVE-STATED
+WARRANTY FAILS OF ITS ESSENTIAL PURPOSE.  BECAUSE SOME STATES OR JURISDICTIONS
+DO NOT ALLOW LIMITATION OR EXCLUSION OF CONSEQUENTIAL OR INCIDENTAL DAMAGES,
+ALL OR PORTIONS OF THE ABOVE LIMITATION MAY NOT APPLY TO YOU.
+
+10. Restricted Rights.  The Software is commercial computer software as that
+term is described in 48 C.F.R. 252.227-7014(a)(1).  If the Software is being
+acquired by or on behalf of the U.S. Government or by a U.S. Government prime
+contractor or subcontractor (at any tier), then the Government's rights in
+Software shall be only those set forth in this Agreement.
+
+11. Personal Information.  You agree that information you provide through your
+registration on Cypress IoT Community Forum or other Cypress websites,
+including contact information or other personal information, may be collected
+and used by Cypress consistent with its Data Privacy Policy
+(www.cypress.com/privacy-policy), as updated or revised from time to time, and
+may be provided to its third party sales representatives, distributors and
+other entities conducting sales activities for Cypress for sales-related and
+other business purposes.
+
+12. General.  This Agreement will bind and inure to the benefit of each
+party's successors and assigns, provided that you may not assign or transfer
+this Agreement, in whole or in part, without Cypress' written consent.  This
+Agreement shall be governed by and construed in accordance with the laws of
+the State of California, United States of America, as if performed wholly
+within the state and without giving effect to the principles of conflict of
+law.  The parties consent to personal and exclusive jurisdiction of and venue
+in, the state and federal courts within Santa Clara County, California;
+provided however, that nothing in this Agreement will limit Cypress' right to
+bring legal action in any venue in order to protect or enforce its
+intellectual property rights.  No failure of either party to exercise or
+enforce any of its rights under this Agreement will act as a waiver of such
+rights.  If any portion of this Agreement is found to be void or
+unenforceable, the remaining provisions of this Agreement shall remain in full
+force and effect.  This Agreement is the complete and exclusive agreement
+between the parties with respect to the subject matter hereof, superseding and
+replacing any and all prior agreements, communications, and understandings
+(both written and oral) regarding such subject matter.  Any notice to Cypress
+will be deemed effective when actually received and must be sent to Cypress
+Semiconductor Corporation, ATTN: Chief Legal Officer, 198 Champion Court, San
+Jose, CA 95134 USA.

+ 104 - 0
project_0/README.md

@@ -0,0 +1,104 @@
+# Infineon Psoc6-evaluationkit-062S2 说明
+
+## 简介
+
+本文档为 `RT-Thread` 为 `PSoC6 CY8CKIT-062S2-43012`开发板提供的 BSP (板级支持包) 说明。
+
+主要内容如下:
+
+- 开发板资源介绍
+- BSP 快速上手
+- 进阶使用方法
+
+通过阅读快速上手章节开发者可以快速地上手该 BSP,将 RT-Thread 运行在开发板上。在进阶使用指南章节,将会介绍更多高级功能,帮助开发者利用 `RT-Thread` 驱动更多板载资源。
+
+## 开发板介绍
+
+`Psoc6-evaluationkit-062S2` 是 RT-Thread 联合英飞凌推出的一款集成32位双核CPU子系统( ARM Cortex-M4 和 ARM Cortex-M0)的开发板,其具有单周期乘法的150-MHz Arm Cortex-M4F CPU (浮点和存储器保护单元),100-MHz Cortex M0+ CPU,带单周期乘法和MPU,可以充分发挥 PSoC6 双核芯片性能。
+
+该开发板核心 **板载资源** 如下:
+
+- MCU:CY8C624ABZI-S2D44,Cortex-M4主频 150MHz,Cortex-M0主频 100MHz,2MB Flash 和 1MB SRAM
+      MCU手册更多详细信息请参考文档 [PSoC 6 MCU: CY8C62x8, CY8C62xA Datasheet (infineon.com)](https://www.infineon.com/dgdl/Infineon-PSOC_6_MCU_CY8C62X8_CY8C62XA-DataSheet-v17_00-EN.pdf?fileId=8ac78c8c7d0d8da4017d0ee7d03a70b1)
+- 板载资源:microSD card , 触摸滑条,Arduino 接口
+- 开发环境:ModusToolbox 2.0/MDK V5
+  	PSoC® Creator™ 下载链接 [ModusToolbox™ Software - Infineon Technologies](https://www.infineon.com/cms/en/design-support/tools/sdk/modustoolbox-software/)
+
+## 外设支持
+
+本 BSP 目前对外设的支持情况如下:
+
+| **片上外设** | **支持情况** | **备注** |
+| :----------: | :----------: | :------: |
+|  USB 转串口  |     支持     |  UART0   |
+|     GPIO     |     支持     |    —     |
+|     UART     |     支持     | UART0-5  |
+|    Touch     |     支持     | 触摸滑条 |
+
+## 快速上手
+
+本 BSP 是以 `MDK V5` 和 `RT-Thread Studio` 为开发环境(编译器:ARMClang / GCC),接下来介绍如何将系统运行起来。
+
+### 使用 MDK V5 开发
+
+#### 硬件连接
+
+使用数据线连接开发板到 PC。
+
+#### 编译下载
+
+1、配置工程:
+
+首先打开 MDK ,若没有安装 `Infineon-PSoC6` 的芯片支持包会提示在线安装,根据提示安装即可。若受网络问题,可以进入 [keil](https://www.keil.com/dd2/pack) 官网下载安装包,离线安装。
+
+![mdk_package](E:\workspace_work\rt-thread-5.0\bsp\Infineon\psoc6-cy8ckit-062S2-43012\figures\mdk_package.png)
+
+2、 编译此工程:在安装好芯片支持包后,在 `MDK`工程中进行编译。
+
+3、下载此工程:
+
+工程默认配置使用板载 `DAP-LINK` 使用 `SWD` 方式下载程序,使用数据线连接开发板,编译之后直接点击下载按钮即可。
+
+### 使用 RT-Thread Studio 开发
+
+#### 导入工程
+
+* 首先打开  `RT-Thread Studio` 开发工具,点加左上角文件—>导入—> RT-Thread Studio项目到工作空间中。
+
+![](E:\workspace_work\rt-thread-5.0\bsp\Infineon\psoc6-cy8ckit-062S2-43012\figures\studio1.png)
+
+* 接着选择 `psoc6-evaluationkit-062S2` 开发板支持包的目录,进行导入。
+
+![](E:\workspace_work\rt-thread-5.0\bsp\Infineon\psoc6-cy8ckit-062S2-43012\figures\studio2.png)
+
+#### 编译下载
+
+* 点击 IDE 左上角的构建选项进行工程的编译。
+
+![](E:\workspace_work\rt-thread-5.0\bsp\Infineon\psoc6-cy8ckit-062S2-43012\figures\studio3-build.png)
+
+* 当编译无错误警告时,点击 `Debug` 或 `Download` 选项进行调试/下载。
+
+  注:若点击下载并下载成功后串口终端无显示信息,请手动按下复位按键进行重启运行。
+
+  ![](E:\workspace_work\rt-thread-5.0\bsp\Infineon\psoc6-cy8ckit-062S2-43012\figures\studio4-download.png)
+
+## 运行结果
+
+下载程序成功之后,系统会自动运行。打开终端工具串口助手,选择波特率为 115200。复位设备后,LED 将会以 500HZ 的频率闪烁,而且在终端上可以看到 `RT-Thread` 的输出信息:
+
+注:推荐使用串口调试助手如:`MobaXterm`
+
+```
+ \ | /
+- RT -     Thread Operating System
+ / | \     4.1.1 build Jul 25 2022 18:03:35
+ 2006 - 2022 Copyright by RT-Thread team
+msh >
+```
+
+## 联系人
+
+维护人:
+
+- [Rbb666](https://github.com/Rbb666)

+ 15 - 0
project_0/SConscript

@@ -0,0 +1,15 @@
+# for module compiling
+import os
+Import('RTT_ROOT')
+from building import *
+
+cwd = GetCurrentDir()
+objs = []
+list = os.listdir(cwd)
+
+for d in list:
+    path = os.path.join(cwd, d)
+    if os.path.isfile(os.path.join(path, 'SConscript')):
+        objs = objs + SConscript(os.path.join(d, 'SConscript'))
+
+Return('objs')

+ 64 - 0
project_0/SConstruct

@@ -0,0 +1,64 @@
+import os
+import sys
+import rtconfig
+
+if os.getenv('RTT_ROOT'):
+    RTT_ROOT = os.getenv('RTT_ROOT')
+else:
+    RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')
+
+# set RTT_ROOT
+if not os.getenv("RTT_ROOT"): 
+    RTT_ROOT="rt-thread"
+
+sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
+try:
+    from building import *
+except:
+    print('Cannot found RT-Thread root directory, please check RTT_ROOT')
+    print(RTT_ROOT)
+    exit(-1)
+
+TARGET = 'rt-thread.' + rtconfig.TARGET_EXT
+
+DefaultEnvironment(tools=[])
+env = Environment(tools = ['mingw'],
+    AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
+    CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
+    AR = rtconfig.AR, ARFLAGS = '-rc',
+    CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
+    LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
+env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
+
+if rtconfig.PLATFORM in ['iccarm']:
+    env.Replace(CCCOM = ['$CC $CFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES'])
+    env.Replace(ARFLAGS = [''])
+    env.Replace(LINKCOM = env["LINKCOM"] + ' --map rt-thread.map')
+
+Export('RTT_ROOT')
+Export('rtconfig')
+
+SDK_ROOT = os.path.abspath('./')
+
+if os.path.exists(SDK_ROOT + '/libraries'):
+    libraries_path_prefix = SDK_ROOT + '/libraries'
+else:
+    libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/libraries'
+
+SDK_LIB = libraries_path_prefix
+Export('SDK_LIB')
+
+# prepare building environment
+objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
+
+IFX_library = 'IFX_PSOC6_HAL'
+rtconfig.BSP_LIBRARY_TYPE = IFX_library
+
+# include libraries
+objs.extend(SConscript(os.path.join(libraries_path_prefix, IFX_library, 'SConscript')))
+
+# include drivers
+objs.extend(SConscript(os.path.join(libraries_path_prefix, 'HAL_Drivers', 'SConscript')))
+
+# make a building
+DoBuilding(TARGET, objs)

+ 16 - 0
project_0/applications/SConscript

@@ -0,0 +1,16 @@
+import rtconfig
+from building import *
+import os
+
+cwd  = GetCurrentDir()
+path = [cwd]
+src  = Glob('*.c')
+
+group = DefineGroup('Applications', src, depend = [''], CPPPATH = path)
+
+list = os.listdir(cwd)
+for item in list:
+    if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
+        group = group + SConscript(os.path.join(item, 'SConscript'))
+
+Return('group')

+ 29 - 0
project_0/applications/main.c

@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-06-29     Rbb666       first version
+ */
+
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#include "drv_gpio.h"
+
+#define LED_PIN     GET_PIN(0, 0)
+
+int main(void)
+{
+    rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
+
+    for (;;)
+    {
+        rt_pin_write(LED_PIN, PIN_HIGH);
+        rt_thread_mdelay(500);
+        rt_pin_write(LED_PIN, PIN_LOW);
+        rt_thread_mdelay(500);
+    }
+}

+ 319 - 0
project_0/board/Kconfig

@@ -0,0 +1,319 @@
+menu "Hardware Drivers Config"
+
+config SOC_CY8C624ALQI_S2D42
+    bool
+    select SOC_SERIES_IFX_PSOC62
+    select RT_USING_COMPONENTS_INIT
+    select RT_USING_USER_MAIN
+    default y
+
+menu "Onboard Peripheral Drivers"
+
+    config BSP_USING_USB_TO_USART
+        bool "Enable USB TO USART (uart6)"
+        select BSP_USING_UART
+        select BSP_USING_UART6
+        default y
+endmenu
+
+menu "On-chip Peripheral Drivers"
+
+    config BSP_USING_GPIO
+        bool "Enable GPIO"
+        select RT_USING_PIN
+        default y
+
+    menuconfig BSP_USING_UART
+        bool "Enable UART"
+        default y
+        select RT_USING_SERIAL
+        if BSP_USING_UART
+            config BSP_USING_UART0
+                bool "Enable UART0"
+                default y
+            config BSP_USING_UART1
+                bool "Enable UART1"
+                default n
+            config BSP_USING_UART2
+                bool "Enable UART2"
+                default n
+            config BSP_USING_UART3
+                bool "Enable UART3"
+                default n
+            config BSP_USING_UART4
+                bool "Enable UART4"
+                default n
+            config BSP_USING_UART5
+                bool "Enable UART5"
+                default n
+            config BSP_USING_UART6
+                bool "Enable UART6"
+                default n
+        endif
+
+    menuconfig BSP_USING_PWM
+        bool "Enable PWM"
+        default n
+        select RT_USING_PWM
+        if BSP_USING_PWM
+        menuconfig BSP_USING_PWM0
+            bool "Enable timer0 output pwm"
+            default n
+            if BSP_USING_PWM0
+                menuconfig BSP_USING_PWM0_CH3
+                    bool "Enable PWM0 channel3"
+                    default n
+                    if BSP_USING_PWM0_CH3
+                        config BSP_USING_PWM0_PORT13
+                        bool "Enable PWM0-PORT13 output pwm"
+                        default n
+                    endif
+                menuconfig BSP_USING_PWM0_CH7
+                    bool "Enable PWM0 channel7"
+                    default n
+                    if BSP_USING_PWM0_CH7
+                        config BSP_USING_PWM0_PORT2
+                        bool "Enable PWM0-PORT2 output pwm"
+                        default n
+                    endif
+                    if BSP_USING_PWM0_CH7
+                        config BSP_USING_PWM0_PORT5
+                        bool "Enable PWM0-PORT5 output pwm"
+                        default n
+                    endif
+                    if BSP_USING_PWM0_CH7
+                        config BSP_USING_PWM0_PORT7
+                        bool "Enable PWM0-PORT7 output pwm"
+                        default n
+                    endif
+                    if BSP_USING_PWM0_CH7
+                        config BSP_USING_PWM0_PORT9
+                        bool "Enable PWM0-PORT9 output pwm"
+                        default n
+                    endif
+                    if BSP_USING_PWM0_CH7
+                        config BSP_USING_PWM0_PORT10
+                        bool "Enable PWM0-PORT10 output pwm"
+                        default n
+                    endif
+                    if BSP_USING_PWM0_CH7
+                        config BSP_USING_PWM0_PORT12
+                        bool "Enable PWM0-PORT12 output pwm"
+                        default n
+                    endif
+            endif
+        endif
+
+    menuconfig BSP_USING_SPI
+        bool "Enable SPI BUS"
+        select RT_USING_SPI
+        default n
+        if BSP_USING_SPI
+            menuconfig BSP_USING_SPI0
+                bool "Enable SPI0 BUS"
+                default n
+                if BSP_USING_SPI0
+                    config BSP_USING_SPI0_SAMPLE
+                        bool "Enable SPI0 BUS Sample"
+                        default n
+                endif
+            menuconfig BSP_USING_SPI3
+                bool "Enable SPI3 BUS"
+                default n
+                if BSP_USING_SPI3
+                    config BSP_USING_SPI3_SAMPLE
+                        bool "Enable SPI3 BUS Sample"
+                        default n
+                endif
+        endif
+
+    menuconfig BSP_USING_ADC
+        bool "Enable ADC"
+        default n
+        select RT_USING_ADC
+        if BSP_USING_ADC
+            config BSP_USING_ADC1
+                bool "Enable ADC1"
+                default n
+        endif
+
+    config BSP_USING_SDMMC
+        bool "Enable SDMMC (sd card)"
+        default n
+        select RT_USING_SDIO
+        select RT_USING_DFS
+        select RT_USING_DFS_ELMFAT
+        if BSP_USING_SDMMC
+            config BSP_USING_SDIO1
+                bool "Enable SDIO1 (sd card)"
+                default n
+        endif
+
+    menuconfig BSP_USING_HW_I2C
+        bool "Enable Hardware I2C Bus"
+        default n
+        select RT_USING_I2C
+        select RT_USING_PIN
+        if BSP_USING_HW_I2C
+            config BSP_USING_HW_I2C3
+                bool "Enable I2C3 Bus (User I2C)"
+                default n
+                if BSP_USING_HW_I2C3
+                    comment "Notice: P6_0 --> 48; P6_1 --> 49"
+                    config BSP_I2C3_SCL_PIN
+                        int "i2c3 SCL pin number"
+                        range 1 113
+                        default 48
+                    config BSP_I2C3_SDA_PIN
+                        int "i2c3 SDA pin number"
+                        range 1 113
+                        default 49
+                endif
+            config BSP_USING_HW_I2C6
+                bool "Enable I2C6 Bus (User I2C)"
+                default n
+                if BSP_USING_HW_I2C6
+                    comment "Notice: P13_0 --> 48; P13_1 --> 49"
+                    config BSP_I2C6_SCL_PIN
+                        int "i2c6 SCL pin number"
+                        range 1 113
+                        default 104
+                    config BSP_I2C6_SDA_PIN
+                        int "i2c6 SDA pin number"
+                        range 1 113
+                        default 105
+                endif
+        endif
+
+    menuconfig BSP_USING_I2C
+        bool "Enable Software I2C Bus"
+        default n
+        select RT_USING_I2C
+        select RT_USING_I2C_BITOPS
+        select RT_USING_PIN
+        if BSP_USING_I2C
+            config BSP_USING_I2C1
+                bool "Enable I2C1 Bus (User I2C)"
+                default n
+                if BSP_USING_I2C1
+                    comment "Notice: P13_1 --> 105; P13_2 --> 106"
+                    config BSP_I2C1_SCL_PIN
+                        int "i2c1 SCL pin number"
+                        range 1 113
+                        default 105
+                    config BSP_I2C1_SDA_PIN
+                        int "i2c1 SDA pin number"
+                        range 1 113
+                        default 106
+                endif
+        endif
+
+    menuconfig BSP_USING_RTC
+        bool "Enable RTC"
+        select RT_USING_RTC
+        default n
+        if BSP_USING_RTC
+            choice
+                prompt "Select clock source"
+                default BSP_RTC_USING_LSE
+
+                config BSP_RTC_USING_LSE
+                    bool "RTC USING LSE"
+
+                config BSP_RTC_USING_LSI
+                    bool "RTC USING LSI"
+            endchoice
+        endif
+
+    config BSP_USING_ON_CHIP_FLASH
+        bool "Enable on-chip FLASH"
+        default n
+
+    config BSP_USING_WDT
+        bool "Enable Watchdog Timer"
+        select RT_USING_WDT
+        default n
+
+    menuconfig BSP_USING_DAC
+        bool "Enable DAC"
+        default n
+        select RT_USING_DAC
+        if BSP_USING_DAC
+            config BSP_USING_DAC1
+                bool "Enable DAC1"
+                default n
+            config BSP_USING_DAC2
+                bool "Enable DAC2"
+                default n
+        endif
+
+    menuconfig BSP_USING_TIM
+        bool "Enable timer"
+        default n
+        select RT_USING_HWTIMER
+        if BSP_USING_TIM
+            config BSP_USING_TIM1
+                bool "Enable TIM1"
+                default n
+            config BSP_USING_TIM2
+                bool "Enable TIM2"
+                default n
+        endif
+endmenu
+
+menu "Board extended module Drivers"
+
+    config BSP_USING_SLIDER
+        bool "Enable Slider Demo"
+        default n
+
+        menuconfig BSP_USING_RW007
+            bool "Enable RW007"
+            default n
+            select PKG_USING_RW007
+            select BSP_USING_SPI
+            select BSP_USING_SPI0
+            select RW007_NOT_USE_EXAMPLE_DRIVERS
+
+        if BSP_USING_RW007
+            comment "Notice: P5_7 --> 47; P5_6 -->46; P0_5 --> 5; P0_4 --> 4"
+            config IFX_RW007_SPI_BUS_NAME
+                string "RW007 BUS NAME"
+                default "spi0"
+
+            config IFX_RW007_WIFI_SSID
+                string "Wi-Fi SSID"
+                default "realthread_VIP"
+
+            config IFX_RW007_WIFI_PASSWORD
+                string "Wi-Fi Password"
+                default "your wifi password"
+
+            config IFX_RW007_CS_PIN
+                int "(INT)CS pin index"
+                range 1 113
+                default 5
+
+            config IFX_RW007_BOOT0_PIN
+                int "(INT)BOOT0 pin index (same as spi clk pin)"
+                range 1 113
+                default 4
+
+            config IFX_RW007_BOOT1_PIN
+                int "(INT)BOOT1 pin index (same as spi cs pin)"
+                range 1 113
+                default 5
+
+            config IFX_RW007_INT_BUSY_PIN
+                int "(INT)INT/BUSY pin index"
+                range 1 113
+                default 47
+
+            config IFX_RW007_RST_PIN
+                int "(INT)RESET pin index"  
+                range 1 113
+                default 46
+        endif
+endmenu
+
+endmenu

+ 40 - 0
project_0/board/SConscript

@@ -0,0 +1,40 @@
+import os
+import rtconfig
+from building import *
+
+Import('SDK_LIB')
+
+objs = []
+cwd = GetCurrentDir()
+list = os.listdir(cwd)
+
+# add general drivers
+src = Split('''
+board.c
+''')
+
+if GetDepend(['BSP_USING_SPI3_SAMPLE']):
+    src += Glob('ports/spi_sample.c')
+
+if GetDepend(['BSP_USING_RW007']):
+    src += Glob('ports/drv_rw007.c')
+
+if GetDepend(['BSP_USING_SLIDER']):
+    src += Glob('ports/slider_sample.c')
+
+path = [cwd]
+path += [cwd + '/ports']
+
+startup_path_prefix = SDK_LIB
+
+if rtconfig.PLATFORM in ['gcc']:
+    src += [startup_path_prefix +
+            '/IFX_PSOC6_HAL/mtb-pdl-cat1/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_gcc.S']
+elif rtconfig.PLATFORM in ['armclang']:
+    src += [startup_path_prefix +
+            '/IFX_PSOC6_HAL/mtb-pdl-cat1/drivers/source/TOOLCHAIN_ARM/cy_syslib_mdk.S']
+
+CPPDEFINES = ['CY8C624ALQI_S2D42', 'CY_USING_HAL', 'COMPONENT_CAT1A', 'COMPONENT_CAT1', 'COMPONENT_BSP_DESIGN_MODUS']
+group = DefineGroup('Drivers', src, depend=[''], CPPPATH=path, CPPDEFINES=CPPDEFINES)
+
+Return('group')

+ 25 - 0
project_0/board/board.c

@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-06-29     Rbb666       first version
+ */
+
+#include "board.h"
+
+void cy_bsp_all_init(void)
+{
+    cy_rslt_t result;
+
+    /* Initialize the device and board peripherals */
+    result = cybsp_init();
+
+    /* Board init failed. Stop program execution */
+    if (result != CY_RSLT_SUCCESS)
+    {
+        CY_ASSERT(0);
+    }
+}

+ 63 - 0
project_0/board/board.h

@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-06-29     Rbb666       first version
+ * 2022-07-26     Rbb666       Add Flash Config
+ */
+
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+#include <rtthread.h>
+#include "drv_common.h"
+#include "drv_gpio.h"
+
+#include "cy_result.h"
+#include "cybsp_types.h"
+#include "cyhal.h"
+#include "cybsp.h"
+
+#ifdef BSP_USING_USBD
+    #include "cy_usb_dev.h"
+    #include "cy_usb_dev_hid.h"
+    #include "cycfg_usbdev.h"
+#endif
+
+/*FLASH CONFIG*/
+#define IFX_FLASH_START_ADRESS          ((uint32_t)0x10000000)
+#define IFX_FLASH_PAGE_SIZE             (256 * 1024)
+#define IFX_FLASH_SIZE                  (2 * 1024 * 1024)
+#define IFX_FLASH_END_ADDRESS           ((uint32_t)(IFX_FLASH_START_ADRESS + IFX_FLASH_SIZE))
+
+/*EFLASH CONFIG*/
+#define IFX_EFLASH_START_ADRESS         ((uint32_t)0x14000000)
+#define IFX_EFLASH_PAGE_SIZE            (32 * 1024)
+#define IFX_EFLASH_SIZE                 (32 * 1024)
+#define IFX_EFLASH_END_ADDRESS          ((uint32_t)(IFX_EFLASH_START_ADRESS + IFX_EFLASH_SIZE))
+
+/*SRAM CONFIG*/
+#define IFX_SRAM_SIZE                   (1014)
+#define IFX_SRAM_END                    (0x08002000 + IFX_SRAM_SIZE * 1024)
+
+#ifdef __ARMCC_VERSION
+    extern int Image$$RW_IRAM1$$ZI$$Limit;
+    #define HEAP_BEGIN    (&Image$$RW_IRAM1$$ZI$$Limit)
+    #define HEAP_END        IFX_SRAM_END
+#elif __ICCARM__
+    #pragma section="HEAP"
+    #define HEAP_BEGIN    (__segment_end("HEAP"))
+#else
+    extern unsigned int __end__;
+    extern unsigned int __HeapLimit;
+    #define HEAP_BEGIN    (void*)&__end__
+    #define HEAP_END      (void*)&__HeapLimit
+#endif
+
+void cy_bsp_all_init(void);
+
+#endif
+

+ 247 - 0
project_0/board/linker_scripts/link.icf

@@ -0,0 +1,247 @@
+/*******************************************************************************
+* \file cy8c6xxa_cm4_dual.icf
+* \version 2.91
+*
+* Linker file for the IAR compiler.
+*
+* The main purpose of the linker script is to describe how the sections in the
+* input files should be mapped into the output file, and to control the memory
+* layout of the output file.
+*
+* \note The entry point is fixed and starts at 0x10000000. The valid application
+* image should be placed there.
+*
+* \note The linker files included with the PDL template projects must be generic
+* and handle all common use cases. Your project may not use every section
+* defined in the linker files. In that case you may see warnings during the
+* build process. In your project, you can simply comment out or remove the
+* relevant code in the linker file.
+*
+********************************************************************************
+* \copyright
+* Copyright 2016-2021 Cypress Semiconductor Corporation
+* SPDX-License-Identifier: Apache-2.0
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+
+/*###ICF### Section handled by ICF editor, don't touch! ****/
+/*-Editor annotation file-*/
+/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_4.xml" */
+/*-Specials-*/
+define symbol __ICFEDIT_intvec_start__ = 0x00000000;
+
+/* The symbols below define the location and size of blocks of memory in the target.
+ * Use these symbols to specify the memory regions available for allocation.
+ */
+
+/* The following symbols control RAM and flash memory allocation for the CM4 core.
+ * You can change the memory allocation by editing RAM and Flash symbols.
+ * Note that 2 KB of RAM (at the end of the SRAM) are reserved for system use.
+ * Using this memory region for other purposes will lead to unexpected behavior.
+ * Your changes must be aligned with the corresponding symbols for CM0+ core in 'xx_cm0plus.icf',
+ * where 'xx' is the device group; for example, 'cy8c6xx7_cm0plus.icf'.
+ */
+/* RAM */
+define symbol __ICFEDIT_region_IRAM1_start__ = 0x08002000;
+define symbol __ICFEDIT_region_IRAM1_end__   = 0x080FF7FF;
+
+/* Flash */
+define symbol __ICFEDIT_region_IROM1_start__ = 0x10000000;
+define symbol __ICFEDIT_region_IROM1_end__   = 0x101FFFFF;
+
+/* The following symbols define a 32K flash region used for EEPROM emulation.
+ * This region can also be used as the general purpose flash.
+ * You can assign sections to this memory region for only one of the cores.
+ * Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region.
+ * Therefore, repurposing this memory region will prevent such middleware from operation.
+ */
+define symbol __ICFEDIT_region_IROM2_start__ = 0x14000000;
+define symbol __ICFEDIT_region_IROM2_end__   = 0x14007FFF;
+
+/* The following symbols define device specific memory regions and must not be changed. */
+/* Supervisory FLASH - User Data */
+define symbol __ICFEDIT_region_IROM3_start__ = 0x16000800;
+define symbol __ICFEDIT_region_IROM3_end__   = 0x16000FFF;
+
+/* Supervisory FLASH - Normal Access Restrictions (NAR) */
+define symbol __ICFEDIT_region_IROM4_start__ = 0x16001A00;
+define symbol __ICFEDIT_region_IROM4_end__   = 0x16001BFF;
+
+/* Supervisory FLASH - Public Key */
+define symbol __ICFEDIT_region_IROM5_start__ = 0x16005A00;
+define symbol __ICFEDIT_region_IROM5_end__   = 0x160065FF;
+
+/* Supervisory FLASH - Table of Content # 2 */
+define symbol __ICFEDIT_region_IROM6_start__ = 0x16007C00;
+define symbol __ICFEDIT_region_IROM6_end__   = 0x16007DFF;
+
+/* Supervisory FLASH - Table of Content # 2 Copy */
+define symbol __ICFEDIT_region_IROM7_start__ = 0x16007E00;
+define symbol __ICFEDIT_region_IROM7_end__   = 0x16007FFF;
+
+/* eFuse */
+define symbol __ICFEDIT_region_IROM8_start__ = 0x90700000;
+define symbol __ICFEDIT_region_IROM8_end__   = 0x907FFFFF;
+
+/* XIP */
+define symbol __ICFEDIT_region_EROM1_start__ = 0x18000000;
+define symbol __ICFEDIT_region_EROM1_end__   = 0x1FFFFFFF;
+
+define symbol __ICFEDIT_region_EROM2_start__ = 0x0;
+define symbol __ICFEDIT_region_EROM2_end__   = 0x0;
+define symbol __ICFEDIT_region_EROM3_start__ = 0x0;
+define symbol __ICFEDIT_region_EROM3_end__   = 0x0;
+
+
+define symbol __ICFEDIT_region_IRAM2_start__ = 0x0;
+define symbol __ICFEDIT_region_IRAM2_end__   = 0x0;
+define symbol __ICFEDIT_region_ERAM1_start__ = 0x0;
+define symbol __ICFEDIT_region_ERAM1_end__   = 0x0;
+define symbol __ICFEDIT_region_ERAM2_start__ = 0x0;
+define symbol __ICFEDIT_region_ERAM2_end__   = 0x0;
+define symbol __ICFEDIT_region_ERAM3_start__ = 0x0;
+define symbol __ICFEDIT_region_ERAM3_end__   = 0x0;
+/*-Sizes-*/
+if (!isdefinedsymbol(__STACK_SIZE)) {
+  define symbol __ICFEDIT_size_cstack__ = 0x1000;
+} else {
+  define symbol __ICFEDIT_size_cstack__ = __STACK_SIZE;
+}
+define symbol __ICFEDIT_size_proc_stack__ = 0x0;
+
+/* Defines the minimum heap size. The actual heap size will be expanded to the end of the stack region */
+if (!isdefinedsymbol(__HEAP_SIZE)) {
+    define symbol __ICFEDIT_size_heap__ = 0x0400;
+} else {
+  define symbol __ICFEDIT_size_heap__ = __HEAP_SIZE;
+}
+/**** End of ICF editor section. ###ICF###*/
+
+/* By default, the COMPONENT_CM0P_SLEEP prebuilt image is used for the CM0p core.
+ * More about CM0+ prebuilt images, see here:
+ * https://github.com/cypresssemiconductorco/psoc6cm0p
+ */
+/* The size of the Cortex-M0+ application image */
+define symbol FLASH_CM0P_SIZE  = 0x2000;
+
+define memory mem with size = 4G;
+define region IROM1_region = mem:[from __ICFEDIT_region_IROM1_start__ to __ICFEDIT_region_IROM1_end__];
+define region IROM2_region = mem:[from __ICFEDIT_region_IROM2_start__ to __ICFEDIT_region_IROM2_end__];
+define region IROM3_region = mem:[from __ICFEDIT_region_IROM3_start__ to __ICFEDIT_region_IROM3_end__];
+define region IROM4_region = mem:[from __ICFEDIT_region_IROM4_start__ to __ICFEDIT_region_IROM4_end__];
+define region IROM5_region = mem:[from __ICFEDIT_region_IROM5_start__ to __ICFEDIT_region_IROM5_end__];
+define region IROM6_region = mem:[from __ICFEDIT_region_IROM6_start__ to __ICFEDIT_region_IROM6_end__];
+define region IROM7_region = mem:[from __ICFEDIT_region_IROM7_start__ to __ICFEDIT_region_IROM7_end__];
+define region IROM8_region = mem:[from __ICFEDIT_region_IROM8_start__ to __ICFEDIT_region_IROM8_end__];
+define region EROM1_region = mem:[from __ICFEDIT_region_EROM1_start__ to __ICFEDIT_region_EROM1_end__];
+define region IRAM1_region = mem:[from __ICFEDIT_region_IRAM1_start__ to __ICFEDIT_region_IRAM1_end__];
+
+define block CSTACK     with alignment = 8, size = __ICFEDIT_size_cstack__     { };
+define block PROC_STACK with alignment = 8, size = __ICFEDIT_size_proc_stack__ { };
+define block HEAP       with expanding size, alignment = 8, minimum size = __ICFEDIT_size_heap__ { };
+define block HSTACK {block HEAP, block PROC_STACK, last block CSTACK};
+define block CM0P_RO with size = FLASH_CM0P_SIZE  { readonly section .cy_m0p_image };
+define block RO     {first section .intvec, readonly};
+
+define block cy_xip { section .cy_xip };
+
+/*-Initializations-*/
+initialize by copy { readwrite };
+do not initialize  { section .noinit, section .intvec_ram };
+
+/*-Placement-*/
+
+/* Flash - Cortex-M0+ application image */
+place at start of IROM1_region  { block CM0P_RO };
+
+/* Flash - Cortex-M4 application */
+place in          IROM1_region  { block RO };
+
+/* Used for the digital signature of the secure application and the Bootloader SDK application. */
+".cy_app_signature" : place at address (__ICFEDIT_region_IROM1_end__ - 0x200) { section .cy_app_signature };
+
+/* Emulated EEPROM Flash area */
+".cy_em_eeprom" : place at start of IROM2_region  { section .cy_em_eeprom };
+
+/* Supervisory Flash - User Data */
+".cy_sflash_user_data" : place at start of IROM3_region  { section .cy_sflash_user_data };
+
+/* Supervisory Flash - NAR */
+".cy_sflash_nar" : place at start of IROM4_region  { section .cy_sflash_nar };
+
+/* Supervisory Flash - Public Key */
+".cy_sflash_public_key" : place at start of IROM5_region  { section .cy_sflash_public_key };
+
+/* Supervisory Flash - TOC2 */
+".cy_toc_part2" : place at start of IROM6_region  { section .cy_toc_part2 };
+
+/* Supervisory Flash - RTOC2 */
+".cy_rtoc_part2" : place at start of IROM7_region  { section .cy_rtoc_part2 };
+
+/* eFuse */
+".cy_efuse" : place at start of IROM8_region  { section .cy_efuse };
+
+/* Execute in Place (XIP). See the smif driver documentation for details. */
+"cy_xip" : place at start of EROM1_region  { block cy_xip };
+
+/* RAM */
+place at start of IRAM1_region  { readwrite section .intvec_ram};
+place in          IRAM1_region  { readwrite };
+place at end   of IRAM1_region  { block HSTACK };
+
+/* These sections are used for additional metadata (silicon revision, Silicon/JTAG ID, etc.) storage. */
+".cymeta" : place at address mem : 0x90500000 { readonly section .cymeta };
+
+
+keep {  section .cy_m0p_image,
+        section .cy_app_signature,
+        section .cy_em_eeprom,
+        section .cy_sflash_user_data,
+        section .cy_sflash_nar,
+        section .cy_sflash_public_key,
+        section .cy_toc_part2,
+        section .cy_rtoc_part2,
+        section .cy_efuse,
+        section .cy_xip,
+        section .cymeta,
+         };
+
+
+/* The following symbols used by the cymcuelftool. */
+/* Flash */
+define exported symbol __cy_memory_0_start    = 0x10000000;
+define exported symbol __cy_memory_0_length   = 0x00200000;
+define exported symbol __cy_memory_0_row_size = 0x200;
+
+/* Emulated EEPROM Flash area */
+define exported symbol __cy_memory_1_start    = 0x14000000;
+define exported symbol __cy_memory_1_length   = 0x8000;
+define exported symbol __cy_memory_1_row_size = 0x200;
+
+/* Supervisory Flash */
+define exported symbol __cy_memory_2_start    = 0x16000000;
+define exported symbol __cy_memory_2_length   = 0x8000;
+define exported symbol __cy_memory_2_row_size = 0x200;
+
+/* XIP */
+define exported symbol __cy_memory_3_start    = 0x18000000;
+define exported symbol __cy_memory_3_length   = 0x08000000;
+define exported symbol __cy_memory_3_row_size = 0x200;
+
+/* eFuse */
+define exported symbol __cy_memory_4_start    = 0x90700000;
+define exported symbol __cy_memory_4_length   = 0x100000;
+define exported symbol __cy_memory_4_row_size = 1;
+
+/* EOF */

+ 487 - 0
project_0/board/linker_scripts/link.ld

@@ -0,0 +1,487 @@
+/***************************************************************************//**
+* \file cy8c6xxa_cm4_dual.ld
+* \version 2.91
+*
+* Linker file for the GNU C compiler.
+*
+* The main purpose of the linker script is to describe how the sections in the
+* input files should be mapped into the output file, and to control the memory
+* layout of the output file.
+*
+* \note The entry point location is fixed and starts at 0x10000000. The valid
+* application image should be placed there.
+*
+* \note The linker files included with the PDL template projects must be generic
+* and handle all common use cases. Your project may not use every section
+* defined in the linker files. In that case you may see warnings during the
+* build process. In your project, you can simply comment out or remove the
+* relevant code in the linker file.
+*
+********************************************************************************
+* \copyright
+* Copyright 2016-2021 Cypress Semiconductor Corporation
+* SPDX-License-Identifier: Apache-2.0
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*******************************************************************************/
+
+OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
+SEARCH_DIR(.)
+GROUP(-lgcc -lc -lnosys)
+ENTRY(Reset_Handler)
+
+/* The size of the stack section at the end of CM4 SRAM */
+STACK_SIZE = 0x1000;
+
+/* By default, the COMPONENT_CM0P_SLEEP prebuilt image is used for the CM0p core.
+* More about CM0+ prebuilt images, see here:
+* https://github.com/cypresssemiconductorco/psoc6cm0p
+*/
+/* The size of the Cortex-M0+ application image at the start of FLASH */
+FLASH_CM0P_SIZE  = 0x2000;
+
+/* Force symbol to be entered in the output file as an undefined symbol. Doing
+* this may, for example, trigger linking of additional modules from standard
+* libraries. You may list several symbols for each EXTERN, and you may use
+* EXTERN multiple times. This command has the same effect as the -u command-line
+* option.
+*/
+EXTERN(Reset_Handler)
+
+/* The MEMORY section below describes the location and size of blocks of memory in the target.
+* Use this section to specify the memory regions available for allocation.
+*/
+MEMORY
+{
+    /* The ram and flash regions control RAM and flash memory allocation for the CM4 core.
+     * You can change the memory allocation by editing the 'ram' and 'flash' regions.
+     * Note that 2 KB of RAM (at the end of the SRAM) are reserved for system use.
+     * Using this memory region for other purposes will lead to unexpected behavior.
+     * Your changes must be aligned with the corresponding memory regions for CM0+ core in 'xx_cm0plus.ld',
+     * where 'xx' is the device group; for example, 'cy8c6xx7_cm0plus.ld'.
+     */
+    ram               (rwx)   : ORIGIN = 0x08002000, LENGTH = 0xFD800
+    flash             (rx)    : ORIGIN = 0x10000000, LENGTH = 0x200000
+
+    /* This is a 32K flash region used for EEPROM emulation. This region can also be used as the general purpose flash.
+     * You can assign sections to this memory region for only one of the cores.
+     * Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region.
+     * Therefore, repurposing this memory region will prevent such middleware from operation.
+     */
+    em_eeprom         (rx)    : ORIGIN = 0x14000000, LENGTH = 0x8000       /*  32 KB */
+
+    /* The following regions define device specific memory regions and must not be changed. */
+    sflash_user_data  (rx)    : ORIGIN = 0x16000800, LENGTH = 0x800        /* Supervisory flash: User data */
+    sflash_nar        (rx)    : ORIGIN = 0x16001A00, LENGTH = 0x200        /* Supervisory flash: Normal Access Restrictions (NAR) */
+    sflash_public_key (rx)    : ORIGIN = 0x16005A00, LENGTH = 0xC00        /* Supervisory flash: Public Key */
+    sflash_toc_2      (rx)    : ORIGIN = 0x16007C00, LENGTH = 0x200        /* Supervisory flash: Table of Content # 2 */
+    sflash_rtoc_2     (rx)    : ORIGIN = 0x16007E00, LENGTH = 0x200        /* Supervisory flash: Table of Content # 2 Copy */
+    xip               (rx)    : ORIGIN = 0x18000000, LENGTH = 0x8000000    /* 128 MB */
+    efuse             (r)     : ORIGIN = 0x90700000, LENGTH = 0x100000     /*   1 MB */
+}
+
+/* Library configurations */
+GROUP(libgcc.a libc.a libm.a libnosys.a)
+
+/* Linker script to place sections and symbol values. Should be used together
+ * with other linker script that defines memory regions FLASH and RAM.
+ * It references following symbols, which must be defined in code:
+ *   Reset_Handler : Entry of reset handler
+ *
+ * It defines following symbols, which code can use without definition:
+ *   __exidx_start
+ *   __exidx_end
+ *   __copy_table_start__
+ *   __copy_table_end__
+ *   __zero_table_start__
+ *   __zero_table_end__
+ *   __etext
+ *   __data_start__
+ *   __preinit_array_start
+ *   __preinit_array_end
+ *   __init_array_start
+ *   __init_array_end
+ *   __fini_array_start
+ *   __fini_array_end
+ *   __data_end__
+ *   __bss_start__
+ *   __bss_end__
+ *   __end__
+ *   end
+ *   __HeapLimit
+ *   __StackLimit
+ *   __StackTop
+ *   __stack
+ *   __Vectors_End
+ *   __Vectors_Size
+ */
+
+
+SECTIONS
+{
+     /* Cortex-M0+ application flash image area */
+    .cy_m0p_image ORIGIN(flash) :
+    {
+        . = ALIGN(4);
+        __cy_m0p_code_start = . ;
+        KEEP(*(.cy_m0p_image))
+        __cy_m0p_code_end = . ;
+    } > flash
+
+    /* Check if .cy_m0p_image size exceeds FLASH_CM0P_SIZE */
+    ASSERT(__cy_m0p_code_end <= ORIGIN(flash) + FLASH_CM0P_SIZE, "CM0+ flash image overflows with CM4, increase FLASH_CM0P_SIZE")
+
+    /* Cortex-M4 application flash area */
+    .text ORIGIN(flash) + FLASH_CM0P_SIZE :
+    {
+        . = ALIGN(4);
+        __Vectors = . ;
+        KEEP(*(.vectors))
+        . = ALIGN(4);
+        __Vectors_End = .;
+        __Vectors_Size = __Vectors_End - __Vectors;
+        __end__ = .;
+
+        . = ALIGN(4);
+        *(.text*)
+
+        KEEP(*(.init))
+        KEEP(*(.fini))
+
+        /* .ctors */
+        *crtbegin.o(.ctors)
+        *crtbegin?.o(.ctors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
+        *(SORT(.ctors.*))
+        *(.ctors)
+
+        /* .dtors */
+        *crtbegin.o(.dtors)
+        *crtbegin?.o(.dtors)
+        *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
+        *(SORT(.dtors.*))
+        *(.dtors)
+
+        . = ALIGN(4);
+        /* Read-only code (constants). */
+        *(.rodata .rodata.* .constdata .constdata.* .conststring .conststring.*)
+        KEEP(*(.eh_frame*))
+
+        /* section information for utest */
+        . = ALIGN(4);
+        __rt_utest_tc_tab_start = .;
+        KEEP(*(UtestTcTab))
+        __rt_utest_tc_tab_end = .;
+
+        /* section information for finsh shell */
+        . = ALIGN(4);
+        __fsymtab_start = .;
+        KEEP(*(FSymTab))
+        __fsymtab_end = .;
+        . = ALIGN(4);
+        __vsymtab_start = .;
+        KEEP(*(VSymTab))
+        __vsymtab_end = .;
+        . = ALIGN(4);
+
+        /* section information for modules */
+        . = ALIGN(4);
+        __rtmsymtab_start = .;
+        KEEP(*(RTMSymTab))
+        __rtmsymtab_end = .;
+
+        /* section information for initialization */
+        . = ALIGN(4);
+        __rt_init_start = .;
+        KEEP(*(SORT(.rti_fn*)))
+        __rt_init_end = .;
+
+    } > flash
+
+    .ARM.extab :
+    {
+        *(.ARM.extab* .gnu.linkonce.armextab.*)
+    } > flash
+
+    __exidx_start = .;
+
+    .ARM.exidx :
+    {
+        *(.ARM.exidx* .gnu.linkonce.armexidx.*)
+    } > flash
+    __exidx_end = .;
+
+
+    /* To copy multiple ROM to RAM sections,
+     * uncomment .copy.table section and,
+     * define __STARTUP_COPY_MULTIPLE in startup_psoc6_02_cm4.S */
+    .copy.table :
+    {
+        . = ALIGN(4);
+        __copy_table_start__ = .;
+
+        /* Copy interrupt vectors from flash to RAM */
+        LONG (__Vectors)                                    /* From */
+        LONG (__ram_vectors_start__)                        /* To   */
+        LONG (__Vectors_End - __Vectors)                    /* Size */
+
+        /* Copy data section to RAM */
+        LONG (__etext)                                      /* From */
+        LONG (__data_start__)                               /* To   */
+        LONG (__data_end__ - __data_start__)                /* Size */
+
+        __copy_table_end__ = .;
+    } > flash
+
+    . = ALIGN(4);
+    .ctors :
+    {
+        PROVIDE(__ctors_start__ = .);
+        KEEP (*(SORT(.init_array.*)))
+        KEEP (*(.init_array))
+        PROVIDE(__ctors_end__ = .);
+    } > flash
+
+    . = ALIGN(4);
+    .dtors :
+    {
+        PROVIDE(__dtors_start__ = .);
+        KEEP(*(SORT(.dtors.*)))
+        KEEP(*(.dtors))
+        PROVIDE(__dtors_end__ = .);
+    } > flash
+
+    /* To clear multiple BSS sections,
+     * uncomment .zero.table section and,
+     * define __STARTUP_CLEAR_BSS_MULTIPLE in startup_psoc6_02_cm4.S */
+    .zero.table :
+    {
+        . = ALIGN(4);
+        __zero_table_start__ = .;
+        LONG (__bss_start__)
+        LONG (__bss_end__ - __bss_start__)
+        __zero_table_end__ = .;
+    } > flash
+
+    __etext =  . ;
+
+    .ramVectors (NOLOAD) : ALIGN(8)
+    {
+        __ram_vectors_start__ = .;
+        KEEP(*(.ram_vectors))
+        __ram_vectors_end__   = .;
+    } > ram
+
+
+    .data __ram_vectors_end__ :
+    {
+        . = ALIGN(4);
+        __data_start__ = .;
+
+        *(vtable)
+        *(.data*)
+
+        . = ALIGN(4);
+        /* preinit data */
+        PROVIDE_HIDDEN (__preinit_array_start = .);
+        KEEP(*(.preinit_array))
+        PROVIDE_HIDDEN (__preinit_array_end = .);
+
+        . = ALIGN(4);
+        /* init data */
+        PROVIDE_HIDDEN (__init_array_start = .);
+        KEEP(*(SORT(.init_array.*)))
+        KEEP(*(.init_array))
+        PROVIDE_HIDDEN (__init_array_end = .);
+
+        . = ALIGN(4);
+        /* finit data */
+        PROVIDE_HIDDEN (__fini_array_start = .);
+        KEEP(*(SORT(.fini_array.*)))
+        KEEP(*(.fini_array))
+        PROVIDE_HIDDEN (__fini_array_end = .);
+
+        KEEP(*(.jcr*))
+        . = ALIGN(4);
+
+        KEEP(*(.cy_ramfunc*))
+        . = ALIGN(4);
+
+        __data_end__ = .;
+
+    } > ram AT>flash
+
+
+    /* Place variables in the section that should not be initialized during the
+    *  device startup.
+    */
+    .noinit (NOLOAD) : ALIGN(8)
+    {
+      KEEP(*(.noinit))
+    } > ram
+
+
+    /* The uninitialized global or static variables are placed in this section.
+    *
+    * The NOLOAD attribute tells linker that .bss section does not consume
+    * any space in the image. The NOLOAD attribute changes the .bss type to
+    * NOBITS, and that  makes linker to A) not allocate section in memory, and
+    * A) put information to clear the section with all zeros during application
+    * loading.
+    *
+    * Without the NOLOAD attribute, the .bss section might get PROGBITS type.
+    * This  makes linker to A) allocate zeroed section in memory, and B) copy
+    * this section to RAM during application loading.
+    */
+    .bss (NOLOAD):
+    {
+        . = ALIGN(4);
+        __bss_start__ = .;
+        *(.bss*)
+        *(COMMON)
+        . = ALIGN(4);
+        __bss_end__ = .;
+    } > ram
+
+
+    .heap (NOLOAD):
+    {
+        __HeapBase = .;
+        __end__ = .;
+        end = __end__;
+        KEEP(*(.heap*))
+        . = ORIGIN(ram) + LENGTH(ram) - STACK_SIZE;
+        __HeapLimit = .;
+    } > ram
+
+
+    /* .stack_dummy section doesn't contains any symbols. It is only
+     * used for linker to calculate size of stack sections, and assign
+     * values to stack symbols later */
+    .stack_dummy (NOLOAD):
+    {
+        KEEP(*(.stack*))
+    } > ram
+
+
+    /* Set stack top to end of RAM, and stack limit move down by
+     * size of stack_dummy section */
+    __StackTop = ORIGIN(ram) + LENGTH(ram);
+    __StackLimit = __StackTop - SIZEOF(.stack_dummy);
+    PROVIDE(__stack = __StackTop);
+
+    /* Check if data + heap + stack exceeds RAM limit */
+    ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
+
+
+    /* Used for the digital signature of the secure application and the Bootloader SDK application.
+    * The size of the section depends on the required data size. */
+    .cy_app_signature ORIGIN(flash) + LENGTH(flash) - 256 :
+    {
+        KEEP(*(.cy_app_signature))
+    } > flash
+
+
+    /* Emulated EEPROM Flash area */
+    .cy_em_eeprom :
+    {
+        KEEP(*(.cy_em_eeprom))
+    } > em_eeprom
+
+
+    /* Supervisory Flash: User data */
+    .cy_sflash_user_data :
+    {
+        KEEP(*(.cy_sflash_user_data))
+    } > sflash_user_data
+
+    /* Supervisory Flash: Normal Access Restrictions (NAR) */
+    .cy_sflash_nar :
+    {
+        KEEP(*(.cy_sflash_nar))
+    } > sflash_nar
+
+
+    /* Supervisory Flash: Public Key */
+    .cy_sflash_public_key :
+    {
+        KEEP(*(.cy_sflash_public_key))
+    } > sflash_public_key
+
+
+    /* Supervisory Flash: Table of Content # 2 */
+    .cy_toc_part2 :
+    {
+        KEEP(*(.cy_toc_part2))
+    } > sflash_toc_2
+
+
+    /* Supervisory Flash: Table of Content # 2 Copy */
+    .cy_rtoc_part2 :
+    {
+        KEEP(*(.cy_rtoc_part2))
+    } > sflash_rtoc_2
+
+
+    /* Places the code in the Execute in Place (XIP) section. See the smif driver
+    *  documentation for details.
+    */
+    cy_xip :
+    {
+        __cy_xip_start = .;
+        KEEP(*(.cy_xip))
+        __cy_xip_end = .;
+    } > xip
+
+
+    /* eFuse */
+    .cy_efuse :
+    {
+        KEEP(*(.cy_efuse))
+    } > efuse
+
+
+    /* These sections are used for additional metadata (silicon revision,
+    *  Silicon/JTAG ID, etc.) storage.
+    */
+    .cymeta         0x90500000 : { KEEP(*(.cymeta)) } :NONE
+}
+
+
+/* The following symbols used by the cymcuelftool. */
+/* Flash */
+__cy_memory_0_start    = 0x10000000;
+__cy_memory_0_length   = 0x00200000;
+__cy_memory_0_row_size = 0x200;
+
+/* Emulated EEPROM Flash area */
+__cy_memory_1_start    = 0x14000000;
+__cy_memory_1_length   = 0x8000;
+__cy_memory_1_row_size = 0x200;
+
+/* Supervisory Flash */
+__cy_memory_2_start    = 0x16000000;
+__cy_memory_2_length   = 0x8000;
+__cy_memory_2_row_size = 0x200;
+
+/* XIP */
+__cy_memory_3_start    = 0x18000000;
+__cy_memory_3_length   = 0x08000000;
+__cy_memory_3_row_size = 0x200;
+
+/* eFuse */
+__cy_memory_4_start    = 0x90700000;
+__cy_memory_4_length   = 0x100000;
+__cy_memory_4_row_size = 1;
+
+/* EOF */

+ 277 - 0
project_0/board/linker_scripts/link.sct

@@ -0,0 +1,277 @@
+#! armclang -E --target=arm-arm-none-eabi -x c -mcpu=cortex-m4
+; The first line specifies a preprocessor command that the linker invokes
+; to pass a scatter file through a C preprocessor.
+
+;*******************************************************************************
+;* \file cy8c6xxa_cm4_dual.sct
+;* \version 2.91
+;*
+;* Linker file for the ARMCC.
+;*
+;* The main purpose of the linker script is to describe how the sections in the
+;* input files should be mapped into the output file, and to control the memory
+;* layout of the output file.
+;*
+;* \note The entry point location is fixed and starts at 0x10000000. The valid
+;* application image should be placed there.
+;*
+;* \note The linker files included with the PDL template projects must be
+;* generic and handle all common use cases. Your project may not use every
+;* section defined in the linker files. In that case you may see the warnings
+;* during the build process: L6314W (no section matches pattern) and/or L6329W
+;* (pattern only matches removed unused sections). In your project, you can
+;* suppress the warning by passing the "--diag_suppress=L6314W,L6329W" option to
+;* the linker, simply comment out or remove the relevant code in the linker
+;* file.
+;*
+;*******************************************************************************
+;* \copyright
+;* Copyright 2016-2021 Cypress Semiconductor Corporation
+;* SPDX-License-Identifier: Apache-2.0
+;*
+;* Licensed under the Apache License, Version 2.0 (the "License");
+;* you may not use this file except in compliance with the License.
+;* You may obtain a copy of the License at
+;*
+;*     http://www.apache.org/licenses/LICENSE-2.0
+;*
+;* Unless required by applicable law or agreed to in writing, software
+;* distributed under the License is distributed on an "AS IS" BASIS,
+;* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+;* See the License for the specific language governing permissions and
+;* limitations under the License.
+;******************************************************************************/
+
+; The defines below describe the location and size of blocks of memory in the target.
+; Use these defines to specify the memory regions available for allocation.
+
+; The following defines control RAM and flash memory allocation for the CM4 core.
+; You can change the memory allocation by editing RAM and Flash defines.
+; Note that 2 KB of RAM (at the end of the SRAM) are reserved for system use.
+; Using this memory region for other purposes will lead to unexpected behavior.
+; Your changes must be aligned with the corresponding defines for CM0+ core in 'xx_cm0plus.scat',
+; where 'xx' is the device group; for example, 'cy8c6xx7_cm0plus.scat'.
+; RAM
+#define RAM_START               0x08002000
+#define RAM_SIZE                0x000FD800
+; Flash
+#define FLASH_START             0x10000000
+#define FLASH_SIZE              0x00200000
+
+; The size of the stack section at the end of CM4 SRAM
+#define STACK_SIZE              0x00001000
+
+; By default, the COMPONENT_CM0P_SLEEP prebuilt image is used for the CM0p core.
+; More about CM0+ prebuilt images, see here:
+; https://github.com/cypresssemiconductorco/psoc6cm0p
+; The size of the Cortex-M0+ application flash image
+#define FLASH_CM0P_SIZE         0x2000
+
+; The following defines describe a 32K flash region used for EEPROM emulation.
+; This region can also be used as the general purpose flash.
+; You can assign sections to this memory region for only one of the cores.
+; Note some middleware (e.g. BLE, Emulated EEPROM) can place their data into this memory region.
+; Therefore, repurposing this memory region will prevent such middleware from operation.
+#define EM_EEPROM_START         0x14000000
+#define EM_EEPROM_SIZE          0x8000
+
+; The following defines describe device specific memory regions and must not be changed.
+; Supervisory flash: User data
+#define SFLASH_USER_DATA_START  0x16000800
+#define SFLASH_USER_DATA_SIZE   0x00000800
+
+; Supervisory flash: Normal Access Restrictions (NAR)
+#define SFLASH_NAR_START        0x16001A00
+#define SFLASH_NAR_SIZE         0x00000200
+
+; Supervisory flash: Public Key
+#define SFLASH_PUBLIC_KEY_START 0x16005A00
+#define SFLASH_PUBLIC_KEY_SIZE  0x00000C00
+
+; Supervisory flash: Table of Content # 2
+#define SFLASH_TOC_2_START      0x16007C00
+#define SFLASH_TOC_2_SIZE       0x00000200
+
+; Supervisory flash: Table of Content # 2 Copy
+#define SFLASH_RTOC_2_START     0x16007E00
+#define SFLASH_RTOC_2_SIZE      0x00000200
+
+; External memory
+#define XIP_START               0x18000000
+#define XIP_SIZE                0x08000000
+
+; eFuse
+#define EFUSE_START             0x90700000
+#define EFUSE_SIZE              0x100000
+
+
+; Cortex-M0+ application flash image area
+LR_IROM FLASH_START FLASH_CM0P_SIZE
+{
+    .cy_m0p_image +0 FLASH_CM0P_SIZE
+    {
+        * (.cy_m0p_image)
+    }
+}
+
+; Cortex-M4 application flash area
+LR_IROM1 (FLASH_START + FLASH_CM0P_SIZE) (FLASH_SIZE - FLASH_CM0P_SIZE)
+{
+    ER_FLASH_VECTORS +0
+    {
+        * (RESET, +FIRST)
+    }
+
+    ER_FLASH_CODE +0 FIXED
+    {
+        * (InRoot$$Sections)
+        * (+RO)
+    }
+
+    ER_RAM_VECTORS RAM_START UNINIT
+    {
+        * (RESET_RAM, +FIRST)
+    }
+
+    RW_RAM_DATA +0
+    {
+        * (.cy_ramfunc)
+        * (+RW, +ZI)
+    }
+
+    ; Place variables in the section that should not be initialized during the
+    ; device startup.
+    RW_IRAM1 +0 UNINIT
+    {
+        * (.noinit)
+    }
+
+    ; Application heap area (HEAP)
+    ARM_LIB_HEAP  +0 EMPTY ((RAM_START+RAM_SIZE)-AlignExpr(ImageLimit(RW_IRAM1), 8)-STACK_SIZE)
+    {
+    }
+
+    ; Stack region growing down
+    ARM_LIB_STACK (RAM_START+RAM_SIZE) EMPTY -STACK_SIZE
+    {
+    }
+
+    ; Used for the digital signature of the secure application and the
+    ; Bootloader SDK application. The size of the section depends on the required
+    ; data size.
+    .cy_app_signature (FLASH_START + FLASH_SIZE - 256) 256
+    {
+        * (.cy_app_signature)
+    }
+}
+
+
+; Emulated EEPROM Flash area
+LR_EM_EEPROM EM_EEPROM_START EM_EEPROM_SIZE
+{
+    .cy_em_eeprom +0
+    {
+        * (.cy_em_eeprom)
+    }
+}
+
+; Supervisory flash: User data
+LR_SFLASH_USER_DATA SFLASH_USER_DATA_START SFLASH_USER_DATA_SIZE
+{
+    .cy_sflash_user_data +0
+    {
+        * (.cy_sflash_user_data)
+    }
+}
+
+; Supervisory flash: Normal Access Restrictions (NAR)
+LR_SFLASH_NAR SFLASH_NAR_START SFLASH_NAR_SIZE
+{
+    .cy_sflash_nar +0
+    {
+        * (.cy_sflash_nar)
+    }
+}
+
+; Supervisory flash: Public Key
+LR_SFLASH_PUBLIC_KEY SFLASH_PUBLIC_KEY_START SFLASH_PUBLIC_KEY_SIZE
+{
+    .cy_sflash_public_key +0
+    {
+        * (.cy_sflash_public_key)
+    }
+}
+
+; Supervisory flash: Table of Content # 2
+LR_SFLASH_TOC_2 SFLASH_TOC_2_START SFLASH_TOC_2_SIZE
+{
+    .cy_toc_part2 +0
+    {
+        * (.cy_toc_part2)
+    }
+}
+
+; Supervisory flash: Table of Content # 2 Copy
+LR_SFLASH_RTOC_2 SFLASH_RTOC_2_START SFLASH_RTOC_2_SIZE
+{
+    .cy_rtoc_part2 +0
+    {
+        * (.cy_rtoc_part2)
+    }
+}
+
+
+; Places the code in the Execute in Place (XIP) section. See the smif driver documentation for details.
+LR_EROM XIP_START XIP_SIZE
+{
+    cy_xip +0
+    {
+        * (.cy_xip)
+    }
+}
+
+
+; eFuse
+LR_EFUSE EFUSE_START EFUSE_SIZE
+{
+    .cy_efuse +0
+    {
+        * (.cy_efuse)
+    }
+}
+
+
+; The section is used for additional metadata (silicon revision, Silicon/JTAG ID, etc.) storage.
+CYMETA 0x90500000
+{
+    .cymeta +0 { * (.cymeta) }
+}
+
+/* The following symbols used by the cymcuelftool. */
+/* Flash */
+#define __cy_memory_0_start 0x10000000
+#define __cy_memory_0_length  0x00200000
+#define __cy_memory_0_row_size 0x200
+
+/* Emulated EEPROM Flash area */
+#define __cy_memory_1_start    0x14000000
+#define __cy_memory_1_length   0x8000
+#define __cy_memory_1_row_size 0x200
+
+/* Supervisory Flash */
+#define __cy_memory_2_start    0x16000000
+#define __cy_memory_2_length   0x8000
+#define __cy_memory_2_row_size 0x200
+
+/* XIP */
+#define __cy_memory_3_start    0x18000000
+#define __cy_memory_3_length   0x08000000
+#define __cy_memory_3_row_size 0x200
+
+/* eFuse */
+#define __cy_memory_4_start    0x90700000
+#define __cy_memory_4_length   0x100000
+#define __cy_memory_4_row_size 1
+
+
+/* [] END OF FILE */

+ 67 - 0
project_0/board/ports/drv_rw007.c

@@ -0,0 +1,67 @@
+#include <rtthread.h>
+#include <rtdbg.h>
+#ifdef BSP_USING_RW007
+#include <rtdevice.h>
+#include <drv_spi.h>
+#include <board.h>
+#include <spi_wifi_rw007.h>
+
+extern void spi_wifi_isr(int vector);
+
+static void rw007_gpio_init(void)
+{
+    /* Configure IO */
+    rt_pin_mode(IFX_RW007_RST_PIN, PIN_MODE_OUTPUT);
+    rt_pin_mode(IFX_RW007_INT_BUSY_PIN, PIN_MODE_INPUT_PULLDOWN);
+
+    /* Reset rw007 and config mode */
+    rt_pin_write(IFX_RW007_RST_PIN, PIN_LOW);
+    rt_thread_delay(rt_tick_from_millisecond(100));
+    rt_pin_write(IFX_RW007_RST_PIN, PIN_HIGH);
+
+    /* Wait rw007 ready(exit busy stat) */
+    while (!rt_pin_read(IFX_RW007_INT_BUSY_PIN))
+    {
+        rt_thread_delay(5);
+    }
+
+    rt_thread_delay(rt_tick_from_millisecond(200));
+    rt_pin_mode(IFX_RW007_INT_BUSY_PIN, PIN_MODE_INPUT_PULLUP);
+}
+
+static struct rt_spi_device rw007_dev;
+
+int wifi_spi_device_init(void)
+{
+    char sn_version[32];
+    uint32_t cs_pin = IFX_RW007_CS_PIN;
+
+    rw007_gpio_init();
+    rt_hw_spi_device_attach(IFX_RW007_SPI_BUS_NAME, "wspi", cs_pin);
+    rt_hw_wifi_init("wspi");
+
+    rt_wlan_set_mode(RT_WLAN_DEVICE_STA_NAME, RT_WLAN_STATION);
+    rt_wlan_set_mode(RT_WLAN_DEVICE_AP_NAME, RT_WLAN_AP);
+
+    rw007_sn_get(sn_version);
+    rt_kprintf("\nrw007  sn: [%s]\n", sn_version);
+    rw007_version_get(sn_version);
+    rt_kprintf("rw007 ver: [%s]\n\n", sn_version);
+
+    return 0;
+}
+INIT_APP_EXPORT(wifi_spi_device_init);
+
+static void int_wifi_irq(void *p)
+{
+    ((void)p);
+    spi_wifi_isr(0);
+}
+
+void spi_wifi_hw_init(void)
+{
+    rt_pin_attach_irq(IFX_RW007_INT_BUSY_PIN, PIN_IRQ_MODE_FALLING, int_wifi_irq, 0);
+    rt_pin_irq_enable(IFX_RW007_INT_BUSY_PIN, RT_TRUE);
+}
+
+#endif /* BSP_USING_RW007 */

+ 37 - 0
project_0/board/ports/fal_cfg.h

@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-27     Rbb666       first version
+ */
+
+#ifndef _FAL_CFG_H_
+#define _FAL_CFG_H_
+
+#include <rtthread.h>
+#include <board.h>
+
+extern const struct fal_flash_dev ifx_onchip_flash_32k;
+extern const struct fal_flash_dev ifx_onchip_flash_256k;
+
+/* flash device table */
+#define FAL_FLASH_DEV_TABLE         \
+    {                               \
+        &ifx_onchip_flash_32k,      \
+        &ifx_onchip_flash_256k,     \
+    }
+/* ====================== Partition Configuration ========================== */
+#ifdef FAL_PART_HAS_TABLE_CFG
+
+/* partition table */
+#define FAL_PART_TABLE                                                                  \
+    {                                                                                   \
+        {FAL_PART_MAGIC_WROD, "param", "onchip_flash_32k", 0, IFX_EFLASH_SIZE, 0},      \
+        {FAL_PART_MAGIC_WROD, "app", "onchip_flash_256k", 0, IFX_FLASH_SIZE, 0},        \
+    }
+
+#endif /* FAL_PART_HAS_TABLE_CFG */
+#endif /* _FAL_CFG_H_ */

+ 244 - 0
project_0/board/ports/slider_sample.c

@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-28     Rbb666       first version
+ */
+
+#include <rtthread.h>
+#include "drv_common.h"
+
+#ifdef BSP_USING_SLIDER
+#include "cycfg_capsense.h"
+
+#define CAPSENSE_INTR_PRIORITY      (7u)
+#define EZI2C_INTR_PRIORITY         (6u)
+
+/* Allowed duty cycle for maximum brightness */
+#define LED_MAX_BRIGHTNESS      (100u)
+
+/* Allowed duty cycle for minimum brightness*/
+#define LED_MIN_BRIGHTNESS      (0u)
+
+#define GET_DUTY_CYCLE(x)       (1 * 1000 * 1000 - x * 10 * 1000)
+
+typedef enum
+{
+    LED_OFF,
+    LED_ON
+} led_state_t;
+
+typedef struct
+{
+    led_state_t state;
+    uint32_t brightness;
+} led_data_t;
+
+static rt_sem_t trans_done_semphr = RT_NULL;
+static rt_thread_t sld_thread = RT_NULL;
+
+#ifndef RT_USING_PWM
+    #error You need enable PWM to use this sample
+#else
+    #define PWM_DEV_NAME "pwm0"
+    #define PWM_DEV_CHANNEL 3
+    static struct rt_device_pwm *pwm_dev;
+#endif
+
+static void capsense_isr(void)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    Cy_CapSense_InterruptHandler(CYBSP_CSD_HW, &cy_capsense_context);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+
+void capsense_callback(cy_stc_active_scan_sns_t *ptrActiveScan)
+{
+    rt_sem_release(trans_done_semphr);
+}
+
+static uint32_t initialize_capsense(void)
+{
+    uint32_t status = CYRET_SUCCESS;
+
+    /* CapSense interrupt configuration parameters */
+    static const cy_stc_sysint_t capSense_intr_config =
+    {
+        .intrSrc = csd_interrupt_IRQn,
+        .intrPriority = CAPSENSE_INTR_PRIORITY,
+    };
+
+    /* Capture the CSD HW block and initialize it to the default state. */
+    status = Cy_CapSense_Init(&cy_capsense_context);
+    if (CYRET_SUCCESS != status)
+    {
+        return status;
+    }
+
+    /* Initialize CapSense interrupt */
+    cyhal_system_set_isr(csd_interrupt_IRQn, csd_interrupt_IRQn, CAPSENSE_INTR_PRIORITY, &capsense_isr);
+    NVIC_ClearPendingIRQ(capSense_intr_config.intrSrc);
+    NVIC_EnableIRQ(capSense_intr_config.intrSrc);
+
+    /* Initialize the CapSense firmware modules. */
+    status = Cy_CapSense_Enable(&cy_capsense_context);
+    if (CYRET_SUCCESS != status)
+    {
+        return status;
+    }
+
+    /* Assign a callback function to indicate end of CapSense scan. */
+    status = Cy_CapSense_RegisterCallback(CY_CAPSENSE_END_OF_SCAN_E,
+                                          capsense_callback, &cy_capsense_context);
+    if (CYRET_SUCCESS != status)
+    {
+        return status;
+    }
+
+    return status;
+}
+
+void Slider_Init(void)
+{
+    cy_rslt_t result;
+
+    result = initialize_capsense();
+
+    if (CYRET_SUCCESS != result)
+    {
+        /* Halt the CPU if CapSense initialization failed */
+        RT_ASSERT(0);
+    }
+
+    /* Initiate first scan */
+    Cy_CapSense_ScanAllWidgets(&cy_capsense_context);
+
+    trans_done_semphr = rt_sem_create("slider_sem", 1, RT_IPC_FLAG_PRIO);
+    if (trans_done_semphr == RT_NULL)
+    {
+        rt_kprintf("create transform done semphr failed.\n");
+        RT_ASSERT(0);
+        return;
+    }
+
+#ifdef BSP_USING_PWM0_PORT13
+    /* Initiate PWM*/
+    pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);
+
+    if (pwm_dev == RT_NULL)
+    {
+        rt_kprintf("PWM init failed! can't find %s device!\n", PWM_DEV_NAME);
+        RT_ASSERT(0);
+    }
+
+    /*default   period:1ms    pulse:0*/
+    rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, 1 * 1000 * 1000, 1 * 1000 * 1000);
+    rt_pwm_enable(pwm_dev, PWM_DEV_CHANNEL);
+#endif
+}
+
+void update_led_state(led_data_t *ledData)
+{
+    if (ledData->brightness >= 0)
+    {
+        uint32_t brightness = (ledData->brightness < LED_MIN_BRIGHTNESS) ? LED_MIN_BRIGHTNESS : ledData->brightness;
+
+        /* Drive the LED with brightness */
+        rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, 1 * 1000 * 1000, GET_DUTY_CYCLE(brightness));
+    }
+}
+
+static void process_touch(void)
+{
+    cy_stc_capsense_touch_t *slider_touch_info;
+    uint16_t slider_pos;
+    uint8_t slider_touch_status;
+    bool led_update_req = false;
+
+    static uint16_t slider_pos_prev;
+    static led_data_t led_data = {LED_ON, LED_MAX_BRIGHTNESS};
+
+    /* Get slider status */
+    slider_touch_info = Cy_CapSense_GetTouchInfo(
+                            CY_CAPSENSE_LINEARSLIDER0_WDGT_ID, &cy_capsense_context);
+    slider_touch_status = slider_touch_info->numPosition;
+    slider_pos = slider_touch_info->ptrPosition->x;
+
+    /* Detect the new touch on slider */
+    if ((RT_NULL != slider_touch_status) &&
+            (slider_pos != slider_pos_prev))
+    {
+        led_data.brightness = (slider_pos * 100)
+                              / cy_capsense_context.ptrWdConfig[CY_CAPSENSE_LINEARSLIDER0_WDGT_ID].xResolution;
+
+        led_update_req = true;
+    }
+
+#ifndef RT_USING_PWM
+#error You need enable PWM to use this sample
+#else
+    /* Update the LED state if requested */
+    if (led_update_req)
+    {
+        update_led_state(&led_data);
+    }
+#endif
+    slider_pos_prev = slider_pos;
+}
+
+static void Slider_thread_entry(void *parameter)
+{
+    Slider_Init();
+
+    for (;;)
+    {
+        rt_sem_take(trans_done_semphr, RT_WAITING_FOREVER);
+
+        /* Process all widgets */
+        Cy_CapSense_ProcessAllWidgets(&cy_capsense_context);
+
+        /* Process touch input */
+        process_touch();
+
+        /* Establishes synchronized operation between the CapSense
+         * middleware and the CapSense Tuner tool.
+         */
+        Cy_CapSense_RunTuner(&cy_capsense_context);
+
+        /* Initiate next scan */
+        Cy_CapSense_ScanAllWidgets(&cy_capsense_context);
+
+        rt_thread_mdelay(50);
+    }
+}
+
+int Slider_ctrl_sample(void)
+{
+    rt_err_t ret = RT_EOK;
+
+    sld_thread = rt_thread_create("slider_th",
+                                  Slider_thread_entry,
+                                  RT_NULL,
+                                  1024,
+                                  25,
+                                  10);
+    if (sld_thread != RT_NULL)
+    {
+        rt_thread_startup(sld_thread);
+    }
+    else
+    {
+        ret = -RT_ERROR;
+    }
+
+    return ret;
+}
+MSH_CMD_EXPORT(Slider_ctrl_sample, Slider sample to ctrl led);
+#endif

+ 84 - 0
project_0/board/ports/spi_sample.c

@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-19     Rbbb666      first version
+ */
+
+#include "board.h"
+
+#if defined(BSP_USING_SPI3_SAMPLE)
+#include <drv_spi.h>
+
+#define SPI_NAME     "spi30"
+static struct rt_spi_device *spi_dev = RT_NULL;
+
+/* attach spi5 device */
+static int rt_spi_device_init(void)
+{
+    struct rt_spi_configuration cfg;
+
+    rt_hw_spi_device_attach("spi3", "spi30", NULL);
+
+    cfg.data_width = 8;
+    cfg.mode   = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB | RT_SPI_NO_CS;
+    cfg.max_hz = 1 *1000 *1000;
+
+    spi_dev = (struct rt_spi_device *)rt_device_find(SPI_NAME);
+
+    if (RT_NULL == spi_dev)
+    {
+        rt_kprintf("spi sample run failed! can't find %s device!\n", SPI_NAME);
+        return -RT_ERROR;
+    }
+
+    rt_spi_configure(spi_dev, &cfg);
+
+    return RT_EOK;
+}
+INIT_APP_EXPORT(rt_spi_device_init);
+
+/* spi5 loopback mode test case */
+static int spi_sample(int argc, char **argv)
+{
+    rt_uint8_t t_buf[8], r_buf[8];
+    int i = 0;
+    static struct rt_spi_message msg1;
+
+    if (argc != 9)
+    {
+        rt_kprintf("Please Usage:\n");
+        rt_kprintf("spi_sample 1 2 3 4 5 6 7 8\n");
+        return -RT_ERROR;
+    }
+
+    for (i = 0; i < 8; i++)
+    {
+        t_buf[i] = atoi(argv[i+1]);
+    }
+
+    msg1.send_buf   = &t_buf;
+    msg1.recv_buf   = &r_buf;
+    msg1.length     = sizeof(t_buf);
+    msg1.cs_take    = 1;
+    msg1.cs_release = 0;
+    msg1.next       = RT_NULL;
+
+    rt_spi_transfer_message(spi_dev, &msg1);
+
+    rt_kprintf("spi rbuf : ");
+    for (i = 0; i < sizeof(t_buf); i++)
+    {
+        rt_kprintf("%x ", r_buf[i]);
+    }
+
+    rt_kprintf("\nspi loopback mode test over!\n");
+
+    return RT_EOK;
+}
+MSH_CMD_EXPORT(spi_sample, spi loopback test);
+
+#endif /* BSP_USING_SPI3 */

BIN
project_0/figures/board.png


BIN
project_0/figures/mdk_package.png


BIN
project_0/figures/studio1.png


BIN
project_0/figures/studio2.png


BIN
project_0/figures/studio3-build.png


BIN
project_0/figures/studio4-download.png


+ 64 - 0
project_0/libraries/HAL_Drivers/SConscript

@@ -0,0 +1,64 @@
+Import('RTT_ROOT')
+Import('rtconfig')
+from building import *
+
+cwd = GetCurrentDir()
+
+# add the general drivers.
+src = Split("""
+drv_common.c
+""")
+
+if GetDepend(['RT_USING_PIN']):
+    src += ['drv_gpio.c']
+
+if GetDepend(['RT_USING_SERIAL']):
+    if GetDepend(['RT_USING_SERIAL_V2']):
+        src += ['drv_usart_v2.c']
+    else:
+        src += ['drv_uart.c']
+
+if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']):
+    if GetDepend('BSP_USING_I2C1'):
+        src += ['drv_soft_i2c.c']
+
+if GetDepend(['RT_USING_I2C']):
+    if GetDepend('BSP_USING_HW_I2C3') or GetDepend('BSP_USING_HW_I2C6'):
+        src += ['drv_i2c.c']
+
+if GetDepend(['BSP_USING_SDIO1']):
+    src += Glob('drv_sdio.c')
+
+if GetDepend(['BSP_USING_PWM']):
+    src += ['drv_pwm.c']
+
+if GetDepend(['BSP_USING_SPI']):
+    src += ['drv_spi.c']
+
+if GetDepend(['BSP_USING_ADC']):
+    src += ['drv_adc.c']
+
+if GetDepend(['BSP_USING_USBD']):
+    src += ['drv_usbd.c']
+
+if GetDepend('BSP_USING_RTC'):
+    src += ['drv_rtc.c']
+
+if GetDepend('BSP_USING_ON_CHIP_FLASH'):
+    src += ['drv_flash.c']
+
+if GetDepend(['RT_USING_WDT']):
+    src += ['drv_wdt.c']
+
+if GetDepend(['RT_USING_DAC']):
+    src += ['drv_dac.c']
+
+if GetDepend(['BSP_USING_TIM']):
+    src += ['drv_hwtimer.c']
+
+path =  [cwd]
+path += [cwd + '/config']
+
+group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path)
+
+Return('group')

+ 135 - 0
project_0/libraries/HAL_Drivers/drv_adc.c

@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-04     Rbb666       first version
+ */
+#include "drv_common.h"
+#include "drv_adc.h"
+
+#include "cyhal.h"
+#include "cybsp.h"
+
+#if defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2)
+
+//#define DRV_DEBUG
+#define LOG_TAG             "drv.adc"
+#include <drv_log.h>
+
+#define VPLUS_CHANNEL_0     (P10_0)
+
+struct ifx_adc
+{
+    struct rt_adc_device ifx_adc_device;
+    cyhal_adc_channel_t *adc_ch;
+    char *name;
+};
+
+static struct ifx_adc ifx_adc_obj[] =
+{
+    #ifdef BSP_USING_ADC1
+    ADC1_CONFIG,
+    #endif
+};
+
+static rt_err_t ifx_adc_enabled(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled)
+{
+    cyhal_adc_channel_t *adc_ch;
+    cy_rslt_t result;
+
+    RT_ASSERT(device != RT_NULL);
+    adc_ch = device->parent.user_data;
+
+    const cyhal_adc_channel_config_t channel_config =
+    {
+        .enable_averaging = false,      // Disable averaging for channel
+        .min_acquisition_ns = 1000,     // Minimum acquisition time set to 1us
+        .enabled = enabled              // Sample this channel when ADC performs a scan
+    };
+
+    if (enabled)
+    {
+        /* Initialize ADC. The ADC block which can connect to pin 10[0] is selected */
+        result = cyhal_adc_init(&adc_obj, VPLUS_CHANNEL_0, NULL);
+
+        if (result != RT_EOK)
+        {
+            LOG_E("ADC initialization failed. Error: %ld\n", (long unsigned int)result);
+            return -RT_ENOSYS;
+        }
+
+        /* Initialize a channel 0 and configure it to scan P10_0 in single ended mode. */
+        result  = cyhal_adc_channel_init_diff(adc_ch, &adc_obj, VPLUS_CHANNEL_0,
+                                              CYHAL_ADC_VNEG, &channel_config);
+
+        if (result != RT_EOK)
+        {
+            LOG_E("ADC single ended channel initialization failed. Error: %ld\n", (long unsigned int)result);
+            return -RT_ENOSYS;
+        }
+
+        /* Update ADC configuration */
+        result = cyhal_adc_configure(&adc_obj, &adc_config);
+
+        if (result != RT_EOK)
+        {
+            printf("ADC configuration update failed. Error: %ld\n", (long unsigned int)result);
+            return -RT_ENOSYS;
+        }
+    }
+    else
+    {
+        cyhal_adc_free(&adc_obj);
+        cyhal_adc_channel_free(adc_ch);
+    }
+
+    return RT_EOK;
+}
+
+static rt_err_t ifx_get_adc_value(struct rt_adc_device *device, rt_uint32_t channel, rt_uint32_t *value)
+{
+    cyhal_adc_channel_t *adc_ch;
+
+    RT_ASSERT(device != RT_NULL);
+    adc_ch = device->parent.user_data;
+
+    channel = adc_ch->channel_idx;
+
+    *value = cyhal_adc_read(adc_ch);
+
+    return RT_EOK;
+}
+
+static const struct rt_adc_ops at_adc_ops =
+{
+    .enabled = ifx_adc_enabled,
+    .convert = ifx_get_adc_value,
+};
+
+static int rt_hw_adc_init(void)
+{
+    int result = RT_EOK;
+    int i = 0;
+
+    for (i = 0; i < sizeof(ifx_adc_obj) / sizeof(ifx_adc_obj[0]); i++)
+    {
+        /* register ADC device */
+        if (rt_hw_adc_register(&ifx_adc_obj[i].ifx_adc_device, ifx_adc_obj[i].name, &at_adc_ops, ifx_adc_obj[i].adc_ch) == RT_EOK)
+        {
+            LOG_D("%s register success", at32_adc_obj[i].name);
+        }
+        else
+        {
+            LOG_E("%s register failed", ifx_adc_obj[i].name);
+            result = -RT_ERROR;
+        }
+    }
+
+    return result;
+}
+INIT_BOARD_EXPORT(rt_hw_adc_init);
+
+#endif /* BSP_USING_ADC */

+ 54 - 0
project_0/libraries/HAL_Drivers/drv_adc.h

@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-03-28     shelton      first version
+ */
+
+#ifndef __ADC_CONFIG_H__
+#define __ADC_CONFIG_H__
+
+#include <rtthread.h>
+
+#include "cyhal.h"
+#include "cybsp.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#if defined(BSP_USING_ADC1) || defined(BSP_USING_ADC2)
+
+cyhal_adc_t adc_obj;
+cyhal_adc_channel_t adc_chan_obj;
+
+const cyhal_adc_config_t adc_config =
+{
+    .continuous_scanning = false,   // Continuous Scanning is disabled
+    .average_count = 1,             // Average count disabled
+    .vref = CYHAL_ADC_REF_VDDA,     // VREF for Single ended channel set to VDDA
+    .vneg = CYHAL_ADC_VNEG_VSSA,    // VNEG for Single ended channel set to VSSA
+    .resolution = 12u,              // 12-bit resolution
+    .ext_vref = NC,                 // No connection
+    .bypass_pin = NC                // No connection
+};
+
+#ifndef ADC1_CONFIG
+#define ADC1_CONFIG                 \
+    {                               \
+        .adc_ch = &adc_chan_obj,    \
+        .name = "adc1",             \
+    }
+#endif /* ADC1_CONFIG */
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __ADC_CONFIG_H__ */

+ 121 - 0
project_0/libraries/HAL_Drivers/drv_common.c

@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-1      Rbb666       first version
+ */
+
+#include "drv_common.h"
+
+#ifdef RT_USING_SERIAL
+    #include "drv_uart.h"
+#endif
+
+#define DBG_TAG "drv_common"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+static void reboot(uint8_t argc, char **argv)
+{
+    rt_hw_cpu_reset();
+}
+MSH_CMD_EXPORT(reboot, Reboot System);
+#endif /* RT_USING_FINSH */
+
+/**
+ * this is the timer interrupt service routine.
+ */
+void SysTick_Handler_CB(void)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    rt_tick_increase();
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+
+/* systick configuration */
+void rt_hw_systick_init(void)
+{
+    Cy_SysTick_Init(CY_SYSTICK_CLOCK_SOURCE_CLK_CPU, SystemCoreClock / RT_TICK_PER_SECOND);
+    Cy_SysTick_SetCallback(0, SysTick_Handler_CB);
+    Cy_SysTick_EnableInterrupt();
+}
+
+/**
+ * @brief  this function is executed in case of error occurrence.
+ * @param  none
+ * @retval none
+ */
+void _Error_Handler(char *s, int num)
+{
+    /* User can add his own implementation to report the HAL error return state */
+    LOG_E("Error_Handler at file:%s num:%d", s, num);
+
+    while (1)
+    {
+    }
+}
+
+/**
+ * this function will delay for some us.
+ *
+ * @param us the delay time of us
+ */
+void rt_hw_us_delay(rt_uint32_t us)
+{
+    rt_uint32_t start, now, delta, reload, us_tick;
+    start = SysTick->VAL;
+    reload = SysTick->LOAD;
+    us_tick = SystemCoreClock / 1000000UL;
+
+    do
+    {
+        now = SysTick->VAL;
+        delta = start > now ? start - now : reload + start - now;
+    }
+    while(delta < us_tick * us);
+}
+
+/**
+ * this function will initial ifx board.
+ */
+RT_WEAK void rt_hw_board_init()
+{
+    cy_bsp_all_init();
+
+    /* systick init */
+    rt_hw_systick_init();
+
+    /* heap initialization */
+    #if defined(RT_USING_HEAP)
+    rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
+    #endif
+
+    /* pin driver initialization is open by default */
+    #ifdef RT_USING_PIN
+    rt_hw_pin_init();
+    #endif
+
+    /* usart driver initialization is open by default */
+    #ifdef RT_USING_SERIAL
+    rt_hw_uart_init();
+    #endif
+
+    /* set the shell console output device */
+    #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
+    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
+    #endif
+
+    /* board underlying hardware initialization */
+    #ifdef RT_USING_COMPONENTS_INIT
+    rt_components_board_init();
+    #endif
+}

+ 35 - 0
project_0/libraries/HAL_Drivers/drv_common.h

@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-1      Rbb666       first version
+ */
+
+#ifndef __DRV_COMMON_H__
+#define __DRV_COMMON_H__
+
+#include <rtthread.h>
+#include <rthw.h>
+#ifdef RT_USING_DEVICE
+    #include <rtdevice.h>
+#endif
+#include "board.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void _Error_Handler(char *s, int num);
+
+#ifndef Error_Handler
+#define Error_Handler() _Error_Handler(__FILE__, __LINE__)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 181 - 0
project_0/libraries/HAL_Drivers/drv_dac.c

@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author                 Notes
+ * 2022-07-28     rtthread qiu       first version
+ */
+#include "drv_dac.h"
+#include "drv_common.h"
+#include <rtthread.h>
+
+#if defined(BSP_USING_DAC1) || defined(BSP_USING_DAC2)
+
+#define LOG_TAG "drv.dac"
+#include <drv_log.h>
+
+struct cyp_dac
+{
+    cy_stc_csdidac_config_t cyhal_dac_device;
+    struct rt_dac_device cyp_dac_device;
+    char *name;
+};
+
+static struct cyp_dac dac_config[] =
+    {
+#ifdef BSP_USING_DAC1
+        DAC1_CONFIG,
+#endif
+#ifdef BSP_USING_DAC2
+        DAC2_CONFIG,
+#endif
+
+};
+
+/*get dac channel*/
+static rt_uint32_t cyp_dac_get_channel(rt_uint32_t channel)
+{
+    rt_uint32_t cyp_dac_channel = 0;
+
+    switch (channel)
+    {
+    case 1:
+        cyp_dac_channel = CY_CSDIDAC_A;
+        break;
+    case 2:
+        cyp_dac_channel = CY_CSDIDAC_B;
+        break;
+    default:
+        RT_ASSERT(0);
+        break;
+    }
+
+    return cyp_dac_channel;
+}
+
+struct cyp_dac cyp_adc_obj[sizeof(dac_config) / sizeof(dac_config[0])];
+
+cy_stc_csdidac_context_t csdidac_context;
+
+/*dac device enable*/
+static rt_err_t cyp_dac_enabled(struct rt_dac_device *device, rt_uint32_t channel)
+{
+    cy_rslt_t result;
+
+    rt_uint32_t cyp_channel;
+
+    RT_ASSERT(device != RT_NULL);
+
+    cyhal_dac_t *dac_device;
+
+    dac_device = device->parent.user_data;
+
+    /* get current dac channel*/
+    cyp_channel = cyp_dac_get_channel(channel);
+
+    /*DAC device init*/
+    result = Cy_CSDIDAC_Init(&CSDIDAC_csdidac_config, &csdidac_context);
+
+    if (result != RT_EOK)
+    {
+        LOG_E("Cy_CSDIDAC_Init fail = %d\n", result);
+        return -RT_ENOSYS;
+    }
+
+    return RT_EOK;
+}
+
+/*dac device disable*/
+static rt_err_t cyp_dac_disable(struct rt_dac_device *device, rt_uint32_t channel)
+{
+    rt_uint32_t cyp_channel;
+
+    cy_rslt_t result;
+
+    RT_ASSERT(device != RT_NULL);
+
+    cyhal_dac_t *dac_device;
+
+    dac_device = device->parent.user_data;
+
+    cyp_channel = cyp_dac_get_channel(channel);
+
+    /*DAC free device*/
+    result = Cy_CSDIDAC_OutputDisable(cyp_channel, &csdidac_context);
+    if (result != RT_EOK)
+    {
+        LOG_E("DAC Outputdisable failed. Error: %d\n", result);
+        return -RT_ENOSYS;
+    }
+    return RT_EOK;
+}
+
+/*set dac output value*/
+static rt_err_t cyp_adc_convert(struct rt_dac_device *device, rt_uint32_t channel, rt_uint32_t *value)
+{
+    RT_ASSERT(device != RT_NULL);
+
+    cy_rslt_t result;
+
+    rt_uint32_t cyp_channel;
+
+    cyp_channel = cyp_dac_get_channel(channel);
+
+    result = Cy_CSDIDAC_OutputEnable(cyp_channel, *value, &csdidac_context);
+    if (result != RT_EOK)
+    {
+        LOG_E("DAC  channel initialization failed. Error: %d\n", result);
+        return -RT_ENOSYS;
+    }
+
+    return RT_EOK;
+}
+
+static const struct rt_dac_ops cyp_dac_ops =
+{
+    .disabled = cyp_dac_disable,
+    .enabled = cyp_dac_enabled,
+    .convert = cyp_adc_convert,
+};
+
+/*dac device init*/
+static int rt_hw_dac_init(void)
+{
+    int result = RT_EOK;
+
+    /* save dac name */
+    char name_buf[5] = {'d', 'a', 'c', '0', 0};
+
+    int i = 0;
+
+    i = sizeof(dac_config) / sizeof(dac_config[0]);
+
+    for (i = 0; i < sizeof(dac_config) / sizeof(dac_config[0]); i++)
+    {
+
+#ifdef BSP_USING_DAC1
+        name_buf[3] = '1';
+#endif
+
+#ifdef BSP_USING_DAC2
+        name_buf[3] = '2';
+#endif
+        /* register DAC device */
+        if (rt_hw_dac_register(&cyp_adc_obj[i].cyp_dac_device, name_buf, &cyp_dac_ops, RT_NULL) == RT_EOK)
+        {
+            LOG_E("dac device register success\n");
+        }
+        else
+        {
+            LOG_E("dac device register fail\n");
+            result = -RT_ERROR;
+        }
+    }
+    return result;
+}
+
+INIT_BOARD_EXPORT(rt_hw_dac_init);
+
+#endif /* BSP_USING_DAC1 /BSP_USING_DAC2 */

+ 59 - 0
project_0/libraries/HAL_Drivers/drv_dac.h

@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author                 Notes
+ * 2022-07-28     rtthread qiu       first version
+ */
+#ifndef __DRV__DAC_H__
+#define __DRV__DAC_H__
+#include "rtconfig.h"
+#include "cycfg.h"
+#include <rtthread.h>
+#include "cy_csdidac.h"
+#include "cycfg_peripherals.h"
+
+static const cy_stc_csdidac_pin_t CSDIDAC_csdidac_a_pin =
+{
+    .ioPcPtr = GPIO_PRT10,
+    .pin = 0u,
+};
+static const cy_stc_csdidac_pin_t CSDIDAC_csdidac_b_pin =
+{
+    .ioPcPtr = GPIO_PRT10,
+    .pin = 0u,
+};
+
+const cy_stc_csdidac_config_t CSDIDAC_csdidac_config =
+{
+    .base = CSD0,
+    .csdCxtPtr = &cy_csd_0_context,
+    .configA = CY_CSDIDAC_GPIO,
+    .configB = CY_CSDIDAC_GPIO,
+    .ptrPinA = (const cy_stc_csdidac_pin_t *)&CSDIDAC_csdidac_a_pin,
+    .ptrPinB = (const cy_stc_csdidac_pin_t *)&CSDIDAC_csdidac_b_pin,
+    .cpuClk = 100000000u,
+    .csdInitTime = 25u,
+};
+
+#ifdef BSP_USING_DAC1
+#ifndef DAC1_CONFIG
+#define DAC1_CONFIG     \
+    {                   \
+        .name = "dac1", \
+    }
+#endif /* DAC1_CONFIG */
+#endif /*BSP_USING_DAC2*/
+
+#ifdef BSP_USING_DAC2
+#ifndef DAC2_CONFIG
+#define DAC2_CONFIG     \
+    {                   \
+        .name = "dac2", \
+    }
+#endif /* DAC2_CONFIG */
+#endif /*BSP_USING_DAC2*/
+
+#endif /*__DRV__DAC_H__*/

+ 427 - 0
project_0/libraries/HAL_Drivers/drv_flash.c

@@ -0,0 +1,427 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-26     Rbb666       first version
+ */
+
+#include <rtthread.h>
+#include "drv_common.h"
+
+#ifdef BSP_USING_ON_CHIP_FLASH
+#include "drv_flash.h"
+
+#if defined(RT_USING_FAL)
+    #include "fal.h"
+#endif
+
+#define DRV_DEBUG
+#define LOG_TAG                "drv.flash"
+#include <drv_log.h>
+
+static cyhal_flash_t flash_obj;
+static cyhal_flash_block_info_t block_info;
+static cyhal_flash_info_t flash_info;
+
+int _flash_init(void)
+{
+    cy_rslt_t err = CY_RSLT_SUCCESS;
+    /* Init Flash */
+    err = cyhal_flash_init(&flash_obj);
+
+    /* Handle Error */
+    if (CY_RSLT_SUCCESS != err)
+    {
+        LOG_E("\r\n Flash Init failed");
+    }
+
+    cyhal_flash_get_info(&flash_obj, &flash_info);
+
+    block_info = flash_info.blocks[flash_info.block_count - 1u];
+
+    return 0;
+}
+
+static rt_uint32_t get_page_32k(uint32_t addr)
+{
+    rt_uint32_t page = 0;
+
+    page = RT_ALIGN_DOWN(addr, IFX_EFLASH_PAGE_SIZE);
+
+    return page;
+}
+
+/**
+  * @brief  gets the page of a given address
+  * @param  addr: address of the flash memory
+  * @retval the page of a given address
+  */
+static rt_uint32_t get_page_256k(uint32_t addr)
+{
+    rt_uint32_t page = 0;
+
+    page = RT_ALIGN_DOWN(addr, IFX_FLASH_PAGE_SIZE);
+
+    return page;
+}
+
+int ifx_flash_read_32k(rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t size)
+{
+    rt_uint32_t i;
+
+    if ((addr + size) > IFX_EFLASH_END_ADDRESS)
+    {
+        LOG_E("read outrange flash size! addr is (0x%p)", (void *)(addr + size));
+        return -RT_EINVAL;
+    }
+
+    for (i = 0; i < size; i++, buf++, addr++)
+    {
+        *buf = *(rt_uint8_t *) addr;
+    }
+
+    return size;
+}
+
+/**
+ * @brief read data from flash.
+ * @note this operation's units is word.
+ *
+ * @param addr flash address
+ * @param buf buffer to store read data
+ * @param size read bytes size
+ *
+ * @return result
+ */
+int ifx_flash_read_256k(rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t size)
+{
+    rt_uint32_t i;
+
+    if ((addr + size) > IFX_FLASH_END_ADDRESS)
+    {
+        LOG_E("read outrange flash size! addr is (0x%p)", (void *)(addr + size));
+        return -RT_EINVAL;
+    }
+
+    for (i = 0; i < size; i++, buf++, addr++)
+    {
+        *buf = *(rt_uint8_t *) addr;
+    }
+
+    return size;
+}
+
+/**
+ * @brief write data to flash.
+ * @note this operation's units is word.
+ * @note this operation must after erase. @see flash_erase.
+ *
+ * @param addr flash address
+ * @param buf the write data buffer
+ * @param size write bytes size
+ *
+ * @return result
+ */
+int ifx_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, rt_uint32_t size)
+{
+    rt_err_t result = RT_EOK;
+    rt_base_t level;
+    cy_rslt_t err = CY_RSLT_SUCCESS;
+    size_t written_size = 0;
+
+#define BSP_FEATURE_FLASH_WRITE_SIZE 512U
+
+    if (size % BSP_FEATURE_FLASH_WRITE_SIZE)
+    {
+        LOG_E("Flash Write size must be an integer multiple of %d", BSP_FEATURE_FLASH_WRITE_SIZE);
+        return -RT_EINVAL;
+    }
+
+    while (written_size < size)
+    {
+        level = rt_hw_interrupt_disable();
+        /* Write code flash data*/
+        err = cyhal_flash_write(&flash_obj, addr + written_size, (rt_uint32_t *)(buf + written_size));
+        rt_hw_interrupt_enable(level);
+
+        /* Error Handle */
+        if (CY_RSLT_SUCCESS != err)
+        {
+            LOG_E("Write API failed");
+            return -RT_EIO;
+        }
+
+        written_size += BSP_FEATURE_FLASH_WRITE_SIZE;
+    }
+
+    if (result != RT_EOK)
+    {
+        return result;
+    }
+
+    return size;
+}
+
+int ifx_flash_erase_32k(rt_uint32_t addr, rt_uint32_t size)
+{
+    rt_err_t result = RT_EOK;
+    rt_uint32_t end_addr = addr + size;
+    rt_uint32_t page_addr = 0;
+    rt_base_t level;
+
+    level = rt_hw_interrupt_disable();
+
+    if ((end_addr) > IFX_EFLASH_END_ADDRESS)
+    {
+        LOG_E("erase outrange flash size! addr is (0x%p)", (void *)(addr + size));
+        return -RT_EINVAL;
+    }
+
+    while (addr < end_addr)
+    {
+        page_addr = get_page_32k(addr);
+
+        if (cyhal_flash_erase(&flash_obj, page_addr) != CY_RSLT_SUCCESS)
+        {
+            result = -RT_ERROR;
+            goto __exit;
+        }
+
+        addr += IFX_FLASH_PAGE_SIZE;
+    }
+
+    rt_hw_interrupt_enable(level);
+
+__exit:
+
+    if (result != RT_EOK)
+    {
+        return result;
+    }
+
+    return size;
+}
+
+/**
+ * @brief erase data on flash .
+ * @note this operation is irreversible.
+ * @note this operation's units is different which on many chips.
+ *
+ * @param addr flash address
+ * @param size erase bytes size
+ *
+ * @return result
+ */
+int ifx_flash_erase_256k(rt_uint32_t addr, rt_uint32_t size)
+{
+    rt_err_t result = RT_EOK;
+    rt_uint32_t end_addr = addr + size;
+    rt_uint32_t page_addr = 0;
+    rt_base_t level;
+
+    level = rt_hw_interrupt_disable();
+
+    if ((end_addr) > IFX_FLASH_END_ADDRESS)
+    {
+        LOG_E("erase outrange flash size! addr is (0x%p)", (void *)(addr + size));
+        return -RT_EINVAL;
+    }
+
+    while (addr < end_addr)
+    {
+        page_addr = get_page_256k(addr);
+
+        if (cyhal_flash_erase(&flash_obj, page_addr) != CY_RSLT_SUCCESS)
+        {
+            result = -RT_ERROR;
+            goto __exit;
+        }
+
+        addr += IFX_FLASH_PAGE_SIZE;
+    }
+
+    rt_hw_interrupt_enable(level);
+
+__exit:
+
+    if (result != RT_EOK)
+    {
+        return result;
+    }
+
+    return size;
+}
+
+#if defined(RT_USING_FAL)
+static int fal_flash_read_32k(long offset, rt_uint8_t *buf, size_t size);
+static int fal_flash_read_256k(long offset, rt_uint8_t *buf, size_t size);
+
+static int fal_flash_write_32k(long offset, const rt_uint8_t *buf, size_t size);
+static int fal_flash_write_256k(long offset, const rt_uint8_t *buf, size_t size);
+
+static int fal_flash_erase_32k(long offset, size_t size);
+static int fal_flash_erase_256k(long offset, size_t size);
+
+const struct fal_flash_dev ifx_onchip_flash_32k =
+{
+    "onchip_flash_32k",
+    IFX_EFLASH_START_ADRESS,
+    IFX_EFLASH_SIZE,
+    IFX_EFLASH_PAGE_SIZE,
+    {
+        NULL,
+        fal_flash_read_32k,
+        fal_flash_write_32k,
+        fal_flash_erase_32k
+    }
+};
+
+const struct fal_flash_dev ifx_onchip_flash_256k =
+{
+    "onchip_flash_256k",
+    IFX_FLASH_START_ADRESS,
+    IFX_FLASH_SIZE,
+    IFX_FLASH_PAGE_SIZE,
+    {
+        _flash_init,
+        fal_flash_read_256k,
+        fal_flash_write_256k,
+        fal_flash_erase_256k
+    }
+};
+
+static int fal_flash_read_32k(long offset, rt_uint8_t *buf, size_t size)
+{
+    return ifx_flash_read_32k(ifx_onchip_flash_32k.addr + offset, buf, size);
+}
+
+static int fal_flash_read_256k(long offset, rt_uint8_t *buf, size_t size)
+{
+    return ifx_flash_read_256k(ifx_onchip_flash_256k.addr + offset, buf, size);
+}
+
+static int fal_flash_write_32k(long offset, const rt_uint8_t *buf, size_t size)
+{
+    return ifx_flash_write(ifx_onchip_flash_32k.addr + offset, buf, size);
+}
+
+static int fal_flash_write_256k(long offset, const rt_uint8_t *buf, size_t size)
+{
+    return ifx_flash_write(ifx_onchip_flash_256k.addr + offset, buf, size);
+}
+
+static int fal_flash_erase_32k(long offset, size_t size)
+{
+    return ifx_flash_erase_32k(ifx_onchip_flash_32k.addr + offset, size);
+}
+
+static int fal_flash_erase_256k(long offset, size_t size)
+{
+    return ifx_flash_erase_256k(ifx_onchip_flash_256k.addr + offset, size);
+}
+
+#if defined(BSP_USING_ON_CHIP_FLASH)
+static int rt_hw_on_chip_flash_init(void)
+{
+    fal_init();
+    return RT_EOK;
+}
+INIT_ENV_EXPORT(rt_hw_on_chip_flash_init);
+
+int flash64k_test(void)
+{
+#define TEST_OFF (ifx_onchip_flash_256k.len - 0x40000)
+    const struct fal_partition *param;
+    uint8_t write_buffer[512U] = {0};
+    uint8_t read_buffer[512U] = {0};
+
+    /* Set write buffer, clear read buffer */
+    for (uint16_t index = 0; index < 512U; index++)
+    {
+        write_buffer[index] = index;
+        read_buffer[index] = 0;
+    }
+
+    param = fal_partition_find("app");
+
+    if (param == RT_NULL)
+    {
+        LOG_E("not find partition app!");
+        return -1;
+    }
+
+    LOG_I("Erase Start...");
+    fal_partition_erase(param, TEST_OFF, 0x40000);
+    LOG_I("Erase succeeded!");
+    LOG_I("Write Start...");
+    fal_partition_write(param, TEST_OFF, write_buffer, sizeof(write_buffer));
+    LOG_I("Write succeeded!");
+    LOG_I("Read Start...");
+    fal_partition_read(param, TEST_OFF, read_buffer, 128U);
+    LOG_I("Read succeeded!");
+
+    for (int i = 0; i < 128U; i++)
+    {
+        if (read_buffer[i] != write_buffer[i])
+        {
+            LOG_E("Data verification failed!");
+            return -1;
+        }
+    }
+
+    LOG_I("Data verification succeeded!");
+    return 0;
+}
+MSH_CMD_EXPORT(flash64k_test, "drv flash64k test.");
+
+int flash32k_test(void)
+{
+#define TEST32_OFF (ifx_onchip_flash_32k.len - 0x8000)
+    const struct fal_partition *param;
+    uint8_t write_buffer[512U] = {0};
+    uint8_t read_buffer[512U] = {0};
+
+    /* Set write buffer, clear read buffer */
+    for (uint16_t index = 0; index < 512U; index++)
+    {
+        write_buffer[index] = index;
+        read_buffer[index] = 0;
+    }
+
+    param = fal_partition_find("param");
+
+    if (param == RT_NULL)
+    {
+        LOG_E("not find partition param!");
+        return -1;
+    }
+
+    LOG_I("Erase Start...");
+    fal_partition_erase(param, TEST32_OFF, 0x8000);
+    LOG_I("Erase succeeded!");
+    LOG_I("Write Start...");
+    fal_partition_write(param, TEST32_OFF, write_buffer, sizeof(write_buffer));
+    LOG_I("Write succeeded!");
+    LOG_I("Read Start...");
+    fal_partition_read(param, TEST32_OFF, read_buffer, 128U);
+    LOG_I("Read succeeded!");
+
+    for (int i = 0; i < 128U; i++)
+    {
+        if (read_buffer[i] != write_buffer[i])
+        {
+            LOG_E("Data verification failed!");
+            return -1;
+        }
+    }
+
+    LOG_I("Data verification succeeded!");
+    return 0;
+}
+MSH_CMD_EXPORT(flash32k_test, "drv flash32k test.");
+#endif
+#endif
+#endif /* BSP_USING_ON_CHIP_FLASH */

+ 30 - 0
project_0/libraries/HAL_Drivers/drv_flash.h

@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-26     Rbb666       first version
+ */
+
+#ifndef __DRV_FLASH_H__
+#define __DRV_FLASH_H__
+
+#include <rtthread.h>
+#include "rtdevice.h"
+#include <rthw.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int ifx_flash_read(rt_uint32_t addr, rt_uint8_t *buf, rt_uint32_t size);
+int ifx_flash_write(rt_uint32_t addr, const rt_uint8_t *buf, rt_uint32_t size);
+int ifx_flash_erase(rt_uint32_t addr, rt_uint32_t size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __DRV_FLASH_H__ */

+ 341 - 0
project_0/libraries/HAL_Drivers/drv_gpio.c

@@ -0,0 +1,341 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author            Notes
+ * 2022-07-1      Rbb666            first version
+ */
+
+#include "drv_gpio.h"
+
+#ifdef RT_USING_PIN
+
+#define PIN_GET(pin)        ((uint8_t)(((uint8_t)pin) & 0x07U))
+#define PORT_GET(pin)       ((uint8_t)(((uint8_t)pin) >> 3U))
+
+#define __IFX_PORT_MAX      15u
+
+#define PIN_IFXPORT_MAX     __IFX_PORT_MAX
+
+static const struct pin_irq_map pin_irq_map[] =
+{
+    {CYHAL_PORT_0,  ioss_interrupts_gpio_0_IRQn},
+#if !defined(SOC_CY8C6245LQI_S3D72) && !defined(SOC_CY8C6244LQI_S4D92)
+    {CYHAL_PORT_1,  ioss_interrupts_gpio_1_IRQn},
+#endif
+    {CYHAL_PORT_2,  ioss_interrupts_gpio_2_IRQn},
+    {CYHAL_PORT_3,  ioss_interrupts_gpio_3_IRQn},
+#if !defined(SOC_CY8C6245LQI_S3D72) && !defined(SOC_CY8C6244LQI_S4D92)
+    {CYHAL_PORT_4,  ioss_interrupts_gpio_4_IRQn},
+#endif
+    {CYHAL_PORT_5,  ioss_interrupts_gpio_5_IRQn},
+    {CYHAL_PORT_6,  ioss_interrupts_gpio_6_IRQn},
+    {CYHAL_PORT_7,  ioss_interrupts_gpio_7_IRQn},
+    {CYHAL_PORT_8,  ioss_interrupts_gpio_8_IRQn},
+    {CYHAL_PORT_9,  ioss_interrupts_gpio_9_IRQn},
+    {CYHAL_PORT_10,  ioss_interrupts_gpio_10_IRQn},
+    {CYHAL_PORT_11,  ioss_interrupts_gpio_11_IRQn},
+    {CYHAL_PORT_12,  ioss_interrupts_gpio_12_IRQn},
+#if !defined(SOC_CY8C6245LQI_S3D72) && !defined(SOC_CY8C6244LQI_S4D92)
+    {CYHAL_PORT_13,  ioss_interrupts_gpio_13_IRQn},
+#endif
+    {CYHAL_PORT_14,  ioss_interrupts_gpio_14_IRQn},
+};
+
+static struct rt_pin_irq_hdr pin_irq_handler_tab[] =
+{
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+    {-1, 0, RT_NULL, RT_NULL},
+};
+
+rt_inline void pin_irq_handler(int irqno)
+{
+    if (pin_irq_handler_tab[irqno].hdr)
+    {
+        pin_irq_handler_tab[irqno].hdr(pin_irq_handler_tab[irqno].args);
+    }
+}
+
+void gpio_exint_handler(uint16_t GPIO_Port)
+{
+    pin_irq_handler(GPIO_Port);
+}
+
+/* interrupt callback definition*/
+static void irq_callback(void *callback_arg, cyhal_gpio_event_t event)
+{
+    /* To avoid compiler warnings */
+    (void) callback_arg;
+    (void) event;
+
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    gpio_exint_handler(*(rt_uint16_t *)callback_arg);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+
+cyhal_gpio_callback_data_t irq_cb_data;
+
+static void ifx_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
+{
+    rt_uint16_t gpio_pin;
+
+    if (PORT_GET(pin) < PIN_IFXPORT_MAX)
+    {
+        gpio_pin = pin;
+    }
+    else
+    {
+        return;
+    }
+
+    switch (mode)
+    {
+    case PIN_MODE_OUTPUT:
+        cyhal_gpio_init(gpio_pin, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, true);
+        break;
+
+    case PIN_MODE_INPUT:
+        cyhal_gpio_init(gpio_pin, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_NONE, false);
+        break;
+
+    case PIN_MODE_INPUT_PULLUP:
+        cyhal_gpio_init(gpio_pin, CYHAL_GPIO_DIR_BIDIRECTIONAL, CYHAL_GPIO_DRIVE_PULLUP, true);
+        break;
+
+    case PIN_MODE_INPUT_PULLDOWN:
+        cyhal_gpio_init(gpio_pin, CYHAL_GPIO_DIR_BIDIRECTIONAL, CYHAL_GPIO_DRIVE_PULLDOWN, false);
+        break;
+
+    case PIN_MODE_OUTPUT_OD:
+        cyhal_gpio_init(gpio_pin, CYHAL_GPIO_DIR_BIDIRECTIONAL, CYHAL_GPIO_DRIVE_PULLUP, true);
+        break;
+    }
+}
+
+static void ifx_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value)
+{
+    rt_uint16_t gpio_pin;
+
+    if (PORT_GET(pin) < PIN_IFXPORT_MAX)
+    {
+        gpio_pin = pin;
+    }
+    else
+    {
+        return;
+    }
+
+    cyhal_gpio_write(gpio_pin, value);
+}
+
+static int ifx_pin_read(rt_device_t dev, rt_base_t pin)
+{
+    rt_uint16_t gpio_pin;
+
+    if (PORT_GET(pin) < PIN_IFXPORT_MAX)
+    {
+        gpio_pin = pin;
+    }
+    else
+    {
+        return -RT_ERROR;
+    }
+
+    return cyhal_gpio_read(gpio_pin);
+}
+
+static rt_err_t ifx_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
+                                   rt_uint32_t mode, void (*hdr)(void *args), void *args)
+{
+    rt_uint16_t gpio_port;
+    rt_uint16_t gpio_pin;
+    rt_base_t level;
+
+    if (PORT_GET(pin) < PIN_IFXPORT_MAX)
+    {
+        gpio_port = PORT_GET(pin);
+        gpio_pin = pin;
+    }
+    else
+    {
+        return -RT_ERROR;
+    }
+
+    level = rt_hw_interrupt_disable();
+
+    if (pin_irq_handler_tab[gpio_port].pin == pin &&
+            pin_irq_handler_tab[gpio_port].hdr == hdr &&
+            pin_irq_handler_tab[gpio_port].mode == mode &&
+            pin_irq_handler_tab[gpio_port].args == args)
+    {
+        rt_hw_interrupt_enable(level);
+        return RT_EOK;
+    }
+
+    if (pin_irq_handler_tab[gpio_port].pin != -1)
+    {
+        rt_hw_interrupt_enable(level);
+        return -RT_EBUSY;
+    }
+
+    pin_irq_handler_tab[gpio_port].pin = pin;
+    pin_irq_handler_tab[gpio_port].hdr = hdr;
+    pin_irq_handler_tab[gpio_port].mode = mode;
+    pin_irq_handler_tab[gpio_port].args = args;
+    rt_hw_interrupt_enable(level);
+
+    return RT_EOK;
+}
+
+static rt_err_t ifx_pin_dettach_irq(struct rt_device *device, rt_int32_t pin)
+{
+    rt_uint16_t gpio_port;
+    rt_uint16_t gpio_pin;
+    rt_base_t level;
+
+    if (PORT_GET(pin) < PIN_IFXPORT_MAX)
+    {
+        gpio_port = PORT_GET(pin);
+        gpio_pin = pin;
+    }
+    else
+    {
+        return -RT_ERROR;
+    }
+
+    level = rt_hw_interrupt_disable();
+
+    if (pin_irq_handler_tab[gpio_port].pin == -1)
+    {
+        rt_hw_interrupt_enable(level);
+        return RT_EOK;
+    }
+
+    pin_irq_handler_tab[gpio_port].pin = -1;
+    pin_irq_handler_tab[gpio_port].hdr = RT_NULL;
+    pin_irq_handler_tab[gpio_port].mode = 0;
+    pin_irq_handler_tab[gpio_port].args = RT_NULL;
+    rt_hw_interrupt_enable(level);
+
+    return RT_EOK;
+}
+
+static rt_err_t ifx_pin_irq_enable(struct rt_device *device, rt_base_t pin,
+                                   rt_uint32_t enabled)
+{
+    rt_uint16_t gpio_port;
+    rt_uint16_t gpio_pin;
+    rt_base_t level;
+    rt_uint8_t pin_irq_mode;
+
+    const struct pin_irq_map *irqmap;
+
+    if (PORT_GET(pin) < PIN_IFXPORT_MAX)
+    {
+        gpio_port = PORT_GET(pin);
+        gpio_pin = pin;
+    }
+    else
+    {
+        return -RT_ERROR;
+    }
+
+    if (enabled == PIN_IRQ_ENABLE)
+    {
+        level = rt_hw_interrupt_disable();
+
+        if (pin_irq_handler_tab[gpio_port].pin == -1)
+        {
+            rt_hw_interrupt_enable(level);
+            return -RT_EINVAL;
+        }
+
+        irqmap = &pin_irq_map[gpio_port];
+
+        irq_cb_data.callback = irq_callback;
+        irq_cb_data.callback_arg = (rt_uint16_t *)&pin_irq_map[gpio_port].port;
+
+        cyhal_gpio_register_callback(gpio_pin, &irq_cb_data);
+
+        Cy_GPIO_ClearInterrupt(CYHAL_GET_PORTADDR(gpio_pin), CYHAL_GET_PIN(gpio_pin));
+
+        switch (pin_irq_handler_tab[gpio_port].mode)
+        {
+        case PIN_IRQ_MODE_RISING:
+            pin_irq_mode = CYHAL_GPIO_IRQ_RISE;
+            break;
+
+        case PIN_IRQ_MODE_FALLING:
+            pin_irq_mode = CYHAL_GPIO_IRQ_FALL;
+            break;
+
+        case PIN_IRQ_MODE_RISING_FALLING:
+            pin_irq_mode = CYHAL_GPIO_IRQ_BOTH;
+            break;
+
+        default:
+            break;
+        }
+
+        cyhal_gpio_enable_event(gpio_pin, pin_irq_mode, GPIO_INTERRUPT_PRIORITY, RT_TRUE);
+
+        rt_hw_interrupt_enable(level);
+    }
+    else if (enabled == PIN_IRQ_DISABLE)
+    {
+        level = rt_hw_interrupt_disable();
+
+        Cy_GPIO_Port_Deinit(CYHAL_GET_PORTADDR(gpio_pin));
+
+#if !defined(COMPONENT_CAT1C)
+        IRQn_Type irqn = (IRQn_Type)(irqmap->irqno + PORT_GET(irqmap->port));
+#endif
+        _cyhal_irq_disable(irqn);
+
+        rt_hw_interrupt_enable(level);
+    }
+    else
+    {
+        return -RT_EINVAL;
+    }
+
+    return RT_EOK;
+}
+
+const static struct rt_pin_ops _ifx_pin_ops =
+{
+    ifx_pin_mode,
+    ifx_pin_write,
+    ifx_pin_read,
+    ifx_pin_attach_irq,
+    ifx_pin_dettach_irq,
+    ifx_pin_irq_enable,
+    RT_NULL,
+};
+
+int rt_hw_pin_init(void)
+{
+    return rt_device_pin_register("pin", &_ifx_pin_ops, RT_NULL);
+}
+
+#endif /* RT_USING_PIN */

+ 32 - 0
project_0/libraries/HAL_Drivers/drv_gpio.h

@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author            Notes
+ * 2022-07-1      Rbb666            first version
+ */
+
+#ifndef __DRV_GPIO_H__
+#define __DRV_GPIO_H__
+
+#include <rthw.h>
+#include <rtdevice.h>
+#include "drv_common.h"
+
+#include "cyhal_irq_psoc.h"
+
+#define GPIO_INTERRUPT_PRIORITY (7u)
+
+#define GET_PIN(PORTx,PIN)      ((((uint8_t)(PORTx)) << 3U) + ((uint8_t)(PIN)))
+
+struct pin_irq_map
+{
+    rt_uint16_t port;
+    IRQn_Type irqno;
+};
+
+int rt_hw_pin_init(void);
+
+#endif /* __DRV_GPIO_H__ */

+ 344 - 0
project_0/libraries/HAL_Drivers/drv_hwtimer.c

@@ -0,0 +1,344 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author                   Notes
+ * 2022-07-29     rtthread qiu       first version
+ */
+#include "drv_common.h"
+#include "drv_hwtimer.h"
+
+#include <board.h>
+#ifdef BSP_USING_TIM
+
+//#define DRV_DEBUG
+#define LOG_TAG "drv.hwtimer"
+#include <drv_log.h>
+static void isr_timer(void *callback_arg, cyhal_timer_event_t event);
+
+#ifdef RT_USING_HWTIMER
+enum
+{
+#ifdef BSP_USING_TIM1
+    TIM1_INDEX,
+#endif
+#ifdef BSP_USING_TIM2
+    TIM2_INDEX,
+#endif
+};
+
+struct cyp_hwtimer
+{
+    rt_hwtimer_t time_device;
+    cyhal_timer_t tim_handle;
+    IRQn_Type tim_irqn;
+    char *name;
+};
+
+static struct cyp_hwtimer cyp_hwtimer_obj[] =
+{
+#ifdef BSP_USING_TIM1
+    TIM1_CONFIG,
+#endif
+#ifdef BSP_USING_TIM2
+    TIM2_CONFIG,
+#endif
+};
+
+static void timer_init(rt_hwtimer_t *timer, rt_uint32_t state)
+{
+    RT_ASSERT(timer != RT_NULL);
+
+    cy_rslt_t result = RT_EOK;
+
+    cyhal_timer_t *tim = RT_NULL;
+
+    tim = (cyhal_timer_t *)timer->parent.user_data;
+
+    const cyhal_timer_cfg_t init_timer_cfg =
+        {
+            .compare_value = 0,              /* Timer compare value, not used */
+            .period = 9999,                  /* Defines the timer period */
+            .direction = CYHAL_TIMER_DIR_UP, /* Timer counts up */
+            .is_compare = false,             /* Don't use compare mode */
+            .is_continuous = true,           /* Run timer indefinitely */
+            .value = 0                       /* Initial value of counter */
+        };
+
+    if (state)
+    {
+        /* Initialize the timer object. Does not use input pin ('pin' is NC) and
+         * does not use a pre-configured clock source ('clk' is NULL). */
+        result = cyhal_timer_init(tim, NC, NULL);
+
+        if (result != CY_RSLT_SUCCESS)
+        {
+            LOG_E("timer init error \r\n");
+            return;
+        }
+        else
+        {
+            /* Configure timer period and operation mode such as count direction,
+                duration */
+            cyhal_timer_configure(tim, &init_timer_cfg);
+
+            /* Set the frequency of timer's clock source */
+            cyhal_timer_set_frequency(tim, 10000);
+
+            cyhal_timer_start(tim);
+        }
+    }
+    else
+    {
+        cyhal_timer_free(tim);
+        LOG_E("free time \r\n");
+    }
+}
+
+static rt_err_t timer_start(rt_hwtimer_t *timer, rt_uint32_t t, rt_hwtimer_mode_t opmode)
+{
+    RT_ASSERT(timer != RT_NULL);
+    RT_ASSERT(opmode != RT_NULL);
+
+    cy_rslt_t result = RT_EOK;
+
+    cyhal_timer_t *tim = RT_NULL;
+
+    tim = (cyhal_timer_t *)timer->parent.user_data;
+
+    const cyhal_timer_cfg_t init_timer_cfg =
+        {
+            .compare_value = 0,              /* Timer compare value, not used */
+            .period = t - 1,                 /* Defines the timer period */
+            .direction = CYHAL_TIMER_DIR_UP, /* Timer counts up */
+            .is_compare = false,             /* Don't use compare mode */
+            .is_continuous = true,           /* Run timer indefinitely */
+            .value = 0                       /* Initial value of counter */
+        };
+    /* Configure timer period and operation mode such as count direction,
+   duration */
+    cyhal_timer_configure(tim, &init_timer_cfg);
+
+    if (opmode == HWTIMER_MODE_ONESHOT)
+    {
+        /* set timer to single mode */
+        cyhal_timer_stop(tim);
+    }
+    else
+    {
+        cyhal_timer_reset(tim);
+    }
+
+    result = cyhal_timer_start(tim);
+    if (result != CY_RSLT_SUCCESS)
+    {
+        LOG_E("time start error\r\n");
+        cyhal_timer_free(tim);
+    }
+
+    /* Assign the ISR to execute on timer interrupt */
+    cyhal_timer_register_callback(tim, isr_timer, NULL);
+    /* Set the event on which timer interrupt occurs and enable it */
+    cyhal_timer_enable_event(tim, CYHAL_TIMER_IRQ_TERMINAL_COUNT, 1, true);
+
+    return result;
+}
+
+static void timer_stop(rt_hwtimer_t *timer)
+{
+
+    RT_ASSERT(timer != RT_NULL);
+
+    cyhal_timer_t *tim = RT_NULL;
+
+    tim = (cyhal_timer_t *)timer->parent.user_data;
+
+    cyhal_timer_stop(tim);
+}
+
+static rt_uint32_t timer_counter_get(rt_hwtimer_t *timer)
+{
+    cyhal_timer_t *tim = RT_NULL;
+
+    rt_uint32_t count;
+
+    RT_ASSERT(timer != RT_NULL);
+
+    tim = (cyhal_timer_t *)timer->parent.user_data;
+
+    count = cyhal_timer_read(tim);
+
+    return count;
+}
+
+static rt_err_t timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg)
+{
+    RT_ASSERT(timer != RT_NULL);
+    RT_ASSERT(arg != RT_NULL);
+
+    cyhal_timer_t *tim = RT_NULL;
+
+    rt_err_t result = -RT_ERROR;
+
+    tim = (cyhal_timer_t *)timer->parent.user_data;
+
+    switch (cmd)
+    {
+    case HWTIMER_CTRL_FREQ_SET:
+    {
+        rt_uint32_t freq;
+        rt_uint16_t val;
+
+        freq = *((rt_uint32_t *)arg);
+
+        result = cyhal_timer_set_frequency(tim, freq);
+
+        if (result != CY_RSLT_SUCCESS)
+        {
+            LOG_E("cyhal_timer_set_frequency error\r\n");
+            return -RT_ERROR;
+        }
+    }
+    break;
+    default:
+    {
+        result = -RT_EINVAL;
+    }
+    break;
+    }
+    return result;
+}
+
+static const struct rt_hwtimer_info _info = TIM_DEV_INFO_CONFIG;
+
+static const struct rt_hwtimer_ops _ops =
+    {
+        .init = timer_init,
+        .start = timer_start,
+        .stop = timer_stop,
+        .count_get = timer_counter_get,
+        .control = timer_ctrl,
+};
+
+#ifdef BSP_USING_TIM1
+static void isr_timer(void *callback_arg, cyhal_timer_event_t event)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    (void)callback_arg;
+    (void)event;
+
+    rt_device_hwtimer_isr(&cyp_hwtimer_obj[TIM1_INDEX].time_device);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+#endif
+#ifdef BSP_USING_TIM2
+static void isr_timer(void *callback_arg, cyhal_timer_event_t event)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    (void)callback_arg;
+    (void)event;
+
+    rt_device_hwtimer_isr(&cyp_hwtimer_obj[TIM2_INDEX].time_device);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+#endif
+
+int cyp_hwtimer_init(void)
+{
+    int i = 0;
+    int result = RT_EOK;
+
+    for (i = 0; i < sizeof(cyp_hwtimer_obj) / sizeof(cyp_hwtimer_obj[0]); i++)
+    {
+        cyp_hwtimer_obj[i].time_device.info = &_info;
+        cyp_hwtimer_obj[i].time_device.ops = &_ops;
+        if (rt_device_hwtimer_register(&cyp_hwtimer_obj[i].time_device, cyp_hwtimer_obj[i].name, &cyp_hwtimer_obj[i].tim_handle) != RT_EOK)
+        {
+            LOG_E("%s register failed", cyp_hwtimer_obj[i].name);
+            result = -RT_ERROR;
+        }
+    }
+    return result;
+}
+INIT_BOARD_EXPORT(cyp_hwtimer_init);
+
+#endif /*RT_USING_HWTIMER*/
+#endif /*BSP_USING_TIM*/
+
+/* this is a hwtimer test demo*/
+#include <rtthread.h>
+#include <rtdevice.h>
+
+#define HWTIMER_DEV_NAME "time2" /* device name */
+
+static rt_err_t timeout_cb(rt_device_t dev, rt_size_t size)
+{
+    rt_kprintf("this is hwtimer timeout callback fucntion!\n");
+    rt_kprintf("tick is :%d !\n", rt_tick_get());
+
+    return 0;
+}
+
+int hwtimer_sample()
+{
+    rt_err_t ret = RT_EOK;
+    rt_hwtimerval_t timeout_s;
+    rt_device_t hw_dev = RT_NULL;
+    rt_hwtimer_mode_t mode;
+    rt_uint32_t freq = 10000;
+
+    hw_dev = rt_device_find(HWTIMER_DEV_NAME);
+    if (hw_dev == RT_NULL)
+    {
+        rt_kprintf("hwtimer sample run failed! can't find %s device!\n", HWTIMER_DEV_NAME);
+        return -RT_ERROR;
+    }
+
+    ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
+    if (ret != RT_EOK)
+    {
+        rt_kprintf("open %s device failed!\n", HWTIMER_DEV_NAME);
+        return ret;
+    }
+
+    rt_device_set_rx_indicate(hw_dev, timeout_cb);
+
+    rt_device_control(hw_dev, HWTIMER_CTRL_FREQ_SET, &freq);
+
+    mode = HWTIMER_MODE_PERIOD;
+    ret = rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
+    if (ret != RT_EOK)
+    {
+        rt_kprintf("set mode failed! ret is :%d\n", ret);
+        return ret;
+    }
+
+    /* Example Set the timeout period of the timer */
+    timeout_s.sec = 3;  /* secend */
+    timeout_s.usec = 0; /* microsecend */
+    if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
+    {
+        rt_kprintf("set timeout value failed\n");
+        return -RT_ERROR;
+    }
+
+    while (1)
+    {
+        rt_thread_mdelay(1500);
+
+        rt_device_read(hw_dev, 0, &timeout_s, sizeof(timeout_s));
+        rt_kprintf("Read: Sec = %d, Usec = %d\n", timeout_s.sec, timeout_s.usec);
+    }
+    return ret;
+}
+MSH_CMD_EXPORT(hwtimer_sample, hwtimer sample);

+ 51 - 0
project_0/libraries/HAL_Drivers/drv_hwtimer.h

@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author             Notes
+ * 2022-07-29     rtthread qiu      first version
+ */
+
+#ifndef __DRV_HWTIMER_H__
+#define __DRV_HWTIMER_H__
+
+#include <rtthread.h>
+
+#include "cy_pdl.h"
+#include "cyhal.h"
+#include "cybsp.h"
+#include "cy_retarget_io.h"
+
+#ifndef TIM_DEV_INFO_CONFIG
+#define TIM_DEV_INFO_CONFIG            \
+    {                                  \
+        .maxfreq = 1000000,            \
+        .minfreq = 2000,               \
+        .maxcnt = 0xFFFF,              \
+        .cntmode = HWTIMER_CNTMODE_UP, \
+    }
+#endif /* TIM_DEV_INFO_CONFIG */
+
+#ifdef BSP_USING_TIM1
+#ifndef TIM1_CONFIG
+#define TIM1_CONFIG                            \
+    {                                          \
+        .tim_irqn = tcpwm_0_interrupts_0_IRQn, \
+        .name = "time1",                       \
+    }
+#endif /*TIM1_CONFIG*/
+#endif /* BSP_USING_TIM1 */
+
+#ifdef BSP_USING_TIM2
+#ifndef TIM2_CONFIG
+#define TIM2_CONFIG                            \
+    {                                          \
+        .tim_irqn = tcpwm_1_interrupts_0_IRQn, \
+        .name = "time2",                       \
+    }
+#endif /*TIM2_CONFIG*/
+#endif /* BSP_USING_TIM2 */
+
+#endif /* __DRV_HWTIMER_H__ */

+ 174 - 0
project_0/libraries/HAL_Drivers/drv_i2c.c

@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-08     Rbb666       first implementation.
+ */
+
+#include "board.h"
+
+#if defined(RT_USING_I2C)
+#if defined(BSP_USING_HW_I2C3) || defined(BSP_USING_HW_I2C6)
+#include <rtdevice.h>
+
+#ifndef I2C3_CONFIG
+#define I2C3_CONFIG                  \
+    {                                \
+        .name = "i2c3",              \
+        .scl_pin = BSP_I2C3_SCL_PIN, \
+        .sda_pin = BSP_I2C3_SDA_PIN, \
+    }
+#endif /* I2C3_CONFIG */
+#endif
+#ifndef I2C6_CONFIG
+#define I2C6_CONFIG                  \
+    {                                \
+        .name = "i2c6",              \
+        .scl_pin = BSP_I2C6_SCL_PIN, \
+        .sda_pin = BSP_I2C6_SDA_PIN, \
+    }
+#endif /* I2C6_CONFIG */
+
+enum
+{
+#ifdef BSP_USING_HW_I2C3
+    I2C3_INDEX,
+#endif
+#ifdef BSP_USING_HW_I2C6
+    I2C6_INDEX,
+#endif
+};
+
+struct ifx_i2c_config
+{
+    char *name;
+    rt_uint32_t scl_pin;
+    rt_uint32_t sda_pin;
+};
+
+struct ifx_i2c
+{
+    cyhal_i2c_t mI2C;
+    cyhal_i2c_cfg_t mI2C_cfg;
+    struct ifx_i2c_config *config;
+    struct rt_i2c_bus_device i2c_bus;
+};
+
+static struct ifx_i2c_config i2c_config[] =
+    {
+#ifdef BSP_USING_HW_I2C3
+        I2C3_CONFIG,
+#endif
+
+#ifdef BSP_USING_HW_I2C6
+        I2C6_CONFIG,
+#endif
+};
+
+static struct ifx_i2c i2c_objs[sizeof(i2c_config) / sizeof(i2c_config[0])] = {0};
+
+static int ifx_i2c_read(struct ifx_i2c *hi2c, rt_uint16_t slave_address, rt_uint8_t *p_buffer, rt_uint16_t data_byte)
+{
+    if (cyhal_i2c_master_read(&hi2c->mI2C, slave_address, p_buffer, data_byte, 10, true) != RT_EOK)
+    {
+        return -RT_ERROR;
+    }
+
+    return 0;
+}
+
+static int ifx_i2c_write(struct ifx_i2c *hi2c, uint16_t slave_address, uint8_t *p_buffer, uint16_t data_byte)
+{
+    if (cyhal_i2c_master_write(&hi2c->mI2C, slave_address, p_buffer, data_byte, 10, true) != RT_EOK)
+    {
+        return -RT_ERROR;
+    }
+
+    return 0;
+}
+
+static rt_ssize_t _i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
+{
+    struct rt_i2c_msg *msg;
+    rt_uint32_t i;
+    struct ifx_i2c *i2c_obj;
+
+    RT_ASSERT(bus != RT_NULL);
+    RT_ASSERT(msgs != RT_NULL);
+
+    i2c_obj = rt_container_of(bus, struct ifx_i2c, i2c_bus);
+
+    for (i = 0; i < num; i++)
+    {
+        msg = &msgs[i];
+
+        if (msg->flags & RT_I2C_RD)
+        {
+            if (ifx_i2c_read(i2c_obj, msg->addr, msg->buf, msg->len) != 0)
+            {
+                goto out;
+            }
+        }
+        else
+        {
+            if (ifx_i2c_write(i2c_obj, msg->addr, msg->buf, msg->len) != 0)
+            {
+                goto out;
+            }
+        }
+    }
+
+out:
+
+    return i;
+}
+
+static const struct rt_i2c_bus_device_ops i2c_ops =
+    {
+        _i2c_xfer,
+        RT_NULL,
+        RT_NULL};
+
+void HAL_I2C_Init(struct ifx_i2c *obj)
+{
+    rt_uint8_t result = RT_EOK;
+
+    result = cyhal_i2c_init(&obj->mI2C, obj->config->sda_pin, obj->config->scl_pin, NULL);
+    RT_ASSERT(result == RT_EOK);
+
+    result = cyhal_i2c_configure(&obj->mI2C, &obj->mI2C_cfg);
+    RT_ASSERT(result == RT_EOK);
+}
+
+int rt_hw_i2c_init(void)
+{
+    rt_err_t result;
+    cyhal_i2c_t mI2C;
+
+    for (int i = 0; i < sizeof(i2c_config) / sizeof(i2c_config[0]); i++)
+    {
+        i2c_objs[i].config = &i2c_config[i];
+        i2c_objs[i].i2c_bus.parent.user_data = &i2c_config[i];
+
+        i2c_objs[i].mI2C_cfg.is_slave = false;
+        i2c_objs[i].mI2C_cfg.address = 0;
+        i2c_objs[i].mI2C_cfg.frequencyhal_hz = (400000UL);
+
+        i2c_objs[i].mI2C = mI2C;
+
+        i2c_objs[i].i2c_bus.ops = &i2c_ops;
+
+        HAL_I2C_Init(&i2c_objs[i]);
+
+        result = rt_i2c_bus_device_register(&i2c_objs[i].i2c_bus, i2c_config[i].name);
+        RT_ASSERT(result == RT_EOK);
+    }
+
+    return 0;
+}
+INIT_DEVICE_EXPORT(rt_hw_i2c_init);
+
+#endif /* defined(BSP_USING_I2C1) || defined(BSP_USING_I2C2) */

+ 27 - 0
project_0/libraries/HAL_Drivers/drv_log.h

@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2018-11-15     SummerGift   first version
+ */
+
+/*
+ * NOTE: DO NOT include this file on the header file.
+ */
+
+#ifndef LOG_TAG
+    #define DBG_TAG               "drv"
+#else
+    #define DBG_TAG               LOG_TAG
+#endif /* LOG_TAG */
+
+#ifdef DRV_DEBUG
+    #define DBG_LVL               DBG_LOG
+#else
+    #define DBG_LVL               DBG_INFO
+#endif /* DRV_DEBUG */
+
+#include <rtdbg.h>

+ 281 - 0
project_0/libraries/HAL_Drivers/drv_pwm.c

@@ -0,0 +1,281 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-13     Rbb666       first version
+ */
+#include "drv_pwm.h"
+
+#ifdef RT_USING_PWM
+
+#include <drivers/rt_drv_pwm.h>
+#include "drv_gpio.h"
+
+//#define DRV_DEBUG
+#define LOG_TAG "drv.pwm"
+#include <drv_log.h>
+
+struct rt_device_pwm pwm_device;
+
+struct ifx_pwm
+{
+    struct rt_device_pwm pwm_device;
+    cyhal_pwm_t *pwm_obj;
+    rt_uint8_t channel;
+    char *name;
+    rt_uint8_t gpio;
+};
+
+static struct ifx_pwm ifx_pwm_obj[] =
+{
+#ifdef BSP_USING_PWM0_PORT13
+    PWM0_CH3_PORT13_CONFIG,
+#endif
+
+#ifdef BSP_USING_PWM0_PORT2
+    PWM0_CH7_PORT2_CONFIG,
+#endif
+
+#ifdef BSP_USING_PWM0_PORT5
+    PWM0_CH7_PORT5_CONFIG,
+#endif
+
+#ifdef BSP_USING_PWM0_PORT7
+    PWM0_CH7_PORT7_CONFIG,
+#endif
+
+#ifdef BSP_USING_PWM0_PORT9
+    PWM0_CH7_PORT9_CONFIG,
+#endif
+
+#ifdef BSP_USING_PWM0_PORT10
+    PWM0_CH7_PORT10_CONFIG,
+#endif
+
+#ifdef BSP_USING_PWM0_PORT12
+    PWM0_CH7_PORT12_CONFIG,
+#endif
+};
+
+static rt_err_t drv_pwm_enable(cyhal_pwm_t *htim, struct rt_pwm_configuration *configuration, rt_bool_t enable)
+{
+    /* get the value of channel */
+    rt_uint32_t channel = configuration->channel;
+
+    if (!configuration->complementary || configuration->complementary)
+    {
+        if (!enable)
+        {
+            if (channel == 3)
+            {
+                htim->tcpwm.resource.channel_num = channel;
+            }
+            else if (channel == 7)
+            {
+                htim->tcpwm.resource.channel_num = channel;
+            }
+            cyhal_pwm_stop(htim);
+        }
+        else
+        {
+            if (channel == 3)
+            {
+                htim->tcpwm.resource.channel_num = channel;
+            }
+            else if (channel == 7)
+            {
+                htim->tcpwm.resource.channel_num = channel;
+            }
+            cyhal_pwm_start(htim);
+        }
+    }
+
+    return RT_EOK;
+}
+
+static rt_err_t drv_pwm_set(cyhal_pwm_t *htim, struct rt_pwm_configuration *configuration)
+{
+    rt_uint64_t tim_clock;
+    rt_uint32_t period, pulse;
+
+    tim_clock = (rt_uint32_t)(htim->tcpwm.clock_hz);
+
+    htim->tcpwm.resource.channel_num = configuration->channel;
+
+    period = (unsigned long long)configuration->period / 1000ULL;
+
+    pulse = (unsigned long long)configuration->pulse / 1000ULL;
+
+    cyhal_pwm_set_period(htim, period, pulse);
+
+    return RT_EOK;
+}
+
+static rt_err_t drv_pwm_get(cyhal_pwm_t *htim, struct rt_pwm_configuration *configuration)
+{
+    uint32_t Period = Cy_TCPWM_PWM_GetPeriod0(htim->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(htim->tcpwm.resource));
+
+    uint32_t Compare = Cy_TCPWM_PWM_GetCounter(htim->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(htim->tcpwm.resource));
+
+    configuration->period = Period;
+
+    configuration->pulse = Compare;
+
+    return RT_EOK;
+}
+
+static rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg)
+{
+    struct rt_pwm_configuration *configuration = (struct rt_pwm_configuration *)arg;
+    cyhal_pwm_t *htim = (cyhal_pwm_t *)device->parent.user_data;
+
+    switch (cmd)
+    {
+    case PWMN_CMD_ENABLE:
+        configuration->complementary = RT_TRUE;
+
+    case PWM_CMD_ENABLE:
+        return drv_pwm_enable(htim, configuration, RT_TRUE);
+
+    case PWMN_CMD_DISABLE:
+        configuration->complementary = RT_FALSE;
+
+    case PWM_CMD_DISABLE:
+        return drv_pwm_enable(htim, configuration, RT_FALSE);
+
+    case PWM_CMD_SET:
+        return drv_pwm_set(htim, configuration);
+
+    case PWM_CMD_GET:
+        return drv_pwm_get(htim, configuration);
+
+    default:
+        return -RT_EINVAL;
+    }
+}
+
+static struct rt_pwm_ops drv_ops = {drv_pwm_control};
+
+static rt_err_t ifx_hw_pwm_init(struct ifx_pwm *device)
+{
+    rt_err_t result = RT_EOK;
+
+    RT_ASSERT(device != RT_NULL);
+
+    /* config pwm channel */
+    if (device->channel == 0x03)
+    {
+        if (cyhal_pwm_init_adv(device->pwm_obj, device->gpio, NC, CYHAL_PWM_LEFT_ALIGN, true, 0u, false, RT_NULL) != RT_EOK)
+        {
+            LOG_E("%s channel3 config failed", device->name);
+            result = -RT_ERROR;
+            goto __exit;
+        }
+    }
+    /* config pwm channel */
+    if (device->channel == 0x07)
+    {
+        if (cyhal_pwm_init_adv(device->pwm_obj, device->gpio, NC, CYHAL_PWM_LEFT_ALIGN, true, 0u, false, RT_NULL) != RT_EOK)
+        {
+            LOG_E("%s channel7 config failed", device->name);
+            result = -RT_ERROR;
+            goto __exit;
+        }
+    }
+__exit:
+    return result;
+}
+
+static int rt_hw_pwm_init(void)
+{
+    int i;
+    int result = RT_EOK;
+
+    for (i = 0; i < sizeof(ifx_pwm_obj) / sizeof(ifx_pwm_obj[0]); i++)
+    {
+        ifx_pwm_obj[i].pwm_obj = rt_malloc(sizeof(cyhal_pwm_t));
+        RT_ASSERT(ifx_pwm_obj[i].pwm_obj != RT_NULL);
+
+        /* pwm init */
+        if (ifx_hw_pwm_init(&ifx_pwm_obj[i]) != RT_EOK)
+        {
+            LOG_E("%s init failed", ifx_pwm_obj[i].name);
+            result = -RT_ERROR;
+            goto __exit;
+        }
+        else
+        {
+            if (rt_device_pwm_register(&ifx_pwm_obj[i].pwm_device, ifx_pwm_obj[i].name, &drv_ops, ifx_pwm_obj[i].pwm_obj) == RT_EOK)
+            {
+                LOG_D("%s register success", ifx_pwm_obj[i].name);
+            }
+            else
+            {
+                LOG_D("%s register failed", ifx_pwm_obj[i].name);
+                result = -RT_ERROR;
+            }
+        }
+    }
+
+__exit:
+    return result;
+}
+INIT_BOARD_EXPORT(rt_hw_pwm_init);
+
+#define PWM_DEV_NAME "pwm0"
+#define PWM_DEV_CHANNEL 7
+
+struct rt_device_pwm *pwm_dev;
+
+static int pwm_sample(int argc, char *argv[])
+{
+    rt_uint32_t period, pulse, dir;
+
+    period = 1 * 1000 * 1000;
+    dir = 1;
+    pulse = 0;
+
+    pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);
+
+    if (pwm_dev == RT_NULL)
+    {
+        rt_kprintf("pwm sample run failed! can't find %s device!\n", PWM_DEV_NAME);
+        return -RT_ERROR;
+    }
+
+    rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, period, pulse);
+    rt_pwm_enable(pwm_dev, PWM_DEV_CHANNEL);
+
+    rt_kprintf("Now PWM[%s] Channel[%d] Period[%d] Pulse[%d]\n", PWM_DEV_NAME, PWM_DEV_CHANNEL, period, pulse);
+
+    while (1)
+    {
+        rt_thread_mdelay(50);
+
+        if (dir)
+        {
+            pulse += 100000;
+        }
+        else
+        {
+            pulse -= 100000;
+        }
+
+        if (pulse >= period)
+        {
+            dir = 0;
+        }
+
+        if (0 == pulse)
+        {
+            dir = 1;
+        }
+
+        rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, period, pulse);
+    }
+}
+MSH_CMD_EXPORT(pwm_sample, <pwm0> channel7 sample);
+#endif

+ 93 - 0
project_0/libraries/HAL_Drivers/drv_pwm.h

@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-13     Rbb666       first version
+ */
+
+#ifndef __PWM_CONFIG_H__
+#define __PWM_CONFIG_H__
+
+#include <rtthread.h>
+#include <board.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define MAX_PERIOD 65535
+
+#ifdef BSP_USING_PWM0
+#ifndef PWM0_CH3_PORT13_CONFIG
+#define PWM0_CH3_PORT13_CONFIG      \
+    {                               \
+        .name = "pwm0",             \
+        .channel = 3,               \
+        .gpio = GET_PIN(13, 7),     \
+    }
+#endif /* PWM0_CH7_PORT2_CONFIG */
+
+#ifndef PWM0_CH7_PORT2_CONFIG
+#define PWM0_CH7_PORT2_CONFIG       \
+    {                               \
+        .name = "pwm0",             \
+        .channel = 7,               \
+        .gpio = GET_PIN(2, 2),      \
+    }
+#endif /* PWM0_CH7_PORT2_CONFIG */
+
+#ifndef PWM0_CH7_PORT5_CONFIG
+#define PWM0_CH7_PORT5_CONFIG       \
+    {                               \
+        .name = "pwm0",             \
+        .channel = 7,               \
+        .gpio = GET_PIN(5, 6),      \
+    }
+#endif /* PWM0_CH7_PORT5_CONFIG */
+
+#ifndef PWM0_CH7_PORT7_CONFIG
+#define PWM0_CH7_PORT7_CONFIG       \
+    {                               \
+        .name = "pwm0",             \
+        .channel = 7,               \
+        .gpio = GET_PIN(7, 7),      \
+    }
+#endif /* PWM0_CH7_PORT7_CONFIG */
+
+#ifndef PWM0_CH7_PORT9_CONFIG
+#define PWM0_CH7_PORT9_CONFIG       \
+    {                               \
+        .name = "pwm0",             \
+        .channel = 7,               \
+        .gpio = GET_PIN(9, 4),      \
+    }
+#endif /* PWM0_CH7_PORT9_CONFIG */
+
+#ifndef PWM0_CH7_PORT10_CONFIG
+#define PWM0_CH7_PORT10_CONFIG      \
+    {                               \
+        .name = "pwm0",             \
+        .channel = 7,               \
+        .gpio = GET_PIN(10, 2),     \
+    }
+#endif /* PWM0_CH7_PORT10_CONFIG */
+
+#ifndef PWM0_CH7_PORT12_CONFIG
+#define PWM0_CH7_PORT12_CONFIG      \
+    {                               \
+        .name = "pwm0",             \
+        .channel = 7,               \
+        .gpio = GET_PIN(12, 6),     \
+    }
+#endif /* PWM0_CH7_PORT12_CONFIG */
+#endif /* BSP_USING_PWM0 */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 167 - 0
project_0/libraries/HAL_Drivers/drv_rtc.c

@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date         Author         Notes
+ * 2022-07-25   Rbb666         first version
+ */
+
+#include <rtthread.h>
+#include <rtdevice.h>
+#include <sys/time.h>
+#include "drv_common.h"
+
+#ifdef BSP_USING_RTC
+
+//#define DRV_DEBUG
+#define LOG_TAG                         "drv.rtc"
+#include <drv_log.h>
+
+cyhal_rtc_t rtc_obj;
+
+static rt_rtc_dev_t ifx32_rtc_dev;
+
+static int get_day_of_week(int day, int month, int year)
+{
+    int ret;
+    int k = 0;
+    int j = 0;
+
+    if (month < CY_RTC_MARCH)
+    {
+        month += CY_RTC_MONTHS_PER_YEAR;
+        year--;
+    }
+
+    k = (year % 100);
+    j = (year / 100);
+    ret = (day + (13 * (month + 1) / 5) + k + (k / 4) + (j / 4) + (5 * j)) % 7;
+    ret = ((ret + 6) % 7);
+
+    return ret;
+}
+
+static rt_err_t set_rtc_time_stamp(time_t time_stamp)
+{
+    struct tm tm = {0};
+    struct tm new_time = {0};
+
+    gmtime_r(&time_stamp, &tm);
+
+    if (tm.tm_year < 100)
+    {
+        return -RT_ERROR;
+    }
+
+    new_time.tm_sec     = tm.tm_sec ;
+    new_time.tm_min     = tm.tm_min ;
+    new_time.tm_hour    = tm.tm_hour;
+    new_time.tm_mday    = tm.tm_mday;
+    new_time.tm_mon     = tm.tm_mon;
+    new_time.tm_year    = tm.tm_year;
+    new_time.tm_wday    = get_day_of_week(tm.tm_mday, tm.tm_mon, tm.tm_year);
+
+    if (cyhal_rtc_write(&rtc_obj, &new_time) != RT_EOK)
+    {
+        return -RT_ERROR;
+    }
+
+    LOG_D("set rtc time.");
+
+    return RT_EOK;
+}
+
+static rt_err_t ifx_rtc_get_timeval(struct timeval *tv)
+{
+    struct tm tm_new = {0};
+    struct tm date_time = {0};
+
+    cyhal_rtc_read(&rtc_obj, &date_time);
+
+    tm_new.tm_sec  = date_time.tm_sec;
+    tm_new.tm_min  = date_time.tm_min;
+    tm_new.tm_hour = date_time.tm_hour;
+    tm_new.tm_mday = date_time.tm_mday;
+    tm_new.tm_mon  = date_time.tm_mon;
+    tm_new.tm_year = date_time.tm_year;
+
+    tv->tv_sec = timegm(&tm_new);
+
+    return RT_EOK;
+}
+
+static rt_err_t _rtc_init(void)
+{
+    if (cyhal_rtc_init(&rtc_obj) != RT_EOK)
+    {
+        LOG_E("rtc init failed.");
+        return -RT_ERROR;
+    }
+
+    return RT_EOK;
+}
+
+static rt_err_t _rtc_get_secs(time_t *sec)
+{
+    struct timeval tv;
+
+    ifx_rtc_get_timeval(&tv);
+    *(time_t *) sec = tv.tv_sec;
+    LOG_D("RTC: get rtc_time %d", *sec);
+
+    return RT_EOK;
+}
+
+static rt_err_t _rtc_set_secs(time_t *sec)
+{
+    rt_err_t result = RT_EOK;
+
+    if (set_rtc_time_stamp(*sec))
+    {
+        result = -RT_ERROR;
+    }
+
+    LOG_D("RTC: set rtc_time %d", *sec);
+
+    return result;
+}
+
+static const struct rt_rtc_ops _rtc_ops =
+{
+    _rtc_init,
+    _rtc_get_secs,
+    _rtc_set_secs,
+    RT_NULL,
+    RT_NULL,
+    ifx_rtc_get_timeval,
+    RT_NULL,
+};
+
+/**
+ * @brief    RTC initialization function.
+ *
+ * @return   RT_EOK indicates successful initialization, other value indicates failed;
+ */
+static int rt_hw_rtc_init(void)
+{
+    rt_err_t result = RT_EOK;
+
+    ifx32_rtc_dev.ops = &_rtc_ops;
+
+    if (rt_hw_rtc_register(&ifx32_rtc_dev, "rtc", RT_DEVICE_FLAG_RDWR, RT_NULL) != RT_EOK)
+    {
+        LOG_E("rtc init failed");
+        result = -RT_ERROR;
+    }
+    else
+    {
+        LOG_D("rtc init success");
+    }
+
+    return result;
+}
+
+INIT_DEVICE_EXPORT(rt_hw_rtc_init);
+#endif

+ 180 - 0
project_0/libraries/HAL_Drivers/drv_soft_i2c.c

@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-20     Rbb666       first version
+ */
+
+#include <board.h>
+#include "drv_soft_i2c.h"
+
+#ifdef RT_USING_I2C
+
+//#define DRV_DEBUG
+#define LOG_TAG              "drv.i2c"
+#include <drv_log.h>
+
+#if !defined(BSP_USING_I2C1)
+    #error "Please define at least one BSP_USING_I2Cx"
+    /* this driver can be disabled at menuconfig -> RT-Thread Components -> Device Drivers */
+#endif
+
+static const struct ifx_soft_i2c_config soft_i2c_config[] =
+{
+    #ifdef BSP_USING_I2C1
+    I2C1_BUS_CONFIG,
+    #endif
+};
+
+static struct ifx_i2c i2c_obj[sizeof(soft_i2c_config) / sizeof(soft_i2c_config[0])];
+
+/**
+ * This function initializes the i2c pin.
+ *
+ * @param ifx i2c dirver class.
+ */
+static void ifx_i2c_gpio_init(struct ifx_i2c *i2c)
+{
+    struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)i2c->ops.data;
+
+    rt_pin_mode(cfg->scl, PIN_MODE_OUTPUT_OD);
+    rt_pin_mode(cfg->sda, PIN_MODE_OUTPUT_OD);
+
+    rt_pin_write(cfg->scl, PIN_HIGH);
+    rt_pin_write(cfg->sda, PIN_HIGH);
+}
+
+/**
+ * This function sets the sda pin.
+ *
+ * @param ifx config class.
+ * @param The sda pin state.
+ */
+static void ifx_set_sda(void *data, rt_int32_t state)
+{
+    struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)data;
+
+    if (state)
+    {
+        rt_pin_write(cfg->sda, PIN_HIGH);
+    }
+    else
+    {
+        rt_pin_write(cfg->sda, PIN_LOW);
+    }
+}
+
+/**
+ * This function sets the scl pin.
+ *
+ * @param ifx config class.
+ * @param The scl pin state.
+ */
+static void ifx_set_scl(void *data, rt_int32_t state)
+{
+    struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)data;
+
+    if (state)
+    {
+        rt_pin_write(cfg->scl, PIN_HIGH);
+    }
+    else
+    {
+        rt_pin_write(cfg->scl, PIN_LOW);
+    }
+}
+
+/**
+ * This function gets the sda pin state.
+ *
+ * @param The sda pin state.
+ */
+static rt_int32_t ifx_get_sda(void *data)
+{
+    struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)data;
+    return rt_pin_read(cfg->sda);
+}
+
+/**
+ * This function gets the scl pin state.
+ *
+ * @param The scl pin state.
+ */
+static rt_int32_t ifx_get_scl(void *data)
+{
+    struct ifx_soft_i2c_config *cfg = (struct ifx_soft_i2c_config *)data;
+    return rt_pin_read(cfg->scl);
+}
+
+static const struct rt_i2c_bit_ops ifx_bit_ops_default =
+{
+    .data     = RT_NULL,
+    .set_sda  = ifx_set_sda,
+    .set_scl  = ifx_set_scl,
+    .get_sda  = ifx_get_sda,
+    .get_scl  = ifx_get_scl,
+    .udelay   = rt_hw_us_delay,
+    .delay_us = 1,
+    .timeout  = 100
+};
+
+/**
+ * if i2c is locked, this function will unlock it
+ *
+ * @param ifx config class
+ *
+ * @return RT_EOK indicates successful unlock.
+ */
+static rt_err_t ifx_i2c_bus_unlock(const struct ifx_soft_i2c_config *cfg)
+{
+    rt_int32_t i = 0;
+
+    if (PIN_LOW == rt_pin_read(cfg->sda))
+    {
+        while (i++ < 9)
+        {
+            rt_pin_write(cfg->scl, PIN_HIGH);
+            rt_hw_us_delay(100);
+            rt_pin_write(cfg->scl, PIN_LOW);
+            rt_hw_us_delay(100);
+        }
+    }
+
+    if (PIN_LOW == rt_pin_read(cfg->sda))
+    {
+        return -RT_ERROR;
+    }
+
+    return RT_EOK;
+}
+
+/* I2C initialization function */
+int rt_hw_i2c_init(void)
+{
+    rt_size_t obj_num = sizeof(i2c_obj) / sizeof(struct ifx_i2c);
+    rt_err_t result;
+
+    for (int i = 0; i < obj_num; i++)
+    {
+        i2c_obj[i].ops = ifx_bit_ops_default;
+        i2c_obj[i].ops.data = (void *)&soft_i2c_config[i];
+        i2c_obj[i].i2c2_bus.priv = &i2c_obj[i].ops;
+        ifx_i2c_gpio_init(&i2c_obj[i]);
+        result = rt_i2c_bit_add_bus(&i2c_obj[i].i2c2_bus, soft_i2c_config[i].bus_name);
+        RT_ASSERT(result == RT_EOK);
+        ifx_i2c_bus_unlock(&soft_i2c_config[i]);
+
+        LOG_D("software simulation %s init done, pin scl: %d, pin sda %d",
+              soft_i2c_config[i].bus_name,
+              soft_i2c_config[i].scl,
+              soft_i2c_config[i].sda);
+    }
+
+    return RT_EOK;
+}
+INIT_BOARD_EXPORT(rt_hw_i2c_init);
+
+#endif /* RT_USING_I2C */

+ 43 - 0
project_0/libraries/HAL_Drivers/drv_soft_i2c.h

@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-20     Rbb666       first version
+ */
+
+#ifndef __DRV_I2C__
+#define __DRV_I2C__
+
+#include <rtthread.h>
+#include <rthw.h>
+#include <rtdevice.h>
+
+/* ifx config class */
+struct ifx_soft_i2c_config
+{
+    rt_uint8_t scl;
+    rt_uint8_t sda;
+    const char *bus_name;
+};
+/* ifx i2c dirver class */
+struct ifx_i2c
+{
+    struct rt_i2c_bit_ops ops;
+    struct rt_i2c_bus_device i2c2_bus;
+};
+
+#ifdef BSP_USING_I2C1
+#define I2C1_BUS_CONFIG                                  \
+    {                                                    \
+        .scl = BSP_I2C1_SCL_PIN,                         \
+        .sda = BSP_I2C1_SDA_PIN,                         \
+        .bus_name = "i2c1",                              \
+    }
+#endif
+
+int rt_hw_i2c_init(void);
+
+#endif

+ 255 - 0
project_0/libraries/HAL_Drivers/drv_spi.c

@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-18     Rbb666       first version
+ */
+
+#include <drv_spi.h>
+
+#ifdef RT_USING_SPI
+
+//#define DRV_DEBUG
+#define DBG_TAG              "drv.spi"
+#ifdef DRV_DEBUG
+    #define DBG_LVL               DBG_LOG
+#else
+    #define DBG_LVL               DBG_INFO
+#endif /* DRV_DEBUG */
+#include <rtdbg.h>
+
+struct ifx_sw_spi_cs
+{
+    rt_uint32_t pin;
+};
+
+#ifdef BSP_USING_SPI0
+    static struct rt_spi_bus spi_bus0;
+#endif
+#ifdef BSP_USING_SPI3
+    static struct rt_spi_bus spi_bus3;
+#endif
+
+#ifdef BSP_USING_SPI6
+    static struct rt_spi_bus spi_bus6;
+#endif
+static struct ifx_spi spi_bus_obj[] =
+{
+    #ifdef BSP_USING_SPI0
+    {
+        .bus_name = "spi0",
+        .spi_bus = &spi_bus0,
+        .sck_pin = GET_PIN(0, 4),
+        .miso_pin = GET_PIN(0, 3),
+        .mosi_pin = GET_PIN(0, 2),
+    },
+    #endif
+    #ifdef BSP_USING_SPI3
+    {
+        .bus_name = "spi3",
+        .spi_bus = &spi_bus3,
+        .sck_pin = GET_PIN(6, 2),
+        .miso_pin = GET_PIN(6, 1),
+        .mosi_pin = GET_PIN(6, 0),
+    },
+    #endif
+    #ifdef BSP_USING_SPI6
+    {
+        .bus_name = "spi6",
+        .spi_bus = &spi_bus6,
+        .sck_pin = GET_PIN(12, 2),
+        .miso_pin = GET_PIN(12, 1),
+        .mosi_pin = GET_PIN(12, 0),
+    },
+    #endif
+};
+
+/* private rt-thread spi ops function */
+static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *configuration);
+static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message);
+
+static struct rt_spi_ops ifx_spi_ops =
+{
+    .configure = spi_configure,
+    .xfer = spixfer,
+};
+
+static void ifx_spi_init(struct ifx_spi *ifx_spi)
+{
+    int result = RT_EOK;
+
+    result = cyhal_spi_init(ifx_spi->spi_obj, ifx_spi->mosi_pin, ifx_spi->miso_pin, ifx_spi->sck_pin,
+                            NC, NULL, ifx_spi->spi_obj->data_bits, ifx_spi->spi_obj->mode, false);
+
+    RT_ASSERT(result == RT_EOK);
+
+    rt_kprintf("[%s] Freq:[%d]HZ\n", ifx_spi->bus_name, ifx_spi->freq);
+
+    result = cyhal_spi_set_frequency(ifx_spi->spi_obj, ifx_spi->freq);
+
+    RT_ASSERT(result != CYHAL_SPI_RSLT_CLOCK_ERROR);
+}
+
+static rt_err_t spi_configure(struct rt_spi_device *device,
+                              struct rt_spi_configuration *configuration)
+{
+    struct rt_spi_bus *spi_bus = (struct rt_spi_bus *)device->bus;
+    struct ifx_spi *spi_device = (struct ifx_spi *)spi_bus->parent.user_data;
+
+    RT_ASSERT(device != RT_NULL);
+    RT_ASSERT(configuration != RT_NULL);
+
+    /* data_width */
+    if (configuration->data_width <= 8)
+    {
+        spi_device->spi_obj->data_bits = 8;
+    }
+    else if (configuration->data_width <= 16)
+    {
+        spi_device->spi_obj->data_bits = 16;
+    }
+    else
+    {
+        return -RT_EIO;
+    }
+
+    uint32_t max_hz;
+    max_hz = configuration->max_hz;
+
+    spi_device->freq = max_hz;
+
+    /* MSB or LSB */
+    switch (configuration->mode & RT_SPI_MODE_3)
+    {
+        case RT_SPI_MODE_0:
+            spi_device->spi_obj->mode = CYHAL_SPI_MODE_00_MSB;
+            break;
+
+        case RT_SPI_MODE_1:
+            spi_device->spi_obj->mode = CYHAL_SPI_MODE_01_MSB;
+            break;
+
+        case RT_SPI_MODE_2:
+            spi_device->spi_obj->mode = CYHAL_SPI_MODE_10_MSB;
+            break;
+
+        case RT_SPI_MODE_3:
+            spi_device->spi_obj->mode = CYHAL_SPI_MODE_11_MSB;
+            break;
+    }
+
+    ifx_spi_init(spi_device);
+
+    return RT_EOK;
+}
+
+static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message)
+{
+    RT_ASSERT(device != NULL);
+    RT_ASSERT(message != NULL);
+
+    struct rt_spi_bus *spi_bus = (struct rt_spi_bus *)device->bus;
+    struct ifx_spi *spi_device = (struct ifx_spi *)spi_bus->parent.user_data;
+
+    struct rt_spi_configuration *config = &device->config;
+    struct ifx_sw_spi_cs *cs = device->parent.user_data;
+
+    /* take CS */
+    if (message->cs_take)
+    {
+        cyhal_gpio_write(cs->pin, PIN_LOW);
+        LOG_D("spi take cs\n");
+    }
+
+    int result = RT_EOK;
+
+    if (message->length > 0)
+    {
+        if (message->send_buf == RT_NULL && message->recv_buf != RT_NULL)
+        {
+            /**< receive message */
+            result = cyhal_spi_transfer(spi_device->spi_obj, RT_NULL, 0x00, message->recv_buf, message->length, 0x00);
+        }
+        else if (message->send_buf != RT_NULL && message->recv_buf == RT_NULL)
+        {
+            /**< send message */
+            result = cyhal_spi_transfer(spi_device->spi_obj, message->send_buf, message->length, RT_NULL, 0x00, 0x00);
+        }
+        else if (message->send_buf != RT_NULL && message->recv_buf != RT_NULL)
+        {
+            /**< send and receive message */
+            result = cyhal_spi_transfer(spi_device->spi_obj, message->send_buf, message->length, message->recv_buf, message->length, 0x00);
+        }
+    }
+
+    if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS))
+    {
+        if (device->config.mode & RT_SPI_CS_HIGH)
+            cyhal_gpio_write(cs->pin, PIN_LOW);
+        else
+            cyhal_gpio_write(cs->pin, PIN_HIGH);
+    }
+
+    return message->length;
+}
+
+rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, uint16_t cs_gpio_pin)
+{
+    RT_ASSERT(bus_name != RT_NULL);
+    RT_ASSERT(device_name != RT_NULL);
+
+    rt_err_t result;
+    struct rt_spi_device *spi_device;
+
+    /* attach the device to spi bus */
+    spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
+    RT_ASSERT(spi_device != RT_NULL);
+    struct ifx_sw_spi_cs *cs_pin = (struct ifx_sw_spi_cs *)rt_malloc(sizeof(struct ifx_sw_spi_cs));
+    RT_ASSERT(cs_pin != RT_NULL);
+
+    cs_pin->pin = cs_gpio_pin;
+
+    if (cs_pin->pin != 0x00)
+    {
+        /* initialize the cs pin & select the slave*/
+        cyhal_gpio_init(cs_pin->pin, CYHAL_GPIO_DIR_OUTPUT, CYHAL_GPIO_DRIVE_STRONG, 1);
+        cyhal_gpio_write(cs_pin->pin, PIN_HIGH);
+    }
+
+    result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
+
+    RT_ASSERT(spi_device != RT_NULL);
+
+    return result;
+}
+
+int rt_hw_spi_init(void)
+{
+    int result = RT_EOK;
+
+    for (int i = 0; i < sizeof(spi_bus_obj) / sizeof(spi_bus_obj[0]); i++)
+    {
+        spi_bus_obj[i].spi_obj = rt_malloc(sizeof(cyhal_spi_t));
+
+        RT_ASSERT(spi_bus_obj[i].spi_obj != RT_NULL);
+
+        spi_bus_obj[i].spi_bus->parent.user_data = (void *)&spi_bus_obj[i];
+
+        result = rt_spi_bus_register(spi_bus_obj[i].spi_bus, spi_bus_obj[i].bus_name, &ifx_spi_ops);
+
+        RT_ASSERT(result == RT_EOK);
+
+        LOG_D("%s bus init done", spi_bus_obj[i].bus_name);
+
+        LOG_D("MOSI PIN:[%d], MISO PIN[%d], CLK PIN[%d]\n",
+              spi_bus_obj[i].mosi_pin, spi_bus_obj[i].miso_pin,
+              spi_bus_obj[i].sck_pin);
+    }
+
+    return result;
+}
+INIT_BOARD_EXPORT(rt_hw_spi_init);
+#endif /* RT_USING_SPI */

+ 36 - 0
project_0/libraries/HAL_Drivers/drv_spi.h

@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-18     Rbb666       first version
+ */
+
+#ifndef __DRV_SPI__
+#define __DRV_SPI__
+
+#include <rtthread.h>
+#include <drivers/spi.h>
+
+#include "drv_gpio.h"
+
+#define SPI_FREQ_HZ         (10000000UL)
+
+/* gd32 spi dirver class */
+struct ifx_spi
+{
+    char *bus_name;
+    struct rt_spi_bus *spi_bus;
+    cyhal_spi_t *spi_obj;
+
+    uint16_t sck_pin;
+    uint16_t miso_pin;
+    uint16_t mosi_pin;
+    uint32_t freq;
+};
+
+rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, uint16_t cs_gpio_pin);
+
+#endif

+ 314 - 0
project_0/libraries/HAL_Drivers/drv_uart.c

@@ -0,0 +1,314 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-06-29     Rbb666       first version
+ */
+
+#include <rtthread.h>
+#include "drv_uart.h"
+
+#include "uart_config.h"
+#include "cyhal_scb_common.h"
+
+enum
+{
+#ifdef BSP_USING_UART0
+    UART0_INDEX,
+#endif
+#ifdef BSP_USING_UART1
+    UART1_INDEX,
+#endif
+#ifdef BSP_USING_UART2
+    UART2_INDEX,
+#endif
+#ifdef BSP_USING_UART3
+    UART3_INDEX,
+#endif
+#ifdef BSP_USING_UART4
+    UART4_INDEX,
+#endif
+#ifdef BSP_USING_UART5
+    UART5_INDEX,
+#endif
+#ifdef BSP_USING_UART6
+    UART6_INDEX,
+#endif
+};
+
+static struct ifx_uart_config uart_config[] =
+{
+#ifdef BSP_USING_UART0
+    UART0_CONFIG,
+#endif
+#ifdef BSP_USING_UART1
+    UART1_CONFIG,
+#endif
+#ifdef BSP_USING_UART2
+    UART2_CONFIG,
+#endif
+#ifdef BSP_USING_UART3
+    UART3_CONFIG,
+#endif
+#ifdef BSP_USING_UART4
+    UART4_CONFIG,
+#endif
+#ifdef BSP_USING_UART5
+    UART5_CONFIG,
+#endif
+#ifdef BSP_USING_UART6
+    UART6_CONFIG,
+#endif
+};
+
+static struct ifx_uart uart_obj[sizeof(uart_config) / sizeof(uart_config[0])] = {0};
+
+static void uart_isr(struct rt_serial_device *serial)
+{
+    RT_ASSERT(serial != RT_NULL);
+    struct ifx_uart *uart = (struct ifx_uart *) serial->parent.user_data;
+    RT_ASSERT(uart != RT_NULL);
+
+    if ((uart->config->usart_x->INTR_RX_MASKED & SCB_INTR_RX_MASKED_NOT_EMPTY_Msk) != 0)
+    {
+        /* Clear UART "RX fifo not empty interrupt" */
+        uart->config->usart_x->INTR_RX = uart->config->usart_x->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
+
+        rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
+    }
+}
+
+#ifdef BSP_USING_UART0
+/* UART0 Interrupt Hanlder */
+void uart0_isr_callback(void)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    uart_isr(&uart_obj[UART0_INDEX].serial);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+#endif
+#ifdef BSP_USING_UART1
+/* UART1 Interrupt Hanlder */
+void uart1_isr_callback(void)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    uart_isr(&uart_obj[UART1_INDEX].serial);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+#endif
+#ifdef BSP_USING_UART2
+/* UART2 Interrupt Hanlder */
+void uart2_isr_callback(void)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    uart_isr(&uart_obj[UART2_INDEX].serial);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+#endif
+#ifdef BSP_USING_UART3
+/* UART3 Interrupt Hanlder */
+void uart3_isr_callback(void)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    uart_isr(&uart_obj[UART3_INDEX].serial);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+#endif
+#ifdef BSP_USING_UART4
+/* UART4 Interrupt Hanlder */
+void uart4_isr_callback(void)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    uart_isr(&uart_obj[UART4_INDEX].serial);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+#endif
+#ifdef BSP_USING_UART5
+/* UART5 Interrupt Hanlder */
+void uart5_isr_callback(void)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    uart_isr(&uart_obj[UART5_INDEX].serial);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+#endif
+
+#ifdef BSP_USING_UART6
+/* UART5 Interrupt Hanlder */
+void uart6_isr_callback(void)
+{
+    /* enter interrupt */
+    rt_interrupt_enter();
+
+    uart_isr(&uart_obj[UART6_INDEX].serial);
+
+    /* leave interrupt */
+    rt_interrupt_leave();
+}
+#endif
+/*
+ * UARTHS interface
+ */
+static rt_err_t ifx_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
+{
+    RT_ASSERT(serial != RT_NULL);
+    struct ifx_uart *uart = (struct ifx_uart *) serial->parent.user_data;
+    RT_ASSERT(uart != RT_NULL);
+
+    cy_en_scb_uart_status_t result;
+
+    const cyhal_uart_cfg_t uart_config =
+    {
+        .data_bits          = 8,
+        .stop_bits          = 1,
+        .parity             = CYHAL_UART_PARITY_NONE,
+        .rx_buffer          = NULL,
+        .rx_buffer_size     = 0
+    };
+
+    /* Initialize retarget-io to use the debug UART port */
+    result = cyhal_uart_init(uart->config->uart_obj, uart->config->tx_pin, uart->config->rx_pin, NC, NC, NULL, &uart_config);
+
+    if (result == CY_RSLT_SUCCESS)
+    {
+        result = cyhal_uart_set_baud(uart->config->uart_obj, cfg->baud_rate, NULL);
+    }
+
+    RT_ASSERT(result == RT_EOK);
+
+    return RT_EOK;
+}
+
+static rt_err_t ifx_control(struct rt_serial_device *serial, int cmd, void *arg)
+{
+    RT_ASSERT(serial != RT_NULL);
+    struct ifx_uart *uart = (struct ifx_uart *) serial->parent.user_data;
+    RT_ASSERT(uart != RT_NULL);
+
+    switch (cmd)
+    {
+    case RT_DEVICE_CTRL_CLR_INT:
+
+        break;
+
+    case RT_DEVICE_CTRL_SET_INT:
+        /* Unmasking only the RX fifo not empty interrupt bit */
+        uart->config->usart_x->INTR_RX_MASK = SCB_INTR_RX_MASK_NOT_EMPTY_Msk;
+
+        /* Interrupt Settings for UART */
+        Cy_SysInt_Init(uart->config->UART_SCB_IRQ_cfg, uart->config->userIsr);
+
+        /* Enable the interrupt */
+        NVIC_EnableIRQ(uart->config->intrSrc);
+        break;
+    }
+
+    return (RT_EOK);
+}
+
+static int ifx_uarths_putc(struct rt_serial_device *serial, char c)
+{
+    RT_ASSERT(serial != RT_NULL);
+
+    struct ifx_uart *uart = (struct ifx_uart *) serial->parent.user_data;
+
+    RT_ASSERT(uart != RT_NULL);
+
+    if (_cyhal_scb_pm_transition_pending())
+        return CYHAL_SYSPM_RSLT_ERR_PM_PENDING;
+
+    uint32_t count = 0;
+
+    while (count == 0)
+    {
+        count = Cy_SCB_UART_Put(uart->config->usart_x, c);
+    }
+
+    return (1);
+}
+
+static int ifx_uarths_getc(struct rt_serial_device *serial)
+{
+    int ch;
+    rt_uint8_t read_data;
+
+    RT_ASSERT(serial != RT_NULL);
+    struct ifx_uart *uart = (struct ifx_uart *) serial->parent.user_data;
+    RT_ASSERT(uart != RT_NULL);
+
+    ch = -1;
+
+    if (RT_EOK == cyhal_uart_getc(uart->config->uart_obj, (uint8_t *)&read_data, 10))
+    {
+        ch = read_data & 0xff;
+    }
+    else
+    {
+        ch = -1;
+    }
+
+    return ch;
+}
+
+const struct rt_uart_ops _uart_ops =
+{
+    ifx_configure,
+    ifx_control,
+    ifx_uarths_putc,
+    ifx_uarths_getc,
+    RT_NULL
+};
+
+void rt_hw_uart_init(void)
+{
+    int index;
+
+    rt_size_t obj_num = sizeof(uart_obj) / sizeof(struct ifx_uart);
+    struct serial_configure serial_config = RT_SERIAL_CONFIG_DEFAULT;
+    rt_err_t result = 0;
+
+    for (index = 0; index < obj_num; index++)
+    {
+        uart_obj[index].config = &uart_config[index];
+        uart_obj[index].serial.ops = &_uart_ops;
+        uart_obj[index].serial.config = serial_config;
+
+        uart_obj[index].config->uart_obj = rt_malloc(sizeof(cyhal_uart_t));
+        RT_ASSERT(uart_obj[index].config->uart_obj != RT_NULL);
+        /* register uart device */
+        result = rt_hw_serial_register(&uart_obj[index].serial,
+                                       uart_obj[index].config->name,
+                                       RT_DEVICE_FLAG_RDWR |
+                                       RT_DEVICE_FLAG_INT_RX,
+                                       &uart_obj[index]);
+
+        RT_ASSERT(result == RT_EOK);
+    }
+}

+ 42 - 0
project_0/libraries/HAL_Drivers/drv_uart.h

@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-06-29     Rbb666       first version
+ */
+
+#ifndef __DRV_UART_H__
+#define __DRV_UART_H__
+
+#include <rthw.h>
+#include <rtdevice.h>
+
+#include "board.h"
+
+#define  uart_isr_callback(name) name##_isr_callback
+
+struct ifx_uart_config
+{
+    cyhal_uart_t *uart_obj;
+
+    const char *name;
+    rt_uint32_t tx_pin;
+    rt_uint32_t rx_pin;
+    CySCB_Type *usart_x;
+    IRQn_Type intrSrc;
+    cy_israddress userIsr;
+    cy_stc_sysint_t *UART_SCB_IRQ_cfg;
+};
+
+struct ifx_uart
+{
+    struct ifx_uart_config *config;
+    struct rt_serial_device serial;
+};
+
+void rt_hw_uart_init(void);
+
+#endif

+ 110 - 0
project_0/libraries/HAL_Drivers/drv_wdt.c

@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author            Notes
+ * 2022-07-21     Rbb666            first version
+ */
+
+#include "drv_wdt.h"
+
+#ifdef RT_USING_WDT
+
+//#define DRV_DEBUG
+#define LOG_TAG "drv.wdt"
+#include <drv_log.h>
+
+cyhal_wdt_t WDT;
+
+static struct ifx_wdt_cfg wdt_cfg =
+{
+    .name = "wdt",
+    .WDTx = &WDT,
+};
+
+static struct ifx_wdt wdt_drv;
+
+static rt_err_t wdt_init(rt_watchdog_t *wdt)
+{
+    return RT_EOK;
+}
+
+static rt_err_t wdt_control(rt_watchdog_t *wdt_device, int cmd, void *arg)
+{
+    RT_ASSERT(wdt_device != RT_NULL);
+
+    struct ifx_wdt_cfg *cfg;
+    cfg = wdt_device->parent.user_data;
+
+    rt_uint32_t timeout_ms = 0;
+
+    switch (cmd)
+    {
+        /* feed the watchdog */
+        case RT_DEVICE_CTRL_WDT_KEEPALIVE:
+            cyhal_wdt_kick(cfg->WDTx);
+            break;
+
+        /* set watchdog timeout */
+        case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
+        {
+            timeout_ms = *((rt_uint32_t *)arg) * 1000;
+
+            rt_uint32_t max_timeout_ms = cyhal_wdt_get_max_timeout_ms();
+
+            if (timeout_ms >= max_timeout_ms)
+                timeout_ms = max_timeout_ms;
+
+            /* Initialize the WDT */
+            int result = cyhal_wdt_init(cfg->WDTx, (rt_uint32_t)timeout_ms);
+            /* WDT initialization failed. Stop program execution */
+            RT_ASSERT(result == RT_EOK);
+        }
+        break;
+
+        case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
+            timeout_ms = cyhal_wdt_get_timeout_ms(cfg->WDTx);
+            *(rt_uint32_t *)arg = timeout_ms / 1000;
+            break;
+
+        case RT_DEVICE_CTRL_WDT_START:
+            cyhal_wdt_start(cfg->WDTx);
+            break;
+
+        case RT_DEVICE_CTRL_WDT_STOP:
+            cyhal_wdt_stop(cfg->WDTx);
+            break;
+
+        default:
+            LOG_W("This command is not supported.");
+            return -RT_ERROR;
+    }
+
+    return RT_EOK;
+}
+
+const static struct rt_watchdog_ops ifx_wdt_ops =
+{
+    wdt_init,
+    wdt_control
+};
+
+int rt_hw_wdt_init(void)
+{
+    wdt_drv.cfg = &wdt_cfg;
+    wdt_drv.wdt_device.ops = &ifx_wdt_ops;
+
+    if (rt_hw_watchdog_register(&wdt_drv.wdt_device, wdt_drv.cfg->name, RT_DEVICE_FLAG_RDWR, wdt_drv.cfg) != RT_EOK)
+    {
+        LOG_E("wdt device register failed.");
+        return -RT_ERROR;
+    }
+
+    LOG_D("wdt device register success.");
+    return RT_EOK;
+}
+INIT_BOARD_EXPORT(rt_hw_wdt_init);
+
+#endif /* RT_USING_WDT */

+ 31 - 0
project_0/libraries/HAL_Drivers/drv_wdt.h

@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2006-2022, Synwit Technology Co.,Ltd.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-7-21      Rbb666       first version
+ */
+
+#ifndef __DRV_WDT_H__
+#define __DRV_WDT_H__
+
+#include <rtthread.h>
+#include "board.h"
+
+struct ifx_wdt_cfg
+{
+    const char *name;
+    cyhal_wdt_t *WDTx;
+};
+
+struct ifx_wdt
+{
+    struct ifx_wdt_cfg *cfg;
+    struct rt_watchdog_device wdt_device;
+};
+
+int rt_hw_wdt_init(void);
+
+#endif /* __DRV_WDT_H__ */

+ 207 - 0
project_0/libraries/HAL_Drivers/uart_config.h

@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022-07-08     Rbb666       first version
+ */
+
+#ifndef __UART_CONFIG_H__
+#define __UART_CONFIG_H__
+
+#include <rtthread.h>
+#include "board.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#ifdef BSP_USING_UART0
+    /* UART0 device driver structure */
+    cy_stc_sysint_t UART0_SCB_IRQ_cfg =
+        {
+            .intrSrc = (IRQn_Type)scb_0_interrupt_IRQn,
+            .intrPriority = (7u),
+    };
+#endif
+#ifdef BSP_USING_UART1
+    /* UART1 device driver structure */
+    cy_stc_sysint_t UART1_SCB_IRQ_cfg =
+        {
+            .intrSrc = (IRQn_Type)scb_1_interrupt_IRQn,
+            .intrPriority = (7u),
+    };
+#endif
+#ifdef BSP_USING_UART2
+    /* UART2 device driver structure */
+    cy_stc_sysint_t UART2_SCB_IRQ_cfg =
+        {
+            .intrSrc = (IRQn_Type)scb_2_interrupt_IRQn,
+            .intrPriority = (7u),
+    };
+#endif
+#ifdef BSP_USING_UART3
+    /* UART3 device driver structure */
+    cy_stc_sysint_t UART3_SCB_IRQ_cfg =
+        {
+            .intrSrc = (IRQn_Type)scb_3_interrupt_IRQn,
+            .intrPriority = (7u),
+    };
+#endif
+#ifdef BSP_USING_UART4
+    /* UART4 device driver structure */
+    cy_stc_sysint_t UART4_SCB_IRQ_cfg =
+        {
+            .intrSrc = (IRQn_Type)scb_4_interrupt_IRQn,
+            .intrPriority = (7u),
+    };
+#endif
+#ifdef BSP_USING_UART5
+    /* UART5 device driver structure */
+    cy_stc_sysint_t UART5_SCB_IRQ_cfg =
+        {
+            .intrSrc = (IRQn_Type)scb_5_interrupt_IRQn,
+            .intrPriority = (7u),
+    };
+#endif
+
+#ifdef BSP_USING_UART6
+    /* UART6 device driver structure */
+    cy_stc_sysint_t UART6_SCB_IRQ_cfg =
+        {
+            .intrSrc = (IRQn_Type)scb_6_interrupt_IRQn,
+            .intrPriority = (7u),
+    };
+#endif
+#if defined(BSP_USING_UART0)
+#ifndef UART0_CONFIG
+#define UART0_CONFIG                            \
+    {                                           \
+        .name = "uart0",                        \
+        .tx_pin = P0_3,                         \
+        .rx_pin = P0_2,                         \
+        .usart_x = SCB0,                        \
+        .intrSrc = scb_0_interrupt_IRQn,        \
+        .userIsr = uart_isr_callback(uart0),    \
+        .UART_SCB_IRQ_cfg = &UART0_SCB_IRQ_cfg, \
+    }
+    void uart0_isr_callback(void);
+#endif /* UART0_CONFIG */
+#endif /* BSP_USING_UART0 */
+
+#if defined(BSP_USING_UART1)
+#ifndef UART1_CONFIG
+#define UART1_CONFIG                            \
+    {                                           \
+        .name = "uart1",                        \
+        .tx_pin = P10_1,                        \
+        .rx_pin = P10_0,                        \
+        .usart_x = SCB1,                        \
+        .intrSrc = scb_1_interrupt_IRQn,        \
+        .userIsr = uart_isr_callback(uart1),    \
+        .UART_SCB_IRQ_cfg = &UART1_SCB_IRQ_cfg, \
+    }
+    void uart1_isr_callback(void);
+#endif /* UART1_CONFIG */
+#endif /* BSP_USING_UART1 */
+
+#if defined(BSP_USING_UART2)
+#ifndef UART2_CONFIG
+#if defined(SOC_CY8C6244LQI_S4D92)
+#define UART2_CONFIG                            \
+    {                                           \
+        .name = "uart2",                        \
+        .tx_pin = P3_1,                         \
+        .rx_pin = P3_0,                         \
+        .usart_x = SCB2,                        \
+        .intrSrc = scb_2_interrupt_IRQn,        \
+        .userIsr = uart_isr_callback(uart2),    \
+        .UART_SCB_IRQ_cfg = &UART2_SCB_IRQ_cfg, \
+    }
+#else
+#define UART2_CONFIG                            \
+    {                                           \
+        .name = "uart2",                        \
+        .tx_pin = P9_1,                         \
+        .rx_pin = P9_0,                         \
+        .usart_x = SCB2,                        \
+        .intrSrc = scb_2_interrupt_IRQn,        \
+        .userIsr = uart_isr_callback(uart2),    \
+        .UART_SCB_IRQ_cfg = &UART2_SCB_IRQ_cfg, \
+    }
+#endif /* SOC_CY8C6244LQI_S4D92 */
+    void uart2_isr_callback(void);
+#endif /* UART2_CONFIG */
+#endif /* BSP_USING_UART2 */
+
+#if defined(BSP_USING_UART3)
+#ifndef UART3_CONFIG
+#define UART3_CONFIG                            \
+    {                                           \
+        .name = "uart3",                        \
+        .tx_pin = P6_1,                         \
+        .rx_pin = P6_0,                         \
+        .usart_x = SCB3,                        \
+        .intrSrc = scb_3_interrupt_IRQn,        \
+        .userIsr = uart_isr_callback(uart3),    \
+        .UART_SCB_IRQ_cfg = &UART3_SCB_IRQ_cfg, \
+    }
+    void uart3_isr_callback(void);
+#endif /* UART3_CONFIG */
+#endif /* BSP_USING_UART3 */
+
+#if defined(BSP_USING_UART4)
+#ifndef UART4_CONFIG
+#define UART4_CONFIG                            \
+    {                                           \
+        .name = "uart4",                        \
+        .tx_pin = P7_1,                         \
+        .rx_pin = P7_0,                         \
+        .usart_x = SCB4,                        \
+        .intrSrc = scb_4_interrupt_IRQn,        \
+        .userIsr = uart_isr_callback(uart4),    \
+        .UART_SCB_IRQ_cfg = &UART4_SCB_IRQ_cfg, \
+    }
+    void uart4_isr_callback(void);
+#endif /* UART4_CONFIG */
+#endif /* BSP_USING_UART4 */
+
+#if defined(BSP_USING_UART5)
+#ifndef UART5_CONFIG
+#define UART5_CONFIG                            \
+    {                                           \
+        .name = "uart5",                        \
+        .tx_pin = P5_1,                         \
+        .rx_pin = P5_0,                         \
+        .usart_x = SCB5,                        \
+        .intrSrc = scb_5_interrupt_IRQn,        \
+        .userIsr = uart_isr_callback(uart5),    \
+        .UART_SCB_IRQ_cfg = &UART5_SCB_IRQ_cfg, \
+    }
+    void uart5_isr_callback(void);
+#endif /* UART5_CONFIG */
+#endif /* BSP_USING_UART5 */
+
+#if defined(BSP_USING_UART6)
+#ifndef UART6_CONFIG
+#define UART6_CONFIG                            \
+    {                                           \
+        .name = "uart6",                        \
+        .tx_pin = P6_5,                         \
+        .rx_pin = P6_4,                         \
+        .usart_x = SCB6,                        \
+        .intrSrc = scb_6_interrupt_IRQn,        \
+        .userIsr = uart_isr_callback(uart6),    \
+        .UART_SCB_IRQ_cfg = &UART6_SCB_IRQ_cfg, \
+    }
+    void uart6_isr_callback(void);
+#endif /* UART6_CONFIG */
+#endif /* BSP_USING_UART6 */
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 195 - 0
project_0/libraries/IFX_PSOC6_HAL/SConscript

@@ -0,0 +1,195 @@
+from building import *
+import rtconfig
+Import('RTT_ROOT')
+
+# get current directory
+cwd = GetCurrentDir()
+src = []
+
+# The set of source files associated with this SConscript file.
+src = Split('''
+            mtb-hal-cat1/source/cyhal_clock.c
+            mtb-hal-cat1/source/cyhal_hwmgr.c
+            mtb-hal-cat1/source/cyhal_syspm.c
+            mtb-hal-cat1/source/cyhal_system.c
+            mtb-hal-cat1/source/cyhal_uart.c
+            mtb-hal-cat1/source/cyhal_gpio.c
+            mtb-hal-cat1/source/cyhal_scb_common.c
+            mtb-hal-cat1/source/cyhal_interconnect.c
+            mtb-hal-cat1/source/cyhal_utils_psoc.c
+            mtb-hal-cat1/source/cyhal_utils.c
+            mtb-hal-cat1/source/cyhal_lptimer.c
+            mtb-hal-cat1/source/cyhal_irq_psoc.c
+            mtb-pdl-cat1/drivers/source/cy_sysclk.c
+            mtb-pdl-cat1/drivers/source/cy_systick.c
+            mtb-pdl-cat1/drivers/source/cy_gpio.c
+            mtb-pdl-cat1/drivers/source/cy_sysint.c
+            mtb-pdl-cat1/drivers/source/cy_syslib.c
+            mtb-pdl-cat1/drivers/source/cy_scb_i2c.c
+            mtb-pdl-cat1/drivers/source/cy_syspm.c
+            mtb-pdl-cat1/drivers/source/cy_mcwdt.c
+            mtb-pdl-cat1/drivers/source/cy_ipc_pipe.c
+            mtb-pdl-cat1/drivers/source/cy_ipc_sema.c
+            mtb-pdl-cat1/drivers/source/cy_ipc_drv.c
+            mtb-pdl-cat1/drivers/source/cy_trigmux.c
+            mtb-pdl-cat1/drivers/source/cy_prot.c
+            mtb-pdl-cat1/drivers/source/cy_scb_common.c
+            ''')
+
+if GetDepend(['SOC_CY8C624ABZI_S2D44']):
+    src += ['mtb-pdl-cat1/devices/COMPONENT_CAT1A/source/cy_device.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_02.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_124_bga.c']
+    src += Glob('psoc6cm0p/COMPONENT_CM0P_SLEEP/*.c')
+
+if GetDepend(['SOC_CY8C6245LQI_S3D72']):
+    src += ['mtb-pdl-cat1/devices/COMPONENT_CAT1A/source/cy_device.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_03.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_03_68_qfn.c']
+    src += Glob('psoc6cm0p/COMPONENT_CM0P_SLEEP/*.c')
+
+if GetDepend(['SOC_CY8C624ALQI_S2D42']):
+    src += ['mtb-pdl-cat1/devices/COMPONENT_CAT1A/source/cy_device.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_02.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_02_68_qfn.c']
+    src += Glob('psoc6cm0p/COMPONENT_CM0P_SLEEP/*.c')
+
+if GetDepend(['SOC_CY8C6247BZI_D54']):
+    src += ['mtb-pdl-cat1/devices/COMPONENT_CAT1A/source/cy_device.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_01.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_124_bga.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_flash.c']
+    src += Glob('psoc6cm0p/COMPONENT_CM0P_SLEEP/*.c')
+
+if GetDepend(['SOC_CY8C6347BZI_BLD53']):
+    src += ['mtb-pdl-cat1/devices/COMPONENT_CAT1A/source/cy_device.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_01.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_01_116_bga_ble.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_flash.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_ble_clk.c']
+    src += Glob('psoc6cm0p/COMPONENT_CM0P_SLEEP/*.c')
+
+if GetDepend(['SOC_CY8C6244LQI_S4D92']):
+    src += ['mtb-pdl-cat1/devices/COMPONENT_CAT1A/source/cy_device.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/triggers/cyhal_triggers_psoc6_04.c']
+    src += ['mtb-hal-cat1/COMPONENT_CAT1A/source/pin_packages/cyhal_psoc6_04_68_qfn.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_flash.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_ble_clk.c']
+    src += Glob('psoc6cm0p/COMPONENT_CM0P_SLEEP/*.c')
+
+if GetDepend(['RT_USING_SERIAL']):
+    src += ['retarget-io/cy_retarget_io.c']
+    src += ['mtb-hal-cat1/source/cyhal_uart.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_scb_uart.c']
+
+if GetDepend(['RT_USING_ADC']):
+    src += ['mtb-hal-cat1/source/cyhal_dma_dw.c']
+    src += ['mtb-hal-cat1/source/cyhal_dma_dmac.c']
+    src += ['mtb-hal-cat1/source/cyhal_dma.c']
+    src += ['mtb-hal-cat1/source/cyhal_adc_sar.c']
+    src += ['mtb-hal-cat1/source/cyhal_analog_common.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_dma.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_sar.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_dmac.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_sysanalog.c']
+
+if GetDepend(['RT_USING_SDIO']):
+    src += ['mtb-hal-cat1/source/cyhal_sdhc.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_sd_host.c']
+
+if GetDepend(['RT_USING_PWM']):
+    src += ['mtb-hal-cat1/source/cyhal_pwm.c']
+    src += ['mtb-hal-cat1/source/cyhal_timer.c']
+    src += ['mtb-hal-cat1/source/cyhal_tcpwm_common.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_tcpwm_pwm.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_tcpwm_counter.c']
+
+if GetDepend(['RT_USING_SPI']):
+    src += ['mtb-hal-cat1/source/cyhal_spi.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_scb_spi.c']
+
+if GetDepend(['RT_USING_I2C']):
+    src += ['mtb-hal-cat1/source/cyhal_i2c.c']
+
+if GetDepend('BSP_USING_RTC'):
+    src += ['mtb-hal-cat1/source/cyhal_rtc.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_rtc.c']
+
+if GetDepend('BSP_USING_ON_CHIP_FLASH'):
+    src += ['mtb-hal-cat1/source/cyhal_flash.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_flash.c']
+
+if GetDepend(['BSP_USING_SLIDER']):
+    src += ['capsense/cy_capsense_control.c']
+    src += ['capsense/cy_capsense_sensing.c']
+    src += ['capsense/cy_capsense_sensing_v2.c']
+    src += ['capsense/cy_capsense_csx_v2.c']
+    src += ['capsense/cy_capsense_csd_v2.c']
+    src += ['capsense/cy_capsense_processing.c']
+    src += ['capsense/cy_capsense_tuner.c']
+    src += ['capsense/cy_capsense_structure.c']
+    src += ['capsense/cy_capsense_centroid.c']
+    src += ['capsense/cy_capsense_filter.c']
+    src += ['mtb-pdl-cat1/drivers/source/cy_csd.c']
+    if rtconfig.PLATFORM in ['armclang']:
+        src += ['lib/cy_capsense.lib']
+
+if GetDepend(['RT_USING_WDT']):
+    src += ['mtb-pdl-cat1/drivers/source/cy_wdt.c']
+    src += ['mtb-hal-cat1/source/cyhal_wdt.c']
+
+if GetDepend(['RT_USING_DAC']):
+    src += ['mtb_shared/csdidac/cy_csdidac.c']
+
+if GetDepend(['RT_USING_HWTIMER']):
+    src += ['mtb-hal-cat1/source/cyhal_timer.c']
+
+path = [cwd + '/retarget-io',
+        cwd + '/core-lib/include',
+        cwd + '/mtb_shared/usbdev',
+        cwd + '/mtb_shared/csdidac',
+        cwd + '/mtb_shared/serial-flash',
+        cwd + '/mtb-pdl-cat1/cmsis/include',
+        cwd + '/mtb-pdl-cat1/drivers/include',
+        cwd + '/mtb-hal-cat1/include_pvt',
+        cwd + '/mtb-hal-cat1/include']
+
+if GetDepend(['SOC_CY8C624ABZI_S2D44']):
+    path += [cwd + '/psoc6cm0p']
+    path += [cwd + '/capsense']
+    path += [cwd + '/mtb-hal-cat1/COMPONENT_CAT1A/include']
+    path += [cwd + '/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include']
+
+if GetDepend(['SOC_CY8C6245LQI_S3D72']):
+    path += [cwd + '/psoc6cm0p']
+    path += [cwd + '/capsense']
+    path += [cwd + '/mtb-hal-cat1/COMPONENT_CAT1A/include']
+    path += [cwd + '/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include']
+
+if GetDepend(['SOC_CY8C624ALQI_S2D42']):
+    path += [cwd + '/psoc6cm0p']
+    path += [cwd + '/capsense']
+    path += [cwd + '/mtb-hal-cat1/COMPONENT_CAT1A/include']
+    path += [cwd + '/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include']
+
+if GetDepend(['SOC_CY8C6247BZI_D54']):
+    path += [cwd + '/psoc6cm0p']
+    path += [cwd + '/capsense']
+    path += [cwd + '/mtb-hal-cat1/COMPONENT_CAT1A/include']
+    path += [cwd + '/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include']
+
+if GetDepend(['SOC_CY8C6347BZI_BLD53']):
+    path += [cwd + '/psoc6cm0p']
+    path += [cwd + '/capsense']
+    path += [cwd + '/mtb-hal-cat1/COMPONENT_CAT1A/include']
+    path += [cwd + '/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include']
+
+if GetDepend(['SOC_CY8C6244LQI_S4D92']):
+    path += [cwd + '/psoc6cm0p']
+    path += [cwd + '/capsense']
+    path += [cwd + '/mtb-hal-cat1/COMPONENT_CAT1A/include']
+    path += [cwd + '/mtb-pdl-cat1/devices/COMPONENT_CAT1A/include']
+
+group = DefineGroup('Libraries', src, depend=[''], CPPPATH=path)
+
+Return('group')

+ 1 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/.gitignore

@@ -0,0 +1 @@
+docs

BIN
project_0/libraries/IFX_PSOC6_HAL/capsense/COMPONENT_HARDFP/TOOLCHAIN_ARM/libcy_capsense.ar


BIN
project_0/libraries/IFX_PSOC6_HAL/capsense/COMPONENT_SOFTFP/TOOLCHAIN_ARM/libcy_capsense.ar


+ 55 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/LICENSE

@@ -0,0 +1,55 @@
+CYPRESS™ END USER LICENSE AGREEMENT
+
+PLEASE READ THIS END USER LICENSE AGREEMENT ("Agreement") CAREFULLY BEFORE DOWNLOADING, INSTALLING, COPYING, OR USING THIS SOFTWARE AND ACCOMPANYING DOCUMENTATION.  BY DOWNLOADING, INSTALLING, COPYING OR USING THE SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THIS AGREEMENT.  IF YOU DO NOT AGREE TO ALL OF THE TERMS OF THIS AGREEMENT, PROMPTLY RETURN AND DO NOT USE THE SOFTWARE.  IF YOU HAVE PURCHASED THIS LICENSE TO THE SOFTWARE, YOUR RIGHT TO RETURN THE SOFTWARE EXPIRES 30 DAYS AFTER YOUR PURCHASE AND APPLIES ONLY TO THE ORIGINAL PURCHASER.
+
+1. Definitions.
+
+	"Software" means this software and any accompanying documentation, including any upgrades, updates, bug fixes or modified versions provided to you by CYPRESS™ .
+	
+	"Source Code" means software in human-readable form.
+	
+	"Binary Code" means the software in binary code form such as object code or an executable.
+	
+	"Development Tools" means software that is intended to be installed on a personal computer and used to create programming code for Firmware, Drivers, or Host Applications.  Examples of Development Tools are CYPRESS™ PSoC™ Creator software, CYPRESS™'s WICED™ SDKs, and CYPRESS™'s ModusToolbox™ software.
+	
+	"Firmware" means software that executes on a CYPRESS™ hardware product from Infineon.
+	
+	"Driver" means software that enables the use of a CYPRESS™ hardware product from Infineon on a particular host operating system such as GNU/Linux, Windows, MacOS, Android, and iOS.
+	
+	"Host Application" means software that executes on a device other than a CYPRESS™ hardware product in order to program, control, or communicate with a CYPRESS™ hardware product from Infineon.
+	
+	"inf File" means a hardware setup information file (.inf file) created by the Software to allow a Microsoft Windows operating system to install the driver for a CYPRESS™ hardware product from Infineon.
+
+2. License.  Subject to the terms and conditions of this Agreement, Cypress Semiconductor Corporation (an Infineon company) ("CYPRESS™") and its suppliers grant to you a non-exclusive, non-transferable license under their copyright rights:
+
+	a. to use the Development Tools in object code form solely for the purpose of creating Firmware, Drivers, Host Applications, and inf Files for CYPRESS™ hardware products from Infineon; and
+	
+	b. (i) if provided in Source Code form, to copy, modify, and compile the Firmware Source Code to create Firmware for execution on a CYPRESS™ hardware product from Infineon, and (ii) to distribute Firmware in binary code form only, only when installed onto a CYPRESS™ hardware product from Infineon; and
+	
+	c. (i) if provided in Source Code form, to copy, modify, and compile the Driver Source Code to create one or more Drivers to enable the use of a CYPRESS™ hardware product from Infineon on a particular host operating system, and (ii) to distribute the Driver, in binary code form only, only when installed on a device that includes the CYPRESS™ hardware product from Infineon that the Driver is intended to enable; and
+	
+	d. (i) if provided in Source Code form, to copy, modify, and compile the Host Application Source Code to create one or more Host Applications to program, control, or communicate with a CYPRESS™ hardware product, and (ii) to distribute Host Applications, in binary code form only, only when installed on a device that includes a CYPRESS™ hardware product from Infineon that the Host Application is intended to program, control, or communicate with; and
+	
+	e. to freely distribute any inf File.
+
+Any distribution of Software permitted under this Agreement must be made pursuant to your standard end user license agreement used for your proprietary (closed source) software products, such end user license agreement to include, at a minimum, provisions limiting your licensors' liability and prohibiting reverse engineering of the Software, consistent with such provisions in this Agreement.
+
+3. Free and Open Source Software.  Portions of the Software may be licensed under free and/or open source licenses such as the GNU General Public License or other licenses from third parties ("Third Party Software").  Third Party Software is subject to the applicable license agreement and not this Agreement.  If you are entitled to receive the source code from CYPRESS™ for any Third Party Software included with the Software, either the source code will  be included with the Software or you may obtain the source code at no charge from <http://www.cypress.com/go/opensource>.  The applicable license terms will accompany each source code package.  To review the license terms applicable to any Third Party Software for which CYPRESS™ is not required to provide you with source code, please see the Software's installation directory on your computer.
+
+4. Proprietary Rights; Ownership.  The Software, including all intellectual property rights therein, is and will remain the sole and exclusive property of CYPRESS™ or its suppliers.  CYPRESS™ retains ownership of the Source Code and any compiled version thereof.  Subject to CYPRESS™ ownership of the underlying Software (including Source Code), you retain ownership of any modifications you make to the Source Code.  You agree not to remove any CYPRESS™ copyright or other notices from the Source Code and any modifications thereof.  You agree to keep the Source Code confidential.  Any reproduction, modification, translation, compilation, or representation of the Source Code except as permitted in Section 2 ("License") is prohibited without the express written permission of CYPRESS™.  Except as otherwise expressly provided in this Agreement, you may not: (i) modify, adapt, or create derivative works based upon the Software; (ii) copy the Software; (iii) except and only to the extent explicitly permitted by applicable law despite this limitation, decompile, translate, reverse engineer, disassemble or otherwise reduce the Software to human-readable form; or (iv) use the Software or any sample code other than for the Purpose.  You hereby covenant that you will not assert any claim that the Software, or derivative works thereof created by or for CYPRESS™, infringe any intellectual property right owned or controlled by you
+
+5. No Support.  CYPRESS™ may, but is not required to, provide technical support for the Software.
+
+6. Term and Termination.  This Agreement is effective until terminated, and either party may terminate this Agreement at any time with or without cause.  This Agreement and your license rights under this Agreement will terminate immediately without notice from CYPRESS™ if you fail to comply with any provision of this Agreement.  Upon termination, you must destroy all copies of Software in your possession or control.  The following paragraphs shall survive any termination of this Agreement: "Free and Open Source Software," "Proprietary Rights; Ownership," "Compliance With Law," "Disclaimer," "Limitation of Liability," and "General."
+
+7. Compliance With Law.  Each party agrees to comply with all applicable laws, rules and regulations in connection with its activities under this Agreement.  Without limiting the foregoing, the Software may be subject to export control laws and regulations of the United States and other countries.  You agree to comply strictly with all such laws and regulations and acknowledge that you have the responsibility to obtain licenses to export, re-export, or import the Software.
+
+8. Disclaimer.  TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, CYPRESS™ MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THE SOFTWARE, INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. CYPRESS™ reserves the right to make changes to the Software without notice. CYPRESS™ does not assume any liability arising out of the application or use of Software or any product or circuit described in the Software.  It is the responsibility of the user of the Software to properly design, program, and test the functionality and safety of any application made of the Software and any resulting product.  CYPRESS™ does not authorize its Software or products for use in any products where a malfunction or failure of the Software or CYPRESS™ product may reasonably be expected to result in significant property damage, injury or death (“High Risk Product”).  If you include any Software or CYPRESS™ product in a High Risk Product, you assume all risk of such use and agree to indemnify CYPRESS™ and its suppliers against all liability.  No computing device can be absolutely secure.  Therefore, despite security measures implemented in CYPRESS™ hardware or software products, CYPRESS™ does not assume any liability arising out of any security breach, such as unauthorized access to or use of a CYPRESS™ product.
+
+9. Limitation of Liability.  TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT WILL CYPRESS™ OR ITS SUPPLIERS, RESELLERS, OR DISTRIBUTORS BE LIABLE FOR ANY LOST REVENUE, PROFIT, OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR PUNITIVE DAMAGES HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF OR RELATED TO THE USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF CYPRESS OR ITS SUPPLIERS, RESELLERS, OR DISTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.  IN NO EVENT SHALL CYPRESS' OR ITS SUPPLIERS’, RESELLERS’, OR DISTRIBUTORS’ TOTAL LIABILITY TO YOU, WHETHER IN CONTRACT, TORT (INCLUDING NEGLIGENCE), OR OTHERWISE, EXCEED THE GREATER OF US$500 OR THE PRICE PAID BY YOU FOR THE SOFTWARE.  THE FOREGOING LIMITATIONS SHALL APPLY EVEN IF THE ABOVE-STATED WARRANTY FAILS OF ITS ESSENTIAL PURPOSE.  BECAUSE SOME STATES OR JURISDICTIONS DO NOT ALLOW LIMITATION OR EXCLUSION OF CONSEQUENTIAL OR INCIDENTAL DAMAGES, ALL OR PORTIONS OF THE ABOVE LIMITATION MAY NOT APPLY TO YOU.
+
+10. Restricted Rights.  The Software is commercial computer software as that term is described in 48 C.F.R. 252.227-7014(a)(1).  If the Software is being acquired by or on behalf of the U.S. Government or by a U.S. Government prime contractor or subcontractor (at any tier), then the Government's rights in Software shall be only those set forth in this Agreement.
+
+11. Personal Information.  You agree that information you provide through your registration on CYPRESS™ IoT Community Forum or other CYPRESS™ websites, including contact information or other personal information, may be collected and used by CYPRESS™ consistent with its Data Privacy Policy (www.cypress.com/privacy-policy), as updated or revised from time to time, and may be provided to its third party sales representatives, distributors and other entities conducting sales activities for CYPRESS™ for sales-related and other business purposes.
+
+12. General.  This Agreement will bind and inure to the benefit of each party’s successors and assigns, provided that you may not assign or transfer this Agreement, in whole or in part, without CYPRESS™' written consent.  This Agreement shall be governed by and construed in accordance with the laws of the State of California, United States of America, as if performed wholly within the state and without giving effect to the principles of conflict of law.  The parties consent to personal and exclusive jurisdiction of and venue in, the state and federal courts within Santa Clara County, California; provided however, that nothing in this Agreement will limit CYPRESS™' right to bring legal action in any venue in order to protect or enforce its intellectual property rights.  No failure of either party to exercise or enforce any of its rights under this Agreement will act as a waiver of such rights.  If any portion of this Agreement is found to be void or unenforceable, the remaining provisions of this Agreement shall remain in full force and effect.  This Agreement is the complete and exclusive agreement between the parties with respect to the subject matter hereof, superseding and replacing any and all prior agreements, communications, and understandings (both written and oral) regarding such subject matter.  Any notice to CYPRESS™ will be deemed effective when actually received and must be sent to Cypress Semiconductor Corporation, ATTN: Chief Legal Officer, 198 Champion Court, San Jose, CA 95134 USA.

+ 62 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/README.md

@@ -0,0 +1,62 @@
+# CAPSENSE™ Middleware Library
+
+### Overview
+CAPSENSE™ is a CYPRESS™ capacitive sensing solution from Infineon. Capacitive sensing can be used in a variety of applications and products where conventional mechanical buttons can be replaced with sleek human interfaces to transform the way users interact with electronic systems. These include home appliances, automotive, IoT, and industrial applications. CAPSENSE™ supports multiple interfaces (widgets) using both Self-Capacitance (CSD) and Mutual-Capacitance (CSX) sensing methods with robust performance.
+
+CAPSENSE™ has become a popular technology to replace conventional mechanical- and optical-based user interfaces. There are fewer parts involved, which saves cost and increases reliability with no wear-and-tear. The main advantages of CAPSENSE™ compared with other solutions are: robust performance in harsh environmental conditions and rejection of a wide range of external noise sources.
+
+Use CAPSENSE™ for:
+* Touch and gesture detection for various interfaces
+* Proximity detection for innovative user experiences and low-power optimization
+* Contactless liquid-level sensing in a variety of applications
+* Touch-free operations in hazardous materials
+
+### Features
+* Offers best-in-class signal-to-noise ratio (SNR)
+* Supports Self-Capacitance (CSD) and Mutual-Capacitance (CSX) sensing methods
+* Features smart sensing algorithm auto-tuning technology for CSD sensing to avoid complex manual tuning process
+* Supports various Widgets, such as Buttons, Matrix Buttons, Sliders, Touchpads, and Proximity Sensors
+* Provides ultra-low power consumption and liquid-tolerant capacitive sensing technology
+* Contains the integrated graphical CAPSENSE™ Tuner tool for real-time tuning, testing, and debugging
+* Provides superior immunity against external noise and low-radiated emission
+* Offers best-in-class liquid tolerance
+* Supports one-finger and two-finger gestures
+
+### Quick Start
+The [ModusToolbox™ CAPSENSE™ Configurator Tool Guide](https://www.cypress.com/ModusToolboxCapSenseConfig) describes step-by-step instructions how to configure and launch CAPSENSE™ in [ModusToolbox™](https://www.cypress.com/products/modustoolbox-software-environment). The CAPSENSE™ Configurator Tool can be launched in ModusToolbox™ IDE from the CSD personality, as well as in stand-alone mode. Refer to [ModusToolbox™ Software Environment, Quick Start Guide, Documentation, and Videos](https://www.cypress.com/products/modustoolbox-software-environment).
+
+The quickest way to get started with CAPSENSE™ is using code examples. Infineon Technologies continuously extends their portfolio of code examples at the <a href="http:/\/www.infineon.com"><b>Infineon Technologies</b></a> and at the <a href="https:/\/github.com/Infineon"><b> Infineon Technologies GitHub</b></a>.
+
+### More information
+The following resources contain more information:
+* CAPSENSE™ Overview:
+  * [CAPSENSE™ Middleware RELEASE.md](./RELEASE.md)
+  * [CAPSENSE™ Middleware API Reference Guide](https://cypresssemiconductorco.github.io/capsense/capsense_api_reference_manual/html/index.html)
+  * [ModusToolbox™ CAPSENSE™ Configurator Tool Guide](https://www.cypress.com/ModusToolboxCapSenseConfig)
+  * [ModusToolbox™ CAPSENSE™ Tuner Tool Guide](https://www.cypress.com/ModusToolboxCapSenseTuner)
+  * [CAPSENSE™ Design Guide](https://www.cypress.com/documentation/application-notes/an85951-psoc-4-and-psoc-6-mcu-capsense-design-guide)
+  * [CSDADC Middleware API Reference Guide](https://cypresssemiconductorco.github.io/csdadc/csdadc_api_reference_manual/html/index.html)
+  * [CSDIDAC Middleware API Reference Guide](https://cypresssemiconductorco.github.io/csdidac/csdidac_api_reference_manual/html/index.html)
+* ModusToolbox™ Overview:
+  * [ModusToolbox™ Software Environment, Quick Start Guide, Documentation, and Videos](https://www.cypress.com/products/modustoolbox-software-environment)
+  * [ModusToolbox™ Device Configurator Tool Guide](https://www.cypress.com/ModusToolboxDeviceConfig)
+* Infineon Technologies Kits and Code Examples:
+  * [CAPSENSE™ Middleware Code Example for MBED OS](https://github.com/cypresssemiconductorco/mbed-os-example-capsense)
+  * [CAPSENSE™ Middleware Code Example for FreeRTOS](https://www.cypress.com/documentation/code-examples/ce218136-psoc-6-mcu-e-ink-display-capsense-rtos)
+  * [CY8CKIT-145-40XX PSoC™ 4000S CAPSENSE™ Prototyping Kit](https://www.cypress.com/documentation/development-kitsboards/cy8ckit-145-40xx-psoc-4000s-capsense-prototyping-kit)
+  * [CY8CKIT-149 PSoC™ 4100S Plus Prototyping Kit](https://www.cypress.com/documentation/development-kitsboards/cy8ckit-149-psoc-4100s-plus-prototyping-kit)
+  * [CY8CKIT-041-40XX PSoC™ 4 S-Series Pioneer Kit](https://www.cypress.com/documentation/development-kitsboards/cy8ckit-041-psoc-4-s-series-pioneer-kit)
+  * [CY8CKIT-041-41XX PSoC™ 4100S CAPSENSE™ Pioneer Kit](https://www.cypress.com/documentation/development-kitsboards/cy8ckit-041-41xx-psoc-4100s-capsense-pioneer-kit)
+* General Information:
+  * [AN210781 Getting Started with PSoC™ 6 MCU with Bluetooth Low Energy (BLE) Connectivity](http://www.cypress.com/an210781)
+  * [PSoC™ 6 Technical Reference Manual](https://www.cypress.com/documentation/technical-reference-manuals/psoc-6-mcu-psoc-63-ble-architecture-technical-reference)
+  * [PSoC™ 63 with BLE Datasheet Programmable System-on-Chip datasheet](http://www.cypress.com/ds218787)
+  * [CAT1 PDL API Reference](https://cypresssemiconductorco.github.io/mtb-pdl-cat1/pdl_api_reference_manual/html/index.html)
+  * [CAT2 PDL API Reference](https://cypresssemiconductorco.github.io/mtb-pdl-cat2/pdl_api_reference_manual/html/index.html)
+  * [PSoC™ 4000S Family: PSoC™ 4 Architecture Technical Reference Manual (TRM)](https://www.cypress.com/documentation/technical-reference-manuals/psoc-4000s-family-psoc-4-architecture-technical-reference)
+  * [PSoC™ 4100S and PSoC™ 4100S Plus: PSoC™ 4 Architecture Technical Reference Manual (TRM)](https://www.cypress.com/documentation/technical-reference-manuals/psoc-4100s-and-psoc-4100s-plus-psoc-4-architecture)
+  * [Infineon Technologies GitHub](https://github.com/Infineon)
+  * [Infineon Technologies](http://www.infineon.com)
+
+---
+CYPRESS™ Semiconductor Corporation, 2019-2021.

+ 66 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/RELEASE.md

@@ -0,0 +1,66 @@
+# CAPSENSE™ Middleware Library 3.0
+
+### What's Included?
+Please refer to the [README.md](./README.md) and the [API Reference Guide](https://cypresssemiconductorco.github.io/capsense/capsense_api_reference_manual/html/index.html) for a complete description of the CAPSENSE™ Middleware.
+The revision history of the CAPSENSE™ Middleware is also available on the [API Reference Guide Changelog](https://cypresssemiconductorco.github.io/capsense/capsense_api_reference_manual/html/index.html#section_capsense_changelog).
+New important things in this release:
+* Added CAPSENSE™ fifth-generation device support
+* Added flash memory optimization
+
+
+### Known Issues
+Refer to the [API Reference Guide - Errata section](https://cypresssemiconductorco.github.io/capsense/capsense_api_reference_manual/html/index.html#section_capsense_errata) for a complete description of the known issues and possible workarounds
+
+### Supported 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.4     |
+| - ModusToolbox™ Device Configurator                                                               | 3.10    |
+| - ModusToolbox™ MSC Superblock Personality for for PSoC™ 4 devices in the Device Configurator     | 1.0     |
+| - ModusToolbox™ MSC Personality for PSoC™ 4 devices in Device Configurator                        | 1.1     |
+| - ModusToolbox™ CSD Personality for PSoC™ 4 devices in Device Configurator                        | 1.1     |
+| - ModusToolbox™ CSD Personality for PSoC™ 6 devices in Device Configurator                        | 2.0     |
+| - ModusToolbox™ CAPSENSE™ Configurator / Tuner tools                                              | 4.0     |
+| CAT1 Peripheral Driver Library (PDL)                                                              | 2.3.0   |
+| CAT2 Peripheral Driver Library (PDL)                                                              | 1.4.0   |
+| GCC Compiler                                                                                      | 9.3.1   |
+| IAR Compiler                                                                                      | 8.42.1  |
+| ARM Compiler 6                                                                                    | 6.13    |
+| MBED OS                                                                                           | 5.15.8  |
+| FreeRTOS                                                                                          | 10.4.5  |
+
+### More information
+The following resources contain more information:
+* CAPSENSE™ Overview:
+  * [CAPSENSE™ Middleware RELEASE.md](./RELEASE.md)
+  * [CAPSENSE™ Middleware API Reference Guide](https://cypresssemiconductorco.github.io/capsense/capsense_api_reference_manual/html/index.html)
+  * [ModusToolbox™ CAPSENSE™ Configurator Tool Guide](https://www.cypress.com/ModusToolboxCapSenseConfig)
+  * [ModusToolbox™ CAPSENSE™ Tuner Tool Guide](https://www.cypress.com/ModusToolboxCapSenseTuner)
+  * [CAPSENSE™ Design Guide](https://www.cypress.com/documentation/application-notes/an85951-psoc-4-and-psoc-6-mcu-capsense-design-guide)
+  * [CSDADC Middleware API Reference Guide](https://cypresssemiconductorco.github.io/csdadc/csdadc_api_reference_manual/html/index.html)
+  * [CSDIDAC Middleware API Reference Guide](https://cypresssemiconductorco.github.io/csdidac/csdidac_api_reference_manual/html/index.html)
+* ModusToolbox™ Overview:
+  * [ModusToolbox™ Software Environment, Quick Start Guide, Documentation, and Videos](https://www.cypress.com/products/modustoolbox-software-environment)
+  * [ModusToolbox™ Device Configurator Tool Guide](https://www.cypress.com/ModusToolboxDeviceConfig)
+* Infineon Technologies Kits and Code Examples:
+  * [CAPSENSE™ Middleware Code Example for MBED OS](https://github.com/cypresssemiconductorco/mbed-os-example-capsense)
+  * [CAPSENSE™ Middleware Code Example for FreeRTOS](https://www.cypress.com/documentation/code-examples/ce218136-psoc-6-mcu-e-ink-display-capsense-rtos)
+  * [CY8CKIT-145-40XX PSoC™ 4000S CAPSENSE™ Prototyping Kit](https://www.cypress.com/documentation/development-kitsboards/cy8ckit-145-40xx-psoc-4000s-capsense-prototyping-kit)
+  * [CY8CKIT-149 PSoC™ 4100S Plus Prototyping Kit](https://www.cypress.com/documentation/development-kitsboards/cy8ckit-149-psoc-4100s-plus-prototyping-kit)
+  * [CY8CKIT-041-40XX PSoC™ 4 S-Series Pioneer Kit](https://www.cypress.com/documentation/development-kitsboards/cy8ckit-041-psoc-4-s-series-pioneer-kit)
+  * [CY8CKIT-041-41XX PSoC™ 4100S CAPSENSE™ Pioneer Kit](https://www.cypress.com/documentation/development-kitsboards/cy8ckit-041-41xx-psoc-4100s-capsense-pioneer-kit)
+* General Information:
+  * [AN210781 Getting Started with PSoC™ 6 MCU with Bluetooth Low Energy (BLE) Connectivity](http://www.cypress.com/an210781)
+  * [PSoC™ 6 Technical Reference Manual](https://www.cypress.com/documentation/technical-reference-manuals/psoc-6-mcu-psoc-63-ble-architecture-technical-reference)
+  * [PSoC™ 63 with BLE Datasheet Programmable System-on-Chip datasheet](http://www.cypress.com/ds218787)
+  * [CAT1 PDL API Reference](https://cypresssemiconductorco.github.io/mtb-pdl-cat1/pdl_api_reference_manual/html/index.html)
+  * [CAT2 PDL API Reference](https://cypresssemiconductorco.github.io/mtb-pdl-cat2/pdl_api_reference_manual/html/index.html)
+  * [PSoC™ 4000S Family: PSoC™ 4 Architecture Technical Reference Manual (TRM)](https://www.cypress.com/documentation/technical-reference-manuals/psoc-4000s-family-psoc-4-architecture-technical-reference)
+  * [PSoC™ 4100S and PSoC™ 4100S Plus: PSoC™ 4 Architecture Technical Reference Manual (TRM)](https://www.cypress.com/documentation/technical-reference-manuals/psoc-4100s-and-psoc-4100s-plus-psoc-4-architecture)
+  * [Infineon Technologies GitHub](https://github.com/Infineon)
+  * [Infineon Technologies](http://www.infineon.com)
+
+---
+CYPRESS™ Semiconductor Corporation, 2019-2021.

+ 1229 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense.h

@@ -0,0 +1,1229 @@
+/***************************************************************************//**
+* \file cy_capsense.h
+* \version 3.0
+*
+* \brief
+* This file includes all the header files of the CAPSENSE&trade; middleware.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+/**
+********************************************************************************
+* \mainpage CAPSENSE&trade; Middleware Library 3.0
+********************************************************************************
+*
+* CAPSENSE&trade; is a CYPRESS&trade; capacitive sensing solution from Infineon.
+* Capacitive sensing can be used in a variety of applications and products where
+* conventional mechanical buttons can be replaced with sleek human interfaces to
+* transform the way users interact with electronic systems. These include home
+* appliances, and automotive, IoT, and industrial applications. CAPSENSE&trade;
+* supports multiple interfaces (widgets) using both CSX and CSD sensing methods
+* with robust performance.
+*
+* CAPSENSE&trade; has become a popular technology to replace conventional
+* mechanical- and optical-based user interfaces. There are fewer parts
+* involved, which saves cost and increases reliability with no wear-and-tear.
+* The main advantages of CAPSENSE&trade; compared with other solutions are:
+* robust performance in harsh environmental conditions and rejection of a
+* wide range of external noise sources.
+*
+* Use CAPSENSE&trade; for:
+* * Touch and gesture detection for various interfaces
+* * Proximity detection for innovative user experiences and low-power
+*   optimization
+* * Contactless liquid-level sensing in a variety of applications
+* * Touch-free operations in hazardous materials
+*
+********************************************************************************
+* \section section_capsense_general General Description
+********************************************************************************
+*
+* The CAPSENSE&trade; middleware Library supports operation with fourth-generation and
+* fifth-generation of CAPSENSE&trade; HW. CAPSENSE&trade; HW enables multiple sensing
+* capabilities on PSoC&trade; devices including the self-cap (CSD) and mutual-cap (CSX)
+* capacitive touch sensing solutions, inductive sensing, impedance measurement, and
+* other features.
+*
+* Middleware access available the CAPSENSE&trade; HW block through the corresponding
+* peripheral Driver:
+*  - CSD (CAPSENSE&trade; Sigma-Delta) driver for the forth-generation of the
+*    CAPSENSE&trade; HW;
+*  - MSC (Multi-Sensor Converter) driver for the fifth-generation of the
+*    CAPSENSE&trade; HW;
+*
+* The CAPSENSE&trade; peripheral driver does not provide any system-level functions.
+* It only implements the interface to the CAPSENSE&trade; HW resource.
+*
+* The supported CAPSENSE&trade; HW blocks can perform only one function at a time.
+* However, all supported functionality (like CAPSENSE&trade;, CSDADC, etc.) can be
+* time-multiplexed in a design. I.e. you can save the existing state of
+* the CAPSENSE&trade; middleware, restore the state of the the CSDADC middleware, perform
+* CSDADC measurements, and then switch back to the CAPSENSE&trade; functionality.
+* For details and code examples, refer to the description of the
+* Cy_CapSense_Save() and Cy_CapSense_Restore() functions.
+*
+* \image html capsense_solution.png "CAPSENSE&trade; Solution" width=800px
+* \image latex capsense_solution.png
+*
+* This section describes only the CAPSENSE&trade; middleware. Refer to the corresponding
+* sections of documentation for other middleware supported by the CAPSENSE&trade; HW.
+*
+* A CAPSENSE&trade; solution includes:
+* * The CAPSENSE&trade; Configurator to create
+*   and configure CAPSENSE&trade; widgets. It can be launched in ModusToolbox&trade;
+*   from the CAPSENSE&trade; superblock personality and in Stand-alone mode.
+*   It contains a separate document about how to create and
+*   configure widgets, parameters and algorithm descriptions.
+* * API to control the design from the application program. This documentation
+*   describes API with code snippets of how to use them.
+* * The CAPSENSE&trade; Tuner tool for real-time tuning, testing, and debugging,
+*   for easy and smooth designing of human interfaces on customer products.
+*   The Tuner tool communicates with a device through a HW bridge and
+*   communication drivers (EzI2C, UART, etc.) and allows to monitor
+*   widget statuses, sensor signals, detected touch positions, gestures, etc.
+* The application program does not need to interact with the CSD driver
+* and/or other drivers such as GPIO, SysClk directly. All of that is
+* configured and managed by middleware.
+*
+* Include cy_capsense.h to get access to all functions and other declarations
+* in this library. If you are using the ModusToolbox&trade; CAPSENSE&trade; Configurator tool,
+* you can include cycfg_capsense.h only.
+*
+* \subsection subsection_capsense_features Features
+*
+* * Offers best-in-class signal-to-noise ratio (SNR)
+* * Supports Self-Capacitance (CSD) and Mutual-Capacitance (CSX)
+*   sensing methods
+* * Supports various Widgets, such as Buttons, Matrix Buttons, Sliders,
+*   Touchpads, and Proximity Sensors
+* * Provides ultra-low power consumption and liquid-tolerant capacitive
+*   sensing technology
+* * Contains the integrated graphical CAPSENSE&trade; Tuner tool for real-time tuning,
+*   testing, and debugging
+* * Provides superior immunity against external noise and low-radiated
+*   emission
+* * Offers best-in-class liquid tolerance
+* * Supports one-finger and two-finger gestures
+*
+********************************************************************************
+* \section group_capsense_quick_start Quick Start Guide
+********************************************************************************
+*
+* The quickest way to get started with CAPSENSE&trade; is using code examples.
+* Infineon Technologies continuously extends their portfolio of code examples
+* at the <a href="http:/\/www.infineon.com"><b>Infineon Technologies</b></a>
+* and at the <a href="https:/\/github.com/Infineon">
+* <b> Infineon Technologies GitHub</b></a>. The following are the links
+* to code examples for different PSoC&trade; families presented on GitHub.
+*
+* \subsection group_capsense_quick_start_psoc4_csd_ces Code Examples for PSoC&trade; 4 Devices with fourth-generation CAPSENSE&trade;
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc4-capsense-csd-button-tuning">
+*   <b>CSD Button Manual Tuning</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc4-capsense-csx-button-tuning">
+*   <b>CSX Button Manual Tuning</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc4-capsense-csd-slider-tuning">
+*   <b>CSD Slider Manual Tuning</b></a>
+*
+* \subsection group_capsense_quick_start_psoc4_msc_ces Code Examples for PSoC&trade; 4 Devices with fifth-generation CAPSENSE&trade;
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc4-msc-capsense-csd-button-tuning">
+*   <b>CSD Button Manual Tuning</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc4-msc-capsense-csx-button-tuning">
+*   <b>CSX Button Manual Tuning</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc4-msc-capsense--csd-slider-tuning">
+*   <b>CSD Slider Manual Tuning</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc4-msc-capsense-csd-touchpad-tuning">
+*   <b>CSD Touchpad Manual Tuning</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc4-msc-capsense-csx-touchpad-tuning">
+*   <b>CSX Touchpad Manual Tuning</b></a>
+*
+* \subsection group_capsense_quick_start_psoc6_csd_ces Code Examples for PSoC&trade; 6 Devices with fourth-generation CAPSENSE&trade;
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc6-capsense-buttons-slider">
+*   <b>Two Buttons and Slider with CAPSENSE&trade; Tuner</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc6-low-power-capsense-freertos">
+*   <b>Low-Power Slider and Ganged Sensors with FreeRTOS</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc6-capsense-custom-scan">
+*   <b>Custom Scan</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc6-ble-capsense-tuner-client">
+*   <b>BLE Client for CAPSENSE&trade; Tuning</b></a>
+*
+* * <a href="https:/\/github.com/Infineon/mtb-example-psoc6-ble-capsense-tuner-server">
+*   <b>BLE Server for CAPSENSE&trade; Tuning</b></a>
+*
+* The CAPSENSE&trade; middleware can be used in various development environments
+* such as ModusToolbox&trade;, MBED, etc. Refer to the \ref section_capsense_toolchain.
+* The following are the configuration considerations for the different environments.
+*
+* \subsection group_capsense_quick_start_modus ModusToolbox&trade; Configuration Considerations
+*
+* This quick start guide assumes that the environment is configured:
+* * The <a href="https:/\/github.com/Infineon/mtb-pdl-cat1">
+* <b>CAT1 Peripheral Driver Library (PDL)</b></a> is included in the project
+* in case if the PSoC&trade; 6 device is used.
+* * The <a href="https:/\/github.com/Infineon/mtb-pdl-cat2">
+* <b>CAT2 Peripheral Driver Library (PDL)</b></a> is included in the project
+* in case if the PSoC&trade; 4 device is used.
+* * <a href="https:/\/www.cypress.com/ModusToolboxDeviceConfig">
+* <b>ModusToolbox&trade; Device Configurator Tool</b></a>,
+* <a href="https:/\/www.cypress.com/ModusToolboxCapSenseConfig">
+* <b>ModusToolbox&trade; CAPSENSE&trade; Configurator Tool</b></a>, and
+* <a href="https:/\/www.cypress.com/ModusToolboxCapSenseTuner">
+* <b>ModusToolbox&trade; CAPSENSE&trade; Tuner Tool</b></a>
+* are installed on the machine.
+*
+* \note
+* Ensure to set up the device power voltages correctly
+* to the proper operation of the device power domains. The Setup is
+* on the System Tab of the Device Configurator. Enable the Power check box
+* and set up the voltages as they are red-outlined in the picture below.
+*
+* \image html check_power.png "Power Setup" width=800px
+* \image latex check_power.png
+*
+* \subsection group_capsense_quick_start_mbed MBED OS Configuration Considerations
+*
+* You can immediately start with the following MBED OS code example available
+* at the <a href="https:/\/github.com/cypresssemiconductorco">
+* <b> Cypress Semiconductor GitHub</b></a>:
+* * <a href="https:/\/github.com/cypresssemiconductorco/mbed-os-example-capsense">
+*   <b>CAPSENSE&trade; buttons and slider for PSoC&trade; 6 MCU with Mbed OS</b></a>
+*
+* If you are doing your own project, remember to include cycfg.h file:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Resource_Include
+*
+* and call the resource initialization functions in main() at the beginning:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Resource_Initialization
+*
+********************************************************************************
+* \section section_capsense_configuration Summary of Application Programming Interface (API)
+********************************************************************************
+*
+* The CAPSENSE&trade; middleware operates on the top of the MSC/CSD HW driver.
+* Refer to the PDL API Reference Manual.
+*
+* This document provides descriptions of the functions in the CAPSENSE&trade;
+* middleware library, and descriptions of the data structures (register map)
+* used by the middleware library.
+*
+* The Application Programming Interface (API) routines allow controlling and
+* executing specific tasks using the CAPSENSE&trade; middleware. The CAPSENSE&trade; API
+* is described in the following sections:
+* * \ref group_capsense_high_level
+* * \ref group_capsense_low_level
+* * \ref group_capsense_data_structure
+* * \ref group_capsense_enums
+* * \ref group_capsense_macros
+* * \ref group_capsense_callbacks
+*
+********************************************************************************
+* \section section_capsense_toolchain Supported Software and Tools
+********************************************************************************
+*
+* This version of the CAPSENSE&trade; middleware was validated for compatibility
+* with the following Software and Tools:
+* <table class="doxtable">
+*   <tr>
+*     <th>Software and Tools</th>
+*     <th>Version</th>
+*   </tr>
+*   <tr>
+*     <td>ModusToolbox&trade; Software Environment</td>
+*     <td>2.4</td>
+*   </tr>
+*   <tr>
+*     <td>- ModusToolbox&trade; Device Configurator</td>
+*     <td>3.10.0</td>
+*   </tr>
+*   <tr>
+*     <td>- ModusToolbox&trade; MSC Superblock Personality for for PSoC&trade; 4 devices in the Device Configurator</td>
+*     <td>1.0</td>
+*   </tr>
+*   <tr>
+*     <td>- ModusToolbox&trade; MSC Personality for PSoC&trade; 4 devices in the Device Configurator</td>
+*     <td>1.1</td>
+*   </tr>
+*   <tr>
+*     <td>- ModusToolbox&trade; CSD Personality for PSoC&trade; 4 devices in the Device Configurator</td>
+*     <td>1.1</td>
+*   </tr>
+*   <tr>
+*     <td>- ModusToolbox&trade; CSD Personality for PSoC&trade; 6 devices in the Device Configurator</td>
+*     <td>2.0</td>
+*   </tr>
+*   <tr>
+*     <td>- ModusToolbox&trade; CAPSENSE&trade; Configurator tool</td>
+*     <td>4.0.0</td>
+*   </tr>
+*   <tr>
+*     <td>- ModusToolbox&trade; CAPSENSE&trade; Tuner tool</td>
+*     <td>4.0.0</td>
+*   </tr>
+*   <tr>
+*     <td>CAT1 Peripheral Driver Library (PDL)</td>
+*     <td>2.3.0</td>
+*   </tr>
+*   <tr>
+*     <td>CAT2 Peripheral Driver Library (PDL)</td>
+*     <td>1.4.0</td>
+*   </tr>
+*   <tr>
+*     <td>GCC Compiler</td>
+*     <td>9.3.1</td>
+*   </tr>
+*   <tr>
+*     <td>IAR Compiler</td>
+*     <td>8.42.1</td>
+*   </tr>
+*   <tr>
+*     <td>Arm Compiler 6 <sup><b>(Note 1)</b></sup></td>
+*     <td>6.13</td>
+*   </tr>
+*   <tr>
+*     <td>MBED OS (only for PSoC&trade; 6)</td>
+*     <td>5.15.8</td>
+*   </tr>
+*   <tr>
+*     <td>FreeRTOS</td>
+*     <td>10.4.5</td>
+*   </tr>
+* </table>
+*
+* <b>Note 1</b> The CAPSENSE&trade; middleware includes the pre-compiled libraries for
+* Arm Compiler 6. They are built with the following options to be compatible
+* with ModusToolbox&trade; and MBED:
+*
+* * -fshort-enums - Set the size of an enumeration type to the smallest
+*                   data type that can hold all enumerator values
+* * -fshort-wchar - Set the size of wchar_t to 2 bytes
+*
+* To operate in custom environments with Arm Compiler 6, apply
+* the above mentioned build options.
+*
+********************************************************************************
+* \section section_capsense_update Update to Newer Versions
+********************************************************************************
+* Refer to the \ref section_capsense_changelog to learn about the design impact
+* of the newer version. Set up your environment in accordance with
+* \ref section_capsense_toolchain.
+*
+* Ensure:
+* * The specified version of the ModusToolbox&trade; Device Configurator and
+*   the Personality are used to re-generate the device configuration.
+* * The specified version of the ModusToolbox&trade; CAPSENSE&trade; 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 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&trade; Device Configurator and perform the File->Save command
+*   to re-generate the device initialization code.
+* * From the ModusToolbox&trade; Device Configurator, launch the
+*   ModusToolbox&trade; CAPSENSE&trade; Configurator and perform the File->Save command to
+*   re-generate the middleware initialization code.
+*
+********************************************************************************
+* \section section_capsense_memory_usage Memory Usage
+********************************************************************************
+*
+* The CAPSENSE&trade; middleware Flash and RAM memory consumption varies:
+* * marginally - depending on the compiler and device
+* * significantly - depending on the project CAPSENSE&trade; configuration and
+*   number of APIs called by the application program.
+*
+* The table below provides the middleware total memory consumption for
+* specific CAPSENSE&trade; configurations. Memory consumption for any custom
+* design/configuration can be determined by analyzing a *.map file
+* generated by the compiler.
+*
+* The measurements were done with GCC compiler configured in
+* the Release mode with optimization set for Size.
+*
+* <table class="doxtable">
+*  <tr><th>Configuration:</th><th>Mode</th><th>Sensor Connection Type</th><th>Memory Type</th><th>Configuration 1</th><th>Configuration 2</th><th>Configuration 3</th><th>Configuration 4</th><th>Configuration 5</th><th>Configuration 6</th><th>Configuration 7</th><th>Configuration 8</th><th>Configuration 9</th></tr>
+*  <tr align="center"><td rowspan=2>4th Gen</td><td rowspan=2>IntDrv</td><td rowspan=2>AMUX</td><td>Flash:</td><td>&lt; 5.9 kB</td><td>&lt; 8.5 kB</td><td>&lt; 11.7 kB</td><td>&lt; 5.5 kB</td>
+*   <td>&lt; 6.8 kB</td><td>&lt; 7.8 kB</td><td>&lt; 9.1 kB</td><td>&lt; 9.4 kB</td><td>&lt; 18.7 kB</td></tr>
+*  <tr align="center"><td>SRAM:</td><td>&lt; 0.6 kB</td><td>&lt; 0.8 kB</td><td>&lt; 0.8 kB</td><td>&lt; 0.8 kB</td><td>&lt; 0.8 kB</td><td>&lt; 1.1 kB</td><td>&lt; 1.8 kB</td><td>&lt; 0.7 kB</td><td>&lt; 2.4 kB</td></tr>
+*  <tr align="center"><td rowspan=6>5th Gen</td><td rowspan=4>IntDrv</td><td rowspan=2>AMUX</td><td>Flash:</td><td>&lt; 7.3 kB</td><td>&lt; 10.3 kB</td><td>&lt; 11.5 kB</td><td>&lt; 7.4 kB</td>
+*   <td>&lt; 8.8 kB</td><td>&lt; 9.9 kB</td><td>&lt; 11.0 kB</td><td>&lt; 11.3 kB</td><td>&lt; 15.0 kB</td></tr>
+*  <tr align="center"><td>SRAM:</td><td>&lt; 1.1 kB</td><td>&lt; 1.2 kB</td><td>&lt; 1.1 kB</td><td>&lt; 1.3 kB</td><td>&lt; 1.3 kB</td><td>&lt; 1.7 kB</td><td>&lt; 2.3 kB</td><td>&lt; 1.7 kB</td><td>&lt; 3.3 kB</td></tr>
+*  <tr align="center"><td rowspan=2>CTRL_MUX</td><td>Flash:</td><td colspan=9>Flash memory consumption 1000 bytes higher then CTRL_MUX - DMA</td></tr>
+*  <tr align="center"><td>SRAM:</td><td colspan=9>SRAM memory consumption is the same as in CTRL_MUX - DMA</td></tr>
+*  <tr align="center"><td rowspan=2>DMA</td><td rowspan=2>CTRL_MUX</td><td>Flash:</td><td>&lt; 7.7 kB</td><td>&lt; 11.0 kB</td><td>&lt; 11.1 kB</td><td>&lt; 7.8 kB</td><td>&lt; 9.6 kB</td><td>&lt; 10.2 kB</td><td>&lt; 11.4 kB</td><td>&lt; 11.7 kB</td><td>&lt; 15.4 kB</td></tr>
+*  <tr align="center"><td>SRAM:</td><td>&lt; 1.3 kB</td><td>&lt; 1.5 kB</td><td>&lt; 1.4 kB</td><td>&lt; 2.1 kB</td><td>&lt; 2.1 kB</td><td>&lt; 2.6 kB</td><td>&lt; 3.3 kB</td><td>&lt; 2.1 kB</td><td>&lt; 5.4 kB</td></tr>
+*  <tr><th colspan=13>Widgets</th></tr>
+*  <tr><td colspan=4>CSD Button</td><td>3(10 sensors)</td><td>3(10 sensors)</td><td>3(10 sensors)</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1(1 sensor)</td><td>1(1 sensor)</td></tr>
+*  <tr><td colspan=4>CSD Matrix Buttons</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>CSD Slider</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>CSD Touchpad</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1(8x8)</td><td>1(8x8)</td></tr>
+*  <tr><td colspan=4>CSD Proximity</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>CSX Button</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>CSX Matrix Buttons</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1(4x8)</td><td>1(4x8)</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>CSX Touchpad</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>1(9x4)</td><td>1(9x4)</td><td>&nbsp;</td><td>1(8x8)</td></tr>
+*  <tr><th colspan=13>Features</th></tr>
+*  <tr><td colspan=4>Gesture</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Ballistic Multiplier</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Centroid Type</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Supported fingers on touchpad</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Shield</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>enabled</td></tr>
+*  <tr><td colspan=4>SmartSense</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>CSD auto-calibration</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>CSX auto-calibration</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Self-test</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><th colspan=13>Raw Count Filters</th></tr>
+*  <tr><td colspan=4>IIR</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>enabled</td><td>enabled</td></tr>
+*  <tr><td colspan=4>Median</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Average</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><th colspan=13>Position Filters</th></tr>
+*  <tr><td colspan=4>IIR</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Median</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Average</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Adaptive IIR</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+*  <tr><td colspan=4>Jitter</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>enabled</td><td>&nbsp;</td><td>&nbsp;</td></tr>
+* </table>
+*
+* \note
+* * To select values for the Scan mode and Sensor connection method parameters (for the fifth-generation of the CAPSENSE&trade; HW)
+* navigate to the Advanced tab in the CAPSENSE&trade; Configurator tool, and then select the General settings sub-tab.
+*
+* * For the forth-generation of the CAPSENSE&trade; HW, the IntDrv mode with the AMUX sensor connection type is available only.
+*
+********************************************************************************
+* \section section_capsense_misra MISRA-C:2012 Compliance
+********************************************************************************
+*
+* This page describes MISRA-C:2012 compliance and deviations for
+* the CAPSENSE&trade; middleware.
+*
+* MISRA stands for Motor Industry Software Reliability Association. The MISRA
+* specification covers a set of 10 mandatory rules, 110 required rules and
+* 39 advisory rules that apply to firmware design and has been put together
+* by the Automotive Industry to enhance the quality and robustness of
+* the firmware code embedded in automotive devices.
+*
+* \subsection subsection_capsense_misra-mw CAPSENSE&trade; Middleware Deviation
+*
+* <table class="doxtable">
+*   <tr>
+*     <th>Rule ID</th>
+*     <th>Rule Description</th>
+*     <th>Description of Deviation(s)</th>
+*   </tr>
+*    <tr>
+*     <td>Directive  4.8</td>
+*     <td>If a pointer to a structure or union is never dereferenced within a translation
+*         unit, then the implementation of the object should be hidden.
+*     </td>
+*     <td>Advisory. The middleware library consists of several modules. One of them
+*         is CapSense Data Structure. All communication between the other modules
+*         is performed through CapSense Data Structure.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 2.3</td>
+*     <td>A project should not contain unused type declarations.
+*     </td>
+*     <td>Advisory. The middleware library provides API to the hardware. The type
+*         is part of API, which is defined for application-level only.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 2.5</td>
+*     <td>A project should not contain unused macro declarations.
+*     </td>
+*     <td>Advisory. The middleware library provides API to the hardware. The macro
+*         is part of API, which is defined for application-level only.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 5.1</td>
+*     <td>External identifiers shall be distinct.
+*     </td>
+*     <td>Toolchains from Supported Software and Tools documentation section
+*         are verified to work with functions, names of which have similar first 31 symbols.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 5.4</td>
+*     <td>Macro identifiers shall be distinct.
+*     </td>
+*     <td>Toolchains from Supported Software and Tools documentation section
+*         are verified to work with macros, names of which have similar first 31 symbols.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 5.6</td>
+*     <td>A typedef name shall be a unique identifier.
+*     </td>
+*     <td>During the code analysis, the same source files are compiled multiple times
+*         with device-specific options. All typedef names are unique for each specific run.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 5.8</td>
+*     <td>Identifiers that define objects or functions with external linkage shall be unique.
+*     </td>
+*     <td>During the code analysis, the same source files are compiled multiple times
+*         with device-specific options. All object and function identifiers are unique
+*         for each specific run.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 5.9</td>
+*     <td>Identifiers that define objects or functions with internal linkage should be unique.
+*     </td>
+*     <td>Advisory. During the code analysis, the same source files are compiled multiple times
+*         with device-specific options. All object and function identifiers are unique
+*         for each specific run.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 8.3</td>
+*     <td>All declarations of an object or function shall use the same names and type qualifiers.
+*     </td>
+*     <td>During the code analysis, the same source files are compiled multiple times
+*         with device-specific options. All object and function identifiers are unique
+*         for each specific run.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 8.5</td>
+*     <td>An external object or function shall be declared once in one and only one file.
+*     </td>
+*     <td>During the code analysis, the same source files are compiled multiple times
+*         with device-specific options. All object and function identifiers are unique
+*         for each specific run.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 8.6</td>
+*     <td>An identifier with external linkage shall have exactly one external definition.
+*     </td>
+*     <td>During the code analysis, the same source files are compiled multiple times
+*         with device-specific options. All object and function identifiers are unique
+*         for each specific run.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 8.7</td>
+*     <td>Functions and objects should not be defined with external linkage if they
+*         are referenced in only one translation unit.
+*     </td>
+*     <td>Advisory. During the code analysis, the same source files are compiled multiple times
+*         with device-specific options. All object and function identifiers are unique
+*         for each specific run.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 8.13</td>
+*     <td>A pointer should point to const-qualified type whenever possible.
+*     </td>
+*     <td>Advisory. During the code analysis, the same source files are compiled multiple times
+*         with device-specific options. A function argument can be const for some specific run.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 11.5</td>
+*     <td>A conversion should not be performed from pointer to void into pointer to object.
+*     </td>
+*     <td>Advisory. The cast from void pointer to an object pointer does not have any unintended effect,
+*         as it is a consequence of the definition of a structure based on function pointers.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 14.2</td>
+*     <td>A for loop shall be well-formed.
+*     </td>
+*     <td>The third clause of the for loop is empty to improve execution time.
+*     </td>
+*   </tr>
+*    <tr>
+*     <td>Rule 18.4</td>
+*     <td>The +, -, += and -= operators should not be applied to an expression of pointer type.
+*     </td>
+*     <td>Advisory. There are several instances of pointer arithmetic in drivers. They cannot be avoided,
+*         so are manually checked and reviewed to be safe.
+*     </td>
+*   </tr>
+* </table>
+*
+* \subsection subsection_capsense_misra-cfg CAPSENSE&trade; Configurator Generated Sources Deviation
+*
+* <table class="doxtable">
+*   <tr>
+*     <th>Rule ID</th>
+*     <th>Rule Description</th>
+*     <th>Description of Deviation(s)</th>
+*   </tr>
+*   <tr>
+*     <td>Rule 3.1</td>
+*     <td>The character sequences / * and / / shall not be used within a comment.</td>
+*     <td>Using of the special comment symbols is need for Doxygen comment
+*         support, it does not have any impact on functionality. </td>
+*   </tr>
+*   <tr>
+*     <td>Rule 8.4</td>
+*     <td>A compatible declaration shall be visible when an object or function with external linkage is defined.</td>
+*     <td>The CAPSENSE&trade; middleware library consists of several modules. One of them is CapSense Built-in Self Test (BIST).
+*         All the BIST variables are used in other data structures and accessed using pointers.</td>
+*   </tr>
+*   <tr>
+*     <td>Rule 11.4</td>
+*     <td>A conversion should not be performed between a pointer to object and an integer type.</td>
+*     <td>Advisory. There are several instances of pointer conversions in Generated Source.
+*         They are manually checked and reviewed to be safe.</td>
+*   </tr>
+* </table>
+*
+********************************************************************************
+* \section section_capsense_errata Errata
+********************************************************************************
+*
+* This section lists the known problems with the CAPSENSE&trade; middleware.
+*
+* <table class="doxtable">
+*   <tr><th>ID</th><th>Known Issue</th><th>Workaround</th></tr>
+*   <tr>
+*     <td>319100</td>
+*     <td>
+*         GPIO simultaneous operation with unrestricted strength and frequency
+*         creates noise that can affect CAPSENSE&trade; operation. This issue
+*         is applicable for the fourth CAPSENSE&trade; generation devices.
+*     </td>
+*     <td>
+*         For detail, refer to the errata section of the device datasheet.
+*     </td>
+*   </tr>
+*   <tr>
+*     <td>3159</td>
+*     <td>
+*         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. This issue is applicable for the fourth CAPSENSE&trade;
+*         generation devices.
+*     </td>
+*     <td>
+*         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_capsense.c file
+*            and update the .csdInitSwRes field of the cy_capsense_commonConfig structure
+*            with the CY_CAPSENSE_INIT_SW_RES_HIGH value.
+*     </td>
+*   </tr>
+* </table>
+*
+********************************************************************************
+* \section section_capsense_changelog Changelog
+********************************************************************************
+*
+* <table class="doxtable">
+*   <tr><th>Version</th><th>Changes</th><th>Reason for Change</th></tr>
+*   <tr>
+*     <td rowspan="12">3.0</td>
+*     <td colspan="2"><i><b>
+*       This version is not backward compatible with the
+*       previous version due to implemented memory consumption optimization.
+*       We tried to keep the established API, but your design may need to be
+*       updated to operate with CAPSENSE&trade; middleware v3.0.
+*
+*       Also, if you use the CAPSENSE&trade; middleware v3.0 version then
+*       you must use the CAPSENSE&trade; Configurator v4.0 tool or later.
+*       This MW version is not compatible with the previous Configurator tool
+*       versions.
+*     </b></i></td>
+*   </tr>
+*   <tr>
+*     <td>
+*     Added fifth-generation CAPSENSE&trade; device support which includes
+*     but not limited:
+*     * Scanning mode: DMA and Interrupt Driven
+*     * Sensor connection method: Analog mux bus and Control mux bus
+*     * Re-designed multi-frequency scan feature
+*     * Multi-phase TX feature
+*     * Improved signal-to-noise ratio
+*     * Improved refresh rate
+*     </td>
+*     <td>New CAPSENSE&trade; MSC platform covering</td>
+*   </tr>
+*   <tr>
+*     <td colspan="2"><i><b>The following rows show changes related to fourth-generation CAPSENSE&trade;</b></i></td>
+*   </tr>
+*   <tr>
+*     <td>Removed usage of deprecated return error and status codes,
+*         cy_status enum was replaced with the cy_capsense_status_t variable</td>
+*     <td>Defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td>Removed usage of deprecated types, such as uint32 and uint16</td>
+*     <td>Defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td>Changed the default IDAC gain index for the CSX auto-calibration to the configured one</td>
+*     <td>Defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td>The following functions were made obsolete:
+*         * Cy_CapSense_CSDConnectSns()
+*         * Cy_CapSense_CSDDisconnectSns()
+*         * Cy_CapSense_CSXConnectRx()
+*         * Cy_CapSense_CSXConnectTx()
+*         * Cy_CapSense_CSXDisconnectRx()
+*         * Cy_CapSense_CSXDisconnectTx()
+*         * Cy_CapSense_CalibrateAllCsdWidgets()
+*         * Cy_CapSense_CalibrateAllCsxWidgets()
+*     </td>
+*     <td>User experience improvement</td>
+*   </tr>
+*   <tr>
+*     <td>For fourth-generation CAPSENSE&trade; devices callbacks were moved from ptrCommonContext
+*         to ptrInternalContext structure</td>
+*     <td>User experience improvement</td>
+*   </tr>
+*   <tr>
+*     <td>Updated the description of the Cy_CapSense_RunSelfTest() function </td>
+*     <td>Documentation defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td>Specified measurement units in the following function descriptions:
+*         * Cy_CapSense_MeasureCapacitanceSensor()
+*         * Cy_CapSense_MeasureCapacitanceShield()
+*         * Cy_CapSense_MeasureCapacitanceCap()
+*     </td>
+*     <td>Documentation defect fixing</td>
+*   <tr>
+*     <td>Added call of the Cy_CapSense_Wakeup() function to the registered
+*     callback in the Cy_CapSense_DeepSleepCallback() function</td>
+*     <td>Improved robustness of a sensing module</td>
+*   </tr>
+*   <tr>
+*     <td>Added a possibility to enable / disable independent features of
+*     BIST module</td>
+*     <td>Expanded flexibility</td>
+*   </tr>
+*   <tr>
+*     <td rowspan="9">2.10</td>
+*     <td>Added Built-in Self-test (BIST) library</td>
+*     <td>Support Class B (IEC-60730), safety integrity-level compliant design</td>
+*   </tr>
+*   <tr>
+*     <td>Improved the Csh and Cmod coarse initialization functionality.</td>
+*     <td>Feature enhancement</td>
+*   </tr>
+*   <tr>
+*     <td>Improved the shield performance when Csh is enabled</td>
+*     <td>Feature enhancement</td>
+*   </tr>
+*   <tr>
+*     <td>Fixed Cy_CapSense_ScanExt() operation</td>
+*     <td>Defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td>Fixed the bug in the Cy_CapSense_SetPinState() function</td>
+*     <td>Defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td>Optimized software watch-dog values used in monitoring CAPSENSE&trade;
+*         scanning duration</td>
+*     <td>User experience improvement</td>
+*   </tr>
+*   <tr>
+*     <td>Improved IDAC auto-calibration</td>
+*     <td>Operation accuracy increasing</td>
+*   </tr>
+*   <tr>
+*     <td>Added the following functions:
+*         * Cy_CapSense_GetParam()
+*         * Cy_CapSense_SetParam()
+*         * Cy_CapSense_GetCRC()
+*     </td>
+*     <td>Feature enhancement</td>
+*   </tr>
+*   <tr>
+*     <td>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()
+*     </td>
+*     <td>Defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td rowspan="6">2.0</td>
+*     <td>Added memory usage section to the CAPSENSE&trade; API Ref Guide</td>
+*     <td>User experience improvement</td>
+*   </tr>
+*   <tr>
+*     <td>Updated documentation</td>
+*     <td>User experience improvement</td>
+*   </tr>
+*   <tr>
+*     <td>Added the errata section to the CAPSENSE&trade; API Ref Guide</td>
+*     <td>User experience improvement</td>
+*   </tr>
+*   <tr>
+*     <td>CAPSENSE&trade; MW sources are enclosed with the conditional compilation to
+*         ensure a successful compilation for non-CAPSENSE&trade;-capable devices</td>
+*     <td>Fixing a compilation error for non CAPSENSE&trade;-capable devices</td>
+*   </tr>
+*   <tr>
+*     <td>Optimized flash memory consumption based on user's configuration</td>
+*     <td>Flash foot-print optimization</td>
+*   </tr>
+*   <tr>
+*     <td>Renamed function Cy_CapSense_CheckCommandIntegrity() to
+*         Cy_CapSense_CheckTunerCmdIntegrity()</td>
+*     <td>User experience improvement</td>
+*   </tr>
+*   <tr>
+*     <td rowspan="2">1.20</td>
+*     <td>Added Arm Compiler 6 support</td>
+*     <td>Feature enhancement</td>
+*   </tr>
+*   <tr>
+*     <td>Changed the hierarchy of the binary files folders</td>
+*     <td>MBED OS compatibility</td>
+*   </tr>
+*   <tr>
+*     <td rowspan="6">1.1</td>
+*     <td>
+*         The following functions made obsolete:
+*         * Cy_CapSense_CSDSetupWidget()
+*         * Cy_CapSense_CSDSetupWidgetExt()
+*         * Cy_CapSense_CSDScan()
+*         * Cy_CapSense_CSDScanExt()
+*         * Cy_CapSense_CSDCalibrateWidget()
+*         * Cy_CapSense_CSXSetupWidget()
+*         * Cy_CapSense_CSXSetupWidgetExt()
+*         * Cy_CapSense_CSXScan()
+*         * Cy_CapSense_CSXScanExt()
+*         * Cy_CapSense_CSXCalibrateWidget()
+*
+*         Two simple functions introduced to replace the listed above functions:
+*         * Cy_CapSense_SetupWidgetExt()
+*         * Cy_CapSense_ScanExt()
+*     </td>
+*     <td>User experience improvement</td>
+*   </tr>
+*   <tr>
+*     <td>Fixed the shield operation when Csh is disabled</td>
+*     <td>Defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td>Fixed the implementation of the position filtering for the Radial Slider widget</td>
+*     <td>Defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td>Added restoring hardware to its default state in the Cy_CapSense_DeInit() implementation</td>
+*     <td>Defect fixing</td>
+*   </tr>
+*   <tr>
+*     <td>Added the capability to enable the shield electrode without dedicated electrodes</td>
+*     <td>Feature enhancement</td>
+*   </tr>
+*   <tr>
+*     <td>Added support of a protocol-agnostic tuner interface (UART, SPI, etc.)</td>
+*     <td>Feature enhancement</td>
+*   </tr>
+*   <tr>
+*     <td>1.0</td>
+*     <td>
+*         The initial version
+*     </td>
+*     <td></td>
+*   </tr>
+* </table>
+*
+********************************************************************************
+* \section section_capsense_more_information More Information
+********************************************************************************
+*
+* Important information about the CAPSENSE&trade;-technology overview, appropriate
+* CYPRESS&trade; device from Infineon for the design, CAPSENSE&trade; system and sensor
+* design guidelines, different interfaces and tuning guidelines necessary
+* for a successful design of a CAPSENSE&trade; system is available in the Getting
+* Started with CAPSENSE&trade; document and the product-specific CAPSENSE&trade; design guide.
+* CYPRESS&trade; highly recommends starting with these documents. They can be
+* found on the CYPRESS&trade; web site at www.cypress.com.
+*
+* For more information, refer to the following documents:
+*
+* * CAPSENSE&trade; Overview:
+*
+*   * <a href="https:/\/www.cypress.com/ModusToolboxCapSenseConfig"><b>ModusToolbox&trade;
+*   CAPSENSE&trade; Configurator Tool Guide</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/ModusToolboxCapSenseTuner"><b>ModusToolbox&trade;
+*   CAPSENSE&trade; Tuner Tool Guide</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/documentation/application-notes/an85951-psoc-4-and-psoc-6-mcu-capsense-design-guide">
+*   <b>CAPSENSE&trade; Design Guide</b></a>
+*
+* * ModusToolbox&trade; Overview:
+*
+*   * <a href="https:/\/www.cypress.com/products/modustoolbox-software-environment">
+*   <b>ModusToolbox&trade; Software Environment, Quick Start Guide, Documentation,
+*   and Videos</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/ModusToolboxDeviceConfig"><b>ModusToolbox&trade;
+*   Device Configurator Tool Guide</b></a>
+*
+* * Infineon Technologies Kits and Code Examples:
+*
+*   * <a href="https:/\/github.com/cypresssemiconductorco/mbed-os-example-capsense">
+*   <b>CAPSENSE&trade; buttons and slider for PSoC&trade; 6 MCU with Mbed OS</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/documentation/code-examples/ce218136-psoc-6-mcu-e-ink-display-capsense-rtos">
+*   <b>CAPSENSE&trade; Middleware Code Example for FreeRTOS</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/documentation/development-kitsboards/cy8ckit-145-40xx-psoc-4000s-capsense-prototyping-kit">
+*   <b>CY8CKIT-145-40XX PSoC&trade; 4000S CAPSENSE&trade; Prototyping Kit</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/documentation/development-kitsboards/cy8ckit-149-psoc-4100s-plus-prototyping-kit">
+*   <b>CY8CKIT-149 PSoC&trade; 4100S Plus Prototyping Kit</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/documentation/development-kitsboards/cy8ckit-041-psoc-4-s-series-pioneer-kit">
+*   <b>CY8CKIT-041-40XX PSoC&trade; 4 S-Series Pioneer Kit</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/documentation/development-kitsboards/cy8ckit-041-41xx-psoc-4100s-capsense-pioneer-kit">
+*   <b>CY8CKIT-041-41XX PSoC&trade; 4100S CAPSENSE&trade; Pioneer Kit</b></a>
+*
+* * General Information:
+*
+*   * <a href="https:/\/cypresssemiconductorco.github.io/mtb-pdl-cat1/pdl_api_reference_manual/html/index.html">
+*   <b>CAT1 PDL API Reference</b></a>
+*
+*   * <a href="https:/\/cypresssemiconductorco.github.io/mtb-pdl-cat2/pdl_api_reference_manual/html/index.html">
+*   <b>CAT2 PDL API Reference</b></a>
+*
+*   * <a href="http:/\/www.cypress.com/an210781"><b>AN210781 Getting Started with
+*   PSoC&trade; 6 MCU with Bluetooth Low Energy (BLE) Connectivity</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/documentation/technical-reference-manuals/psoc-6-mcu-psoc-63-ble-architecture-technical-reference">
+*   <b>PSoC&trade; 6 Technical Reference Manual</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/documentation/technical-reference-manuals/psoc-4000s-family-psoc-4-architecture-technical-reference">
+*   <b>PSoC&trade; 4000S Family: PSoC&trade; 4 Architecture Technical Reference Manual (TRM)</b></a>
+*
+*   * <a href="https:/\/www.cypress.com/documentation/technical-reference-manuals/psoc-4100s-and-psoc-4100s-plus-psoc-4-architecture">
+*   <b>PSoC&trade; 4100S and PSoC&trade; 4100S Plus: PSoC&trade; 4 Architecture Technical Reference Manual (TRM)</b></a>
+*
+*   * <a href="http:/\/www.cypress.com/ds218787">
+*   <b>PSoC&trade; 63 with BLE Datasheet Programmable System-on-Chip datasheet</b></a>
+*
+*   * <a href="https:/\/github.com/Infineon"><b> Infineon Technologies GitHub</b></a>
+*
+*   * <a href="http:/\/www.infineon.com"><b>Infineon Technologies</b></a>
+*
+* \note
+* The links to another software component's documentation (middleware and PDL)
+* point to GitHub to the latest available version of the software.
+* To get documentation of the specified version, download from GitHub and unzip
+* the component archive. The documentation is available in the <i>docs</i> folder.
+*
+* \defgroup group_capsense_high_level               High-level Functions
+*
+* \defgroup group_capsense_low_level                Low-level Functions
+*
+* \defgroup group_capsense_data_structure           Data Structure
+*
+* \defgroup group_capsense_structures               Structures
+* \ingroup group_capsense_data_structure
+* \brief The CAPSENSE&trade; structures.
+*
+* \defgroup group_capsense_gesture_structures       Gesture Structures
+* \ingroup group_capsense_data_structure
+* \brief The Gesture-related structures.
+*
+* \defgroup group_capsense_enums                    Enumerated Types
+*
+* \defgroup group_capsense_macros                   Macros
+*
+* \defgroup group_capsense_macros_general           General Macros
+*   \ingroup group_capsense_macros
+*   \brief General macros
+* \defgroup group_capsense_macros_mw_state          Middleware State Macros
+*   \ingroup group_capsense_macros
+*   \brief Middleware state macros
+* \defgroup group_capsense_macros_status            Status Macros
+*   \ingroup group_capsense_macros
+*   \brief Status macros
+* \defgroup group_capsense_macros_settings          Settings Macros
+*   \ingroup group_capsense_macros
+*   \brief Settings macros
+* \defgroup group_capsense_macros_pin               Pin-related Macros
+*   \ingroup group_capsense_macros
+*   \brief Pin-related macros
+* \defgroup group_capsense_macros_process           Processing Macros
+*   \ingroup group_capsense_macros
+*   \brief Processing macros
+* \defgroup group_capsense_macros_touch             Touch-related Macros
+*   \ingroup group_capsense_macros
+*   \brief Touch-related macros
+* \defgroup group_capsense_macros_gesture           Gesture Macros
+*   \ingroup group_capsense_macros
+*   \brief Gesture macros
+* \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
+*
+* \cond SECTION_CAPSENSE_INTERNAL
+* \defgroup group_capsense_internal                 Internal Functions
+* \endcond
+*
+**/
+
+/******************************************************************************/
+/** \addtogroup group_capsense_high_level
+* \{
+*
+* High-level functions represent the highest abstraction layer of
+* the CAPSENSE&trade; middleware.
+*
+* These functions perform tasks such as scanning, data processing, data
+* reporting and tuning interfaces. When performing a task, different
+* initialization is required based on a sensing method or type of
+* widgets is automatically handled by these functions. Therefore, these
+* functions are sensing methods, features, and widget type agnostics.
+*
+* All the tasks required to implement a sensing system can be fulfilled
+* by the high-level functions. But, there is a set of
+* \ref group_capsense_low_level that provides access to lower level
+* and specific tasks. If a design requires access to low-level tasks,
+* these functions can be used. The functions related to a given sensing
+* methods are not available if the corresponding method is disabled.
+*
+* \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_low_level
+* \{
+*
+* The Low-level functions represent the lower layer of abstraction in
+* support of \ref group_capsense_high_level.
+*
+* These functions also enable implementation of special case designs
+* requiring performance optimization and non-typical functionalities.
+*
+* All functions are general to all sensing methods. Some of the
+* functions detect the sensing method used by the widget and execute
+* tasks as appropriate.
+*
+* \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros
+* \{
+*
+* Specifies constants used in the CAPSENSE&trade; middleware.
+*
+* \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_enums
+* \{
+*
+* Documents the CAPSENSE&trade; middleware related enumerated types.
+*
+* \} */
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal
+* \{
+*
+* The section documents the CAPSENSE&trade; middleware related internal function.
+*
+* These function should not be used in the application program.
+*
+* \} \endcond */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_data_structure
+* \{
+*
+* The CAPSENSE&trade; Data Structure organizes configuration parameters, input, and
+* output data shared among different FW modules within the CAPSENSE&trade;.
+*
+* The key responsibilities of the Data Structure are as follows:
+* * The Data Structure is the only data container in the CAPSENSE&trade; middleware.
+* * It serves as storage for the configuration and the output data.
+* * All CAPSENSE&trade; modules use the data structure for the communication
+*   and data exchange.
+*
+* The CAPSENSE&trade; Data Structure is a composite of several smaller structures
+* (for global / common data, widget data, sensor data, and pin data).
+* Furthermore, the data is split between RAM and Flash to achieve a
+* reasonable balance between resources consumption and configuration / tuning
+* flexibility at runtime and compile time. A graphical representation of
+* the CAPSENSE&trade; Data Structure is shown below.
+*
+* Note that figure below shows a sample representation and documents the
+* high-level design of the data structure, it does not include all the
+* parameters and elements in each object.
+*
+* \image html capsense_ds.png "CAPSENSE&trade; Data Structure" width=800px
+* \image latex capsense_ds.png
+*
+* CAPSENSE&trade; Data Structure does not perform error checking on the data
+* written to CAPSENSE&trade; Data Structure. It is the responsibility of application
+* program to ensure register map rule are not violated while
+* modifying the value of data field in CAPSENSE&trade; Data Structure.
+*
+* \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_callbacks
+* \{
+*
+* Callbacks allow the user to execute Custom code called from the CAPSENSE&trade;
+* middleware when an event occurs. CAPSENSE&trade; supports several callbacks.
+*
+* <table>
+*   <tr>
+*     <th>#</th>
+*     <th >Callback Name</th>
+*     <th>Associated Register</th>
+*     <th>Callback Function Prototype</th>
+*     <th>Description</th>
+*   </tr>
+*   <tr>
+*     <td>1</td>
+*     <td>Start Sample</td>
+*     <td>ptrSSCallback</td>
+*     <td>\ref cy_capsense_callback_t</td>
+*     <td>This is called before each sensor scan triggering. Such a callback
+*         can be used to implement user-specific use cases like changing scan
+*         parameters depending on whether a sensor is going to be scanned.
+*         For the fifth-generation CAPSENSE&trade; in CS-DMA mode this callback is called
+*         only once in Cy_CapSense_ScanSlots() function with NULL passed as a parameter.
+*         In INT driven mode it is called in Cy_CapSense_ScanSlots() and
+*         in Cy_CapSense_ScanISR() function before HW starting the scan. </td>
+*   </tr>
+*   <tr>
+*     <td>2</td>
+*     <td>End Of Scan</td>
+*     <td>ptrEOSCallback</td>
+*     <td>\ref cy_capsense_callback_t</td>
+*     <td>This is called after sensor scan completion and there is no other
+*         sensor in the queue to be scanned.
+*         For the fifth-generation CAPSENSE&trade; in CS-DMA mode this callback is called
+*         with NULL passed as a parameter.</td>
+*   </tr>
+*   <tr>
+*     <td>3</td>
+*     <td>Tuner Send Callback</td>
+*     <td>ptrTunerSendCallback</td>
+*     <td>\ref cy_capsense_tuner_send_callback_t</td>
+*     <td>This is called by the Cy_CapSense_RunTuner() function to establish
+*         synchronous communication with the Tuner tool.</td>
+*   </tr>
+*   <tr>
+*     <td>4</td>
+*     <td>Tuner Receive Callback</td>
+*     <td>ptrTunerReceiveCallback</td>
+*     <td>\ref cy_capsense_tuner_receive_callback_t</td>
+*     <td>This is called by the Cy_CapSense_RunTuner() function to establish
+*         synchronous communication with the Tuner tool.</td>
+*   </tr>
+*   <tr>
+*     <td>5</td>
+*     <td>CAPSENSE&trade; Data Structure Initialization Callback</td>
+*     <td>ptrEODsInitCallback</td>
+*     <td>\ref cy_capsense_ds_init_callback_t</td>
+*     <td>This is called by the Cy_CapSense_Enable() function after CAPSENSE&trade;
+*         Data Structure initialization complete and before launching
+*         the first initialization scan. Using this callback is not
+*         recommended. It is used only to implement only user's
+*         specific use cases (while changing the CAPSENSE&trade;
+*         default configuration). The callback is available for Fifth
+*         Generation CAPSENSE&trade; devices.</td>
+*   </tr>
+* </table>
+*
+* \note
+* Callbacks 1 and 2 are called by the Cy_CapSense_InterruptHandler()
+* function and lengthen this function execution. Usually,
+* Cy_CapSense_InterruptHandler() is called inside the ISR.
+* Then these callbacks also lengthen the ISR execution.
+*
+* All callbacks can be registered by direct assignment of the function
+* pointers to the corresponding CAPSENSE&trade; Data Structure field after call of
+* the Cy_CapSense_Init() function as follows:
+*  *
+* <tt>context-\>ptrInternalContext-\>\<Associated Register\> = \&CallbackFunction;</tt>
+*
+* Callbacks 1 and 2 can be registered / unregistered using
+* the Cy_CapSense_RegisterCallback() and Cy_CapSense_UnRegisterCallback()
+* functions.
+*
+* \} */
+
+
+#if !defined(CY_CAPSENSE_H)
+#define CY_CAPSENSE_H
+
+#include "cy_device_headers.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_centroid.h"
+#include "cy_capsense_control.h"
+#include "cy_capsense_filter.h"
+#include "cy_capsense_lib.h"
+#include "cy_capsense_gesture_lib.h"
+#include "cy_capsense_processing.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_tuner.h"
+#include "cy_capsense_sensing.h"
+#include "cy_capsense_selftest.h"
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+    #include "cy_capsense_csd_v2.h"
+    #include "cy_capsense_csx_v2.h"
+    #include "cy_capsense_sensing_v2.h"
+    #include "cy_capsense_selftest_v2.h"
+#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
+    #include "cy_capsense_generator_v3.h"
+    #include "cy_capsense_sensing_v3.h"
+    #include "cy_capsense_selftest_v3.h"
+    #include "cy_capsense_sm_base_full_wave_v3.h"
+#endif
+
+#endif /* CY_CAPSENSE_H */
+
+
+/* [] END OF FILE */

+ 2333 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_centroid.c

@@ -0,0 +1,2333 @@
+/***************************************************************************//**
+* \file cy_capsense_centroid.c
+* \version 3.0
+*
+* \brief
+* This file provides the source code for the centroid calculation methods
+* of the CAPSENSE&trade; middleware.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include <string.h>
+#include <stddef.h>
+#include <stdint.h>
+#include "cy_syslib.h"
+#include "cy_capsense_centroid.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_lib.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_filter.h"
+#include "cycfg_capsense_defines.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+#if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_SLIDER_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_TOUCHPAD_EN))
+
+
+/*******************************************************************************
+* Local definition
+*******************************************************************************/
+#define CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_LENGTH        (3u)
+#define CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_PREVIOUS      (0u)
+#define CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_CENTER        (1u)
+#define CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_NEXT          (2u)
+#define CY_CAPSENSE_LINEAR_SLIDER_MIN_SNS_COUNT         (3u)
+#define CY_CAPSENSE_TOUCHPAD_MIN_COL_SNS_COUNT          (3u)
+#define CY_CAPSENSE_TOUCHPAD_MIN_ROW_SNS_COUNT          (3u)
+
+/* Minimum valid age */
+#define CY_CAPSENSE_CSX_TOUCHPAD_AGE_START              (0x0100u)
+#define CY_CAPSENSE_CSX_TOUCHPAD_Z_SHIFT                (0x04u)
+#define CY_CAPSENSE_CSX_TOUCHPAD_BYTE_SHIFT             (8u)
+#define CY_CAPSENSE_CENTROID_ROUND_VALUE                (0x7Fu)
+#define CY_CAPSENSE_NO_LOCAL_MAX                        (0xFFFFu)
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    static void Cy_CapSense_TransferTouch(
+                    uint32_t newIndex,
+                    uint32_t oldIndex,
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    static void Cy_CapSense_NewTouch(
+                    uint32_t newIndex,
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    static uint32_t Cy_CapSense_CalcDistance(
+                    uint32_t newIndex,
+                    uint32_t oldIndex,
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    static void Cy_CapSense_Hungarian(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    static void Cy_CapSense_CopyTouchRecord(
+                    cy_stc_capsense_position_t * destination,
+                    const cy_stc_capsense_position_t * source);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    __STATIC_INLINE void Cy_CapSense_TouchDownDebounce(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    __STATIC_INLINE void Cy_CapSense_SortByAge(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    __STATIC_INLINE uint8_t Cy_CapSense_GetLowestId(uint8_t idMask);
+#endif
+/** \} \endcond */
+
+
+#if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_DIPLEX_SLIDER_EN) ||\
+    (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_DIPLEX_SLIDER_EN))
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpCentroidDiplex
+****************************************************************************//**
+*
+* Finds touch position of a Linear slider widget with enabled diplexing.
+*
+* In scope of position searching this function finds the local maximum with the
+* highest raw count. If such maximums are more than one, then the maximum with the
+* bigger sum of neighboring sensors is taken for further processing. Then the position
+* is calculated using centroid algorithm with three sensors.
+*
+* At least two neighboring sensors should cross finger threshold. Then the algorithm
+* is able to distinguish where real touch is located (direct part of slider or
+* diplex part of slider) and corresponding position is reported. Otherwise no
+* touch is reported.
+*
+* This function does not detect two or more touches.
+*
+* \param newTouch
+* The pointer to the touch structure where found position is stored.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpCentroidDiplex(
+                cy_stc_capsense_touch_t * newTouch,
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t sum;
+    uint32_t diffM;
+    uint32_t diffP;
+    uint32_t snsIndex;
+    const cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+    const uint8_t * ptrDpxTable;
+    uint32_t snsCount = ptrWdConfig->numSns;
+
+    uint32_t maxSum = 0u;
+    uint32_t maxDiff = 0u;
+    uint32_t maxIndex = CY_CAPSENSE_NO_LOCAL_MAX;
+    uint32_t threshold = ptrWdConfig->ptrWdContext->fingerTh;
+    int32_t numerator = 0;
+    int32_t denominator = 0;
+    uint32_t multiplier;
+    uint32_t offset;
+
+    threshold -= ptrWdConfig->ptrWdContext->hysteresis;
+    ptrDpxTable = ptrWdConfig->ptrDiplexTable;
+
+    /* Find maximum signal */
+    ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+    for (snsIndex = 0u; snsIndex < snsCount; snsIndex++)
+    {
+        if (maxDiff < ptrSnsCxt->diff)
+        {
+            maxDiff = ptrSnsCxt->diff;
+        }
+        ptrSnsCxt++;
+    }
+
+    /* Find sensor index with maximum sum ([i-1],[i],[i+1]) including diplex part */
+    ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+    for (snsIndex = 0u; snsIndex < (snsCount << 1u); snsIndex++)
+    {
+        /* Potential maximum */
+        if (maxDiff == ptrSnsCxt[ptrDpxTable[snsIndex]].diff)
+        {
+            /* Get sum of differences around maximum */
+            diffM = (snsIndex > 0u) ? ptrSnsCxt[ptrDpxTable[snsIndex - 1u]].diff : 0u;
+            diffP = (snsIndex < ((snsCount << 1u) - 1u)) ? ptrSnsCxt[ptrDpxTable[snsIndex + 1u]].diff : 0u;
+            sum = ptrSnsCxt[ptrDpxTable[snsIndex]].diff + diffM + diffP;
+            if ((diffM < threshold) && (diffP < threshold))
+            {
+                sum = 0u;
+            }
+            if (maxSum < sum)
+            {
+                /* New maximum */
+                maxIndex = snsIndex;
+                maxSum = sum;
+                numerator = (int32_t)diffP - (int32_t)diffM;
+            }
+        }
+    }
+
+    if ((maxIndex != CY_CAPSENSE_NO_LOCAL_MAX) && (maxSum > 0u))
+    {
+        multiplier = (uint32_t)ptrWdConfig->xResolution << 8u;
+        /* Calculate position */
+        if (0u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CALC_METHOD_MASK))
+        {
+            multiplier /= ((snsCount << 1u) - 1u);
+            offset = 0u;
+        }
+        else
+        {
+            multiplier /= (snsCount << 1u);
+            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 = (uint16_t)(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
+    }
+    else
+    {
+        newTouch->numPosition = CY_CAPSENSE_POSITION_NONE;
+    }
+}
+#endif /*((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_DIPLEX_SLIDER_EN) ||\
+          (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_DIPLEX_SLIDER_EN)) */
+
+
+#if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_LINEAR_SLIDER_EN) ||\
+    (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_LINEAR_SLIDER_EN))
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpCentroidLinear
+****************************************************************************//**
+*
+* Finds touch position of a Linear slider widget.
+*
+* In scope of position searching this function finds the local maximum with the
+* highest raw count. If such maximums are more than one, then the maximum with
+* bigger sum of neighboring sensors is taken for further processing. Then the position
+* is calculated using centroid algorithm with three sensors.
+*
+* This function does not detect two or more touches.
+*
+* \param newTouch
+* The pointer to the touch structure where the found position is stored.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpCentroidLinear(
+                cy_stc_capsense_touch_t * newTouch,
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t snsIndex = 0u;
+    uint32_t snsCount = ptrWdConfig->numSns;
+
+    uint32_t diffM;
+    uint32_t diffP;
+    uint32_t sum = 0u;
+    uint32_t maxSum = 0u;
+    uint32_t maxDiff = 0u;
+    uint32_t maxIndex = CY_CAPSENSE_NO_LOCAL_MAX;
+    const cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+    int32_t numerator = 0;
+    int32_t denominator = 0;
+    uint32_t multiplier;
+    uint32_t offset;
+
+    if(snsCount < CY_CAPSENSE_LINEAR_SLIDER_MIN_SNS_COUNT)
+    {
+        snsCount = CY_CAPSENSE_LINEAR_SLIDER_MIN_SNS_COUNT;
+    }
+
+    if (1u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_NUMBER_MASK))
+    {
+        /* Find maximum signal */
+        ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+        for (snsIndex = 0u; snsIndex < snsCount; snsIndex++)
+        {
+            if (ptrSnsCxt->diff > maxDiff)
+            {
+                maxDiff = ptrSnsCxt->diff;
+            }
+            ptrSnsCxt++;
+        }
+
+        /* Find index of sensor with maximum signal */
+        ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+        for (snsIndex = 0u; snsIndex < snsCount; snsIndex++)
+        {
+            /* Potential maximum */
+            if (maxDiff == ptrSnsCxt->diff)
+            {
+                /* Get sum of differences around maximum */
+                diffM = (snsIndex > 0u) ? (ptrSnsCxt - 1u)->diff : 0u;
+                diffP = (snsIndex < (snsCount - 1u)) ? (ptrSnsCxt + 1u)->diff : 0u;
+                sum = ptrSnsCxt->diff + diffM + diffP;
+                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->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 = (uint16_t)(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
+        }
+        else
+        {
+            newTouch->numPosition = CY_CAPSENSE_POSITION_NONE;
+        }
+    }
+    else
+    {
+        /* This is a place holder for local maximum searching when number of centroids could be more than one */
+    }
+}
+#endif /* ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_LINEAR_SLIDER_EN) ||\
+           (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_LINEAR_SLIDER_EN)) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_RADIAL_SLIDER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpCentroidRadial
+****************************************************************************//**
+*
+* Finds touch position of a Radial slider widget.
+*
+* In scope of position searching this function finds the local maximum with the
+* highest raw count. If such maximums are more than one, then the maximum with
+* bigger sum of neighboring sensors is taken for further processing. Then the position
+* is calculated using centroid algorithm with three sensors.
+*
+* This function does not detect two or more touches.
+*
+* \param newTouch
+* The pointer to the touch structure where found position is stored.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpCentroidRadial(
+                cy_stc_capsense_touch_t * newTouch,
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t snsIndex = 0u;
+    uint32_t snsCount = ptrWdConfig->numSns;
+
+    uint32_t diffM;
+    uint32_t diffP;
+    uint32_t sum = 0u;
+    uint32_t maxSum = 0u;
+    uint32_t maxDiff = 0u;
+    uint32_t maxIndex = CY_CAPSENSE_NO_LOCAL_MAX;
+    const cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+    int32_t numerator = 0;
+    int32_t denominator = 0;
+    uint32_t multiplier;
+
+    if (1u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_NUMBER_MASK))
+    {
+        /* Find maximum signal */
+        ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+        for (snsIndex = 0u; snsIndex < snsCount; snsIndex++)
+        {
+            if (ptrSnsCxt->diff > maxDiff)
+            {
+                maxDiff = ptrSnsCxt->diff;
+            }
+            ptrSnsCxt++;
+        }
+
+        /* Find index of sensor with maximum signal */
+        ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+        for (snsIndex = 0u; snsIndex < snsCount; snsIndex++)
+        {
+            /* Potential maximum */
+            if (maxDiff == ptrSnsCxt->diff)
+            {
+                /* Get sum of differences around maximum */
+                diffM = (snsIndex > 0u) ? (ptrSnsCxt - 1u)->diff : ptrWdConfig->ptrSnsContext[snsCount - 1u].diff;
+                diffP = (snsIndex < (snsCount - 1u)) ? (ptrSnsCxt + 1u)->diff : ptrWdConfig->ptrSnsContext[0u].diff;
+                sum = ptrSnsCxt->diff + diffM + diffP;
+                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->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 = (uint16_t)(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
+        }
+        else
+        {
+            newTouch->numPosition = CY_CAPSENSE_POSITION_NONE;
+        }
+    }
+    else
+    {
+        /* This is a place holder for local maximum searching when number of centroids could be more than one */
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_RADIAL_SLIDER_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpCentroidTouchpad
+****************************************************************************//**
+*
+* Finds touch position of a CSD Touchpad widget.
+*
+* In scope of position searching this function finds the local maximum with the
+* highest raw count. If such maximums are more than one, then the maximum with
+* bigger sum of neighboring sensors is taken for further processing. Then the position
+* is calculated using centroid algorithm with three sensors.
+*
+* This function does not detect two or more touches.
+*
+* \param newTouch
+* The pointer to the touch structure where found position is stored.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpCentroidTouchpad(
+                cy_stc_capsense_touch_t * newTouch,
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t snsIndex = 0u;
+    uint32_t snsCount = ptrWdConfig->numSns;
+    uint32_t colCount = ptrWdConfig->numCols;
+    uint32_t rowCount = ptrWdConfig->numRows;
+
+    uint32_t diffM;
+    uint32_t diffP;
+    uint32_t sum = 0u;
+    uint32_t maxSum = 0u;
+    uint32_t maxDiff = 0u;
+    uint32_t maxIndex = CY_CAPSENSE_NO_LOCAL_MAX;
+    const cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+    int32_t numerator = 0;
+    int32_t denominator = 0;
+    uint32_t multiplier;
+    uint32_t offset;
+
+    if(CY_CAPSENSE_TOUCHPAD_MIN_COL_SNS_COUNT > colCount)
+    {
+        colCount = CY_CAPSENSE_TOUCHPAD_MIN_COL_SNS_COUNT;
+    }
+
+    if(CY_CAPSENSE_TOUCHPAD_MIN_ROW_SNS_COUNT > rowCount)
+    {
+        rowCount = CY_CAPSENSE_TOUCHPAD_MIN_ROW_SNS_COUNT;
+    }
+
+    if (1u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_NUMBER_MASK))
+    {
+        /***********************************************************************
+        * X Axis (Cols)
+        ***********************************************************************/
+        sum = 0u;
+        maxSum = 0u;
+        maxDiff = 0u;
+        /* Find maximum signal */
+        ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+        for (snsIndex = 0u; snsIndex < colCount; snsIndex++)
+        {
+            if (ptrSnsCxt->diff > maxDiff)
+            {
+                maxDiff = ptrSnsCxt->diff;
+            }
+            ptrSnsCxt++;
+        }
+
+        /* Find index of sensor with maximum signal */
+        ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+        for (snsIndex = 0u; snsIndex < colCount; snsIndex++)
+        {
+            /* Potential maximum */
+            if (maxDiff == ptrSnsCxt->diff)
+            {
+                /* Get sum of differences around maximum */
+                diffM = (snsIndex > 0u) ? (ptrSnsCxt - 1u)->diff : 0u;
+                diffP = (snsIndex < (colCount - 1u)) ? (ptrSnsCxt + 1u)->diff : 0u;
+                sum = ptrSnsCxt->diff + diffM + diffP;
+                /* Check whether 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->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 = (uint16_t)(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
+        }
+        else
+        {
+            newTouch->numPosition = CY_CAPSENSE_POSITION_NONE;
+        }
+
+        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++)
+            {
+                if (ptrSnsCxt->diff > maxDiff)
+                {
+                    maxDiff = ptrSnsCxt->diff;
+                }
+                ptrSnsCxt++;
+            }
+
+            /* Find index of sensor with maximum signal */
+            ptrSnsCxt = &ptrWdConfig->ptrSnsContext[colCount];
+            for (snsIndex = 0u; snsIndex < rowCount; snsIndex++)
+            {
+                /* Potential maximum */
+                if (maxDiff == ptrSnsCxt->diff)
+                {
+                    /* 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 = (uint16_t)(((uint32_t)denominator + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
+            }
+            else
+            {
+                newTouch->numPosition = CY_CAPSENSE_POSITION_NONE;
+            }
+        }
+    }
+    else
+    {
+        /* This is a place holder for local maximum searching when number of centroids could be more than one */
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN) */
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_ADVANCED_CENTROID_5X5_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpAdvancedCentroidTouchpad
+****************************************************************************//**
+*
+* Finds touch position of a CSD touchpad widget using an advanced centroid
+* algorithm.
+*
+* This function is able to detect two touch positions using a centroid algorithm
+* with matrix 5*5 of sensors and virtual sensors on the edges.
+*
+* \param newTouch
+* The pointer to the touch structure where the found position is stored.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpAdvancedCentroidTouchpad(
+                cy_stc_capsense_touch_t * newTouch,
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t i;
+    const cy_stc_capsense_sensor_context_t * ptrSnsIndex = ptrWdConfig->ptrSnsContext;
+    uint16_t * ptrDiffIndex = ptrWdConfig->ptrCsdTouchBuffer;
+    cy_stc_capsense_advanced_centroid_config_t advCfg;
+
+    advCfg.fingerTh = ptrWdConfig->ptrWdContext->fingerTh;
+    advCfg.penultimateTh = ptrWdConfig->advConfig.penultimateTh;
+    advCfg.virtualSnsTh = ptrWdConfig->advConfig.virtualSnsTh;
+    advCfg.resolutionX = ptrWdConfig->xResolution;
+    advCfg.resolutionY = ptrWdConfig->yResolution;
+    advCfg.snsCountX = ptrWdConfig->numCols;
+    advCfg.snsCountY = ptrWdConfig->numRows;
+    advCfg.crossCouplingTh = ptrWdConfig->advConfig.crossCouplingTh;
+    advCfg.edgeCorrectionEn = 0u;
+    advCfg.twoFingersEn = 0u;
+
+    if ((ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_NUMBER_MASK) > CY_CAPSENSE_POSITION_ONE)
+    {
+        advCfg.twoFingersEn = 1u;
+    }
+    if (0u != (ptrWdConfig->centroidConfig & CY_CAPSENSE_EDGE_CORRECTION_MASK))
+    {
+        advCfg.edgeCorrectionEn = 1u;
+    }
+    for (i = 0u; i < ptrWdConfig->numSns; i++)
+    {
+        ptrDiffIndex[i] = ptrSnsIndex[i].diff;
+    }
+
+    Cy_CapSense_AdvancedCentroidGetTouchCoordinates_Lib(
+                &advCfg,
+                ptrWdConfig->ptrCsdTouchBuffer,
+                newTouch);
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_ADVANCED_CENTROID_5X5_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpFindLocalMaxDd
+****************************************************************************//**
+*
+* Finds up to five local maximums for CSX Touchpad.
+*
+* This function takes an array of differences of the specified widget and
+* finds up to five local maximums. The found maximums are stored in the CSX buffer
+* ptrCsxTouchBuffer \ref cy_stc_capsense_csx_touch_buffer_t.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+void Cy_CapSense_DpFindLocalMaxDd(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    const cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+    const cy_stc_capsense_sensor_context_t * ptrSnsCxt =  ptrWdConfig->ptrSnsContext;
+    uint32_t thresholdOff = (uint32_t)ptrWdCxt->fingerTh - ptrWdCxt->hysteresis;
+    uint32_t thresholdOn = (uint32_t)ptrWdCxt->fingerTh + ptrWdCxt->hysteresis;
+    uint16_t currDiff;
+    uint8_t rx;
+    uint8_t tx;
+    uint8_t snsShift;
+    uint8_t lastRx = ptrWdConfig->numCols - 1u;
+    uint8_t lastTx = ptrWdConfig->numRows - 1u;
+    uint32_t proceed = 0u;
+    uint32_t touchNum = 0u;
+    cy_stc_capsense_position_t * ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[0u];
+
+    for (rx = CY_CAPSENSE_CSX_TOUCHPAD_MAX_PEAKS; rx-- > 0u;)
+    {
+        ptrNewPeak[rx].id = CY_CAPSENSE_CSX_TOUCHPAD_ID_UNDEFINED;
+    }
+
+    ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[0u];
+    /* Go through all Rx electrodes */
+    for (rx = 0u; rx <= lastRx; rx++)
+    {
+        /*
+        * Go through all Tx and RX (changed above) electrodes intersections
+        * and check whether the local maximum requirement is met.
+        */
+        for (tx = 0u; tx <= lastTx; tx++)
+        {
+            proceed = 0u;
+            currDiff = ptrSnsCxt->diff;
+            if (thresholdOff <= (uint32_t)currDiff)
+            {
+                /*
+                * Check local maximum requirement: Comparing raw count
+                * of a local maximum candidate with raw counts of sensors
+                * from the previous row.
+                */
+                if (rx > 0u)
+                {
+                    /* Check the sensor from the previous row and the next column */
+                    snsShift = lastTx;
+                    if ((tx < lastTx) && (currDiff <= (ptrSnsCxt - snsShift)->diff))
+                    {
+                        proceed = 1u;
+                    }
+                    if (0u == proceed)
+                    {
+                        /* Check the sensor from the previous row and the same column */
+                        snsShift++;
+                        if (currDiff <= (ptrSnsCxt - snsShift)->diff)
+                        {
+                            proceed = 1u;
+                        }
+                    }
+                    if (0u == proceed)
+                    {
+                        /* Check the sensor from the previous row and the previous column */
+                        snsShift++;
+                        if ((tx > 0u) && (currDiff <= (ptrSnsCxt - snsShift)->diff))
+                        {
+                            proceed = 1u;
+                        }
+                    }
+                }
+                /*
+                * Check local maximum requirement: Comparing raw count
+                * of a local maximum candidate with raw counts of sensors
+                * from the next row.
+                */
+                if ((0u == proceed) && (rx < lastRx))
+                {
+                    /* Check the sensor from the next row and the next column */
+                    snsShift = lastTx + 2u;
+                    if ((tx < lastTx) && (currDiff < (ptrSnsCxt + snsShift)->diff))
+                    {
+                        proceed = 1u;
+                    }
+                    if (0u == proceed)
+                    {
+                        /* Check the sensor from the next row and the same column */
+                        snsShift--;
+                        if (currDiff < (ptrSnsCxt + snsShift)->diff)
+                        {
+                            proceed = 1u;
+                        }
+                    }
+                    if (0u == proceed)
+                    {
+                        /* Check the sensor from the next row and the previous column */
+                        snsShift--;
+                        if ((tx > 0u) && (currDiff < (ptrSnsCxt + snsShift)->diff))
+                        {
+                            proceed = 1u;
+                        }
+                    }
+                }
+                /*
+                * Check local maximum requirement: Comparing raw count
+                * of a local maximum candidate with raw counts of sensors
+                * from the same row and the next column. */
+                if ((0u == proceed) && (tx < lastTx))
+                {
+                    if (currDiff < (ptrSnsCxt + 1u)->diff)
+                    {
+                        proceed = 1u;
+                    }
+                }
+                /* Check the sensor from the same row and the previous column */
+                if ((0u == proceed) && (tx > 0u))
+                {
+                    if (currDiff <= (ptrSnsCxt - 1u)->diff)
+                    {
+                        proceed = 1u;
+                    }
+                }
+                /* Add local maximum to the touch structure if there is room. */
+                if (0u == proceed)
+                {
+                    ptrNewPeak->x = rx;
+                    ptrNewPeak->y = tx;
+                    if (currDiff < thresholdOn)
+                    {
+                        ptrNewPeak->id |= CY_CAPSENSE_CSX_TOUCHPAD_ID_ON_FAIL;
+                    }
+                    touchNum++;
+                    ptrNewPeak++;
+                }
+            }
+            ptrSnsCxt++;
+            if (touchNum >= CY_CAPSENSE_CSX_TOUCHPAD_MAX_PEAKS)
+            {
+                break;
+            }
+        }
+        if (touchNum >= CY_CAPSENSE_CSX_TOUCHPAD_MAX_PEAKS)
+        {
+            break;
+        }
+    }
+    ptrWdConfig->ptrCsxTouchBuffer->newPeakNumber = (uint8_t)touchNum;
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/* CY_ID633 */
+#if defined(__ICCARM__)
+    #pragma optimize=none
+#endif /* (__ICCARM__) */
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpCalcTouchPadCentroid
+****************************************************************************//**
+*
+* Calculates the position for each local maximum using the 3x3 algorithm.
+*
+* This function calculates position coordinates of found local maximums.
+* The found positions are stored in the CSX buffer ptrCsxTouchBuffer
+* \ref cy_stc_capsense_csx_touch_buffer_t.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+void Cy_CapSense_DpCalcTouchPadCentroid(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    const cy_stc_capsense_sensor_context_t * ptrSnsCxt =  ptrWdConfig->ptrSnsContext;
+    uint8_t number;
+    uint8_t i;
+    uint8_t j;
+    uint32_t lastRx = (uint32_t)ptrWdConfig->numCols - 1u;
+    uint32_t lastTx = (uint32_t)ptrWdConfig->numRows - 1u;
+    uint16_t centroid[3u][3u];
+    int32_t weightedSumX;
+    int32_t weightedSumY;
+    uint32_t totalSum;
+    uint32_t multiplierX;
+    uint32_t offsetX;
+    uint32_t multiplierY;
+    uint32_t offsetY;
+    uint32_t touchNum = ptrWdConfig->ptrCsxTouchBuffer->newPeakNumber;
+    cy_stc_capsense_position_t * ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[0];
+
+    for(number = 0u; number < touchNum; number++)
+    {
+        /* Set the sensor pointer to the local maximum sensor */
+        ptrSnsCxt =  ptrWdConfig->ptrSnsContext;
+        ptrSnsCxt += (ptrNewPeak->y + (ptrNewPeak->x * ptrWdConfig->numRows));
+
+        /* Prepare 3x3 centroid two dimensional array */
+        /* Fill each row */
+        for (i = 0u; i < CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_LENGTH; i++)
+        {
+            /*
+            * The first  condition could be valid only when local max on the first row (0 row) of Touchpad
+            * The second condition could be valid only when local max on the last row of Touchpad
+            * Then corresponding row (zero or the last) of 3x3 array is initialized to 0u
+            */
+            if (((((int32_t)ptrNewPeak->x - 1) + (int32_t)i) < 0) ||
+                ((((int32_t)ptrNewPeak->x - 1) + (int32_t)i) > (int32_t)lastRx))
+            {
+                centroid[CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_PREVIOUS][i] = 0u;
+                centroid[CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_CENTER][i] = 0u;
+                centroid[CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_NEXT][i] = 0u;
+            }
+            else
+            {
+                /* Fill each column */
+                for (j = 0u; j < CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_LENGTH; j++)
+                {
+                    /*
+                    * The first condition could be valid only when local max
+                    * on the first column (0 row) of Touchpad. The second
+                    * condition could be valid only when local max on the last
+                    * column of Touchpad. Then corresponding column (zero or
+                    * the last) of 3x3 array is initialized to 0u.
+                    */
+                    if (((((int32_t)ptrNewPeak->y - 1) + (int32_t)j) < 0) ||
+                        ((((int32_t)ptrNewPeak->y - 1) + (int32_t)j) > (int32_t)lastTx))
+                    {
+                        centroid[j][i] = 0u;
+                    }
+                    else
+                    {
+                        centroid[j][i] = (uint16_t)(ptrSnsCxt + (((i - 1u) * ptrWdConfig->numRows) + (j - 1u)))->diff; //MISRA?
+                    }
+                }
+            }
+        }
+
+        weightedSumX = 0;
+        weightedSumY = 0;
+        totalSum = 0u;
+
+        /* Calculate centroid */
+        for (i = 0u; i < CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_LENGTH; i++)
+        {
+            for (j = 0u; j < CY_CAPSENSE_CSX_TOUCHPAD_CENTROID_LENGTH; j++)
+            {
+                totalSum += centroid[i][j];
+                weightedSumX += (int32_t)centroid[i][j] * ((int32_t)j - 1);
+                weightedSumY += (int32_t)centroid[i][j] * ((int32_t)i - 1);
+            }
+        }
+
+        /* The X position is calculated.
+        * The weightedSumX value depends on a finger position shifted regarding
+        * the X electrode (ptrNewTouches.x).
+        * The multiplier ptrWdConfig->xCentroidMultiplier is a short from:
+        * CY_CAPSENSE_TOUCHPAD0_X_RESOLUTION * 256u) / (CY_CAPSENSE_TOUCHPAD0_NUM_RX - CONFIG))
+        * where CONFIG = 0 or 1 depends on TouchpadMultiplerMethod parameter.
+        */
+        /* Calculate position */
+        multiplierX = (uint32_t)ptrWdConfig->xResolution << 8u;
+        multiplierY = (uint32_t)ptrWdConfig->yResolution << 8u;
+        if (0u == (ptrWdConfig->centroidConfig & CY_CAPSENSE_CALC_METHOD_MASK))
+        {
+            multiplierX /= lastRx;
+            offsetX = 0u;
+            multiplierY /= lastTx;
+            offsetY = 0u;
+        }
+        else
+        {
+            multiplierX /= (lastRx + 1u);
+            offsetX = multiplierX >> 1u;
+            multiplierY /= (lastTx + 1u);
+            offsetY = multiplierY >> 1u;
+        }
+
+        weightedSumX = ((weightedSumX * (int32_t)multiplierX) / (int32_t)totalSum) +
+                        ((((int32_t)ptrNewPeak->x) * (int32_t)multiplierX) + (int32_t)offsetX);
+
+        /* The X position is rounded to the nearest integer value and normalized to the resolution range */
+        ptrNewPeak->x = (uint16_t)(((uint32_t)weightedSumX + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
+        /* The Y position is calculated.
+        * The weightedSumY value depends on a finger position shifted regarding the Y electrode (ptrWdConfig->ptrNewTouches.y)
+        * The multiplier ptrWdConfig->yCentroidMultiplier is a short from:
+        * CY_CAPSENSE_TOUCHPAD0_Y_RESOLUTION * 256u) / (CY_CAPSENSE_TOUCHPAD0_NUM_TX - CONFIG))
+        * where CONFIG = 0 or 1 depends on TouchpadMultiplerMethod parameter
+        */
+        weightedSumY = ((weightedSumY * (int32_t)multiplierY) / (int32_t)totalSum) +
+                        ((((int32_t)ptrNewPeak->y) * (int32_t)multiplierY) + (int32_t)offsetY);
+
+        /* The Y position is rounded to the nearest integer value and normalized to the resolution range */
+        ptrNewPeak->y = (uint16_t)(((uint32_t)weightedSumY + CY_CAPSENSE_CENTROID_ROUND_VALUE) >> 8u);
+
+        /* The z value is a sum of raw counts of sensors that form 3x3 matrix with a local maximum in the center */
+        ptrNewPeak->z = (uint8_t)(totalSum >> CY_CAPSENSE_CSX_TOUCHPAD_Z_SHIFT);
+        ptrNewPeak++;
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpTouchTracking
+****************************************************************************//**
+*
+* Tracks touches.
+*
+* This function tracks the found touches:
+* - associates them with previous touches applying the Hungarian algorithm.
+* - applies debounce filters.
+* - suppresses excessive touches.
+*
+* The final touch data are stored in the CSX buffer ptrCsxTouchBuffer
+* \ref cy_stc_capsense_csx_touch_buffer_t. This function should be called
+* each scan cycle even when touch is not detected.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+void Cy_CapSense_DpTouchTracking(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t i;
+
+    const cy_stc_capsense_position_t * ptrNewPeak;
+    cy_stc_capsense_position_t * ptrOldPeak;
+
+    uint32_t newTouchNum = ptrWdConfig->ptrCsxTouchBuffer->newPeakNumber;
+    uint32_t oldTouchNum = ptrWdConfig->ptrCsxTouchHistory->oldPeakNumber;
+
+    int8_t * fingerPosIndex = &ptrWdConfig->ptrCsxTouchBuffer->fingerPosIndexMap[0u];
+
+    if ((0u != newTouchNum) || (0u != oldTouchNum))
+    {
+        /* Initialize variables */
+        ptrWdConfig->ptrCsxTouchBuffer->newActiveIdsMask = 0u;
+        /* Getting active touch IDs from previous scan */
+        ptrWdConfig->ptrCsxTouchHistory->oldActiveIdsMask = 0u;
+
+        ptrOldPeak = &ptrWdConfig->ptrCsxTouchHistory->oldPeak[0u];
+        for (i = 0u; i < oldTouchNum; i++)
+        {
+            ptrWdConfig->ptrCsxTouchHistory->oldActiveIdsMask |= (uint8_t)(1u << ptrOldPeak->id);
+            ptrOldPeak++;
+        }
+
+        if (0u < newTouchNum)
+        {
+            if (0u == oldTouchNum)
+            {
+                /* If the previous touch tracking had not any touches */
+                for (i = 0u; i < newTouchNum; i++)
+                {
+                    /* Initializes a new touch, set ID to next value and Age to 0 */
+                    Cy_CapSense_NewTouch(i, ptrWdConfig);
+                }
+            }
+            else
+            {
+                /* Don't call Hungarian for 1 current and 1 previous touch */
+                fingerPosIndex[0u] = 0;
+                if ((1u != newTouchNum) || (1u != oldTouchNum))
+                {
+                    Cy_CapSense_Hungarian(ptrWdConfig);
+                }
+                /* General case */
+                if (newTouchNum >= oldTouchNum)
+                {
+                    ptrOldPeak = &ptrWdConfig->ptrCsxTouchHistory->oldPeak[0u];
+                    for (i = 0u; i < oldTouchNum; i++)
+                    {
+                        if (ptrWdConfig->ptrCsxTouchHistory->velocity < Cy_CapSense_CalcDistance((uint32_t)fingerPosIndex[i], i, ptrWdConfig))
+                        {
+                            /* Set new ID and reset Age */
+                            Cy_CapSense_NewTouch((uint32_t)fingerPosIndex[i], ptrWdConfig);
+                        }
+                        else
+                        {
+                            /* Set ID to previous value and increase Age */
+                            ptrWdConfig->ptrCsxTouchBuffer->newActiveIdsMask |= (uint8_t)(1u << (ptrOldPeak->id));
+                            Cy_CapSense_TransferTouch((uint32_t)fingerPosIndex[i], i, ptrWdConfig);
+                        }
+                        ptrOldPeak++;
+                    }
+                }
+                else
+                {
+                    ptrOldPeak = &ptrWdConfig->ptrCsxTouchHistory->oldPeak[0u];
+                    for (i = 0u; i < newTouchNum; i++)
+                    {
+                        if (ptrWdConfig->ptrCsxTouchHistory->velocity < Cy_CapSense_CalcDistance(i, (uint32_t)fingerPosIndex[i], ptrWdConfig))
+                        {
+                            /* Set new ID and reset Age. */
+                            Cy_CapSense_NewTouch(i, ptrWdConfig);
+                        }
+                        else
+                        {
+                            /* Set ID to previous value and increase Age. */
+                            ptrWdConfig->ptrCsxTouchBuffer->newActiveIdsMask |= (uint8_t)(1u << (ptrOldPeak->id));
+                            Cy_CapSense_TransferTouch(i, (uint32_t)fingerPosIndex[i], ptrWdConfig);
+                        }
+                        ptrOldPeak++;
+                    }
+                }
+                /* Added new fingers, they need to assign ID */
+                if (newTouchNum > oldTouchNum)
+                {
+                    /* Search new fingers */
+                    ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[0u];
+                    for (i = 0u; i < newTouchNum; i++)
+                    {
+                        /* New finger found */
+                        if (0u != (ptrNewPeak->id & CY_CAPSENSE_CSX_TOUCHPAD_ID_UNDEFINED))
+                        {
+                            Cy_CapSense_NewTouch(i, ptrWdConfig);
+                        }
+                        ptrNewPeak++;
+                    }
+                }
+            }
+
+            Cy_CapSense_TouchDownDebounce(ptrWdConfig);
+        }
+
+        Cy_CapSense_SortByAge(ptrWdConfig);
+        newTouchNum = ptrWdConfig->ptrCsxTouchBuffer->newPeakNumber;
+
+        /* Store new touches as old touches */
+        ptrWdConfig->ptrCsxTouchHistory->oldPeakNumber = (uint8_t)newTouchNum;
+        ptrWdConfig->ptrCsxTouchHistory->oldActiveIdsMask = ptrWdConfig->ptrCsxTouchBuffer->newActiveIdsMask;
+        ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[0u];
+        ptrOldPeak = &ptrWdConfig->ptrCsxTouchHistory->oldPeak[0u];
+        for (i = newTouchNum; i-- > 0u;)
+        {
+            Cy_CapSense_CopyTouchRecord(ptrOldPeak, ptrNewPeak);
+            ptrNewPeak++;
+            ptrOldPeak++;
+        }
+    }
+ }
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_TransferTouch
+****************************************************************************//**
+*
+* Transfers a touch from history array into active current array.
+*
+* This function transfers touch specified by oldIndex from history touch array
+* by copying its ID, increments age and decrements debounce (if debounce > 0)
+* parameters into currently active touch structure
+*
+* \param newIndex
+* The touch index of touch array in the active touch structure.
+*
+* \param oldIndex
+* The touch index of touch array in the history touch structure.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_TransferTouch(
+                uint32_t newIndex,
+                uint32_t oldIndex,
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t touchId;
+    uint32_t touchAge;
+    uint32_t touchDebounce;
+    cy_stc_capsense_position_t * ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[newIndex];
+    const cy_stc_capsense_position_t * ptrOldPeak = &ptrWdConfig->ptrCsxTouchHistory->oldPeak[oldIndex];
+
+    touchId = (uint32_t)ptrOldPeak->id & CY_CAPSENSE_CSX_TOUCHPAD_ID_MASK;
+    touchAge = ((uint32_t)ptrOldPeak->z & CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK) >> CY_CAPSENSE_CSX_TOUCHPAD_BYTE_SHIFT;
+    touchDebounce = ((uint32_t)ptrOldPeak->id & CY_CAPSENSE_CSX_TOUCHPAD_DEBOUNCE_MASK) >> CY_CAPSENSE_CSX_TOUCHPAD_BYTE_SHIFT;
+
+    /* Increase AGE by 1 if possible */
+    if (touchAge < CY_CAPSENSE_CSX_TOUCHPAD_MAX_AGE)
+    {
+        touchAge++;
+    }
+    /* Decrement Debounce counter if possible */
+    if (touchDebounce > 0u)
+    {
+        touchDebounce--;
+    }
+
+    ptrNewPeak->id = (uint16_t)(touchId | (uint16_t)(touchDebounce << CY_CAPSENSE_CSX_TOUCHPAD_BYTE_SHIFT));
+    ptrNewPeak->z &= (uint16_t)~CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK;
+    ptrNewPeak->z |= (uint16_t)(touchAge << CY_CAPSENSE_CSX_TOUCHPAD_BYTE_SHIFT);
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_NewTouch
+****************************************************************************//**
+*
+* Set ID, age, and on debounce parameters for a new touch.
+*
+* If raw count is lower than the finger-On-Threshold,
+* then the corresponding touch is marked with CY_CAPSENSE_CSX_TOUCHPAD_ID_ON_FAIL
+* in the ID and will be deleted from the new touch structure in Cy_CapSense_SortByAge()
+* (new touch structure is reorganized in this case).
+*
+* \param newIndex
+* The touch index of touch array in the active touch structure.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_NewTouch(
+                uint32_t newIndex,
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t idx;
+    cy_stc_capsense_position_t * ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[newIndex];
+
+    /* Touch is not accepted */
+    if (0u == (ptrNewPeak->id & CY_CAPSENSE_CSX_TOUCHPAD_ID_ON_FAIL))
+    {
+        /* Create a bit map of ID's currently used and previously used and search for the new lowest ID */
+        idx = Cy_CapSense_GetLowestId(ptrWdConfig->ptrCsxTouchHistory->oldActiveIdsMask |
+                ptrWdConfig->ptrCsxTouchBuffer->newActiveIdsMask);
+
+        /* Indicate that ID is now taken */
+        ptrWdConfig->ptrCsxTouchBuffer->newActiveIdsMask |= (uint8_t)(1u << idx);
+
+        /* Set AGE */
+        ptrNewPeak->z &= (uint16_t)~CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK;
+        ptrNewPeak->z |= CY_CAPSENSE_CSX_TOUCHPAD_AGE_START;
+
+        /* Set ID and Debounce */
+        ptrNewPeak->id = (uint16_t)idx | (uint16_t)(((uint16_t)ptrWdConfig->ptrWdContext->onDebounce - 1u) << CY_CAPSENSE_CSX_TOUCHPAD_BYTE_SHIFT);
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_GetLowestId
+****************************************************************************//**
+*
+* Returns the lowest available free touch ID.
+*
+* \param idMask
+* The mask of IDs used in active and history touch structures.
+*
+* \return
+* Returns the lowest available touch ID. If no ID is available,
+* CY_CAPSENSE_CSX_TOUCHPAD_ID_ABSENT is returned.
+*
+*******************************************************************************/
+__STATIC_INLINE uint8_t Cy_CapSense_GetLowestId(uint8_t idMask)
+{
+    uint32_t idx;
+    uint32_t touchId = CY_CAPSENSE_CSX_TOUCHPAD_ID_ABSENT;
+    uint32_t idMaskLocal = (uint32_t)idMask;
+
+    /* Search for the lowest available ID */
+    for (idx = CY_CAPSENSE_CSX_TOUCHPAD_ID_MIN; idx <= CY_CAPSENSE_CSX_TOUCHPAD_ID_MAX; idx++)
+    {
+        /* Determine whether the new ID is available */
+        if (0u == (idMaskLocal & 1u))
+        {
+            touchId = idx;
+            break;
+        }
+
+        idMaskLocal >>= 1u;
+    }
+
+    /* Return an indicator of failure */
+    return (uint8_t)(touchId);
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_TouchDownDebounce
+****************************************************************************//**
+*
+* Handles touchdown debouncing.
+*
+* Even if a new touch is detected, it is not considered as active until the
+* debounce counter has not reached zero. If the debounce counter has reached zero,
+* the touchdown mask is cleared. Otherwise the age of the new finger is cleared
+* (it is considered as not active).
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+__STATIC_INLINE void Cy_CapSense_TouchDownDebounce(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t i;
+    cy_stc_capsense_position_t * ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[0u];
+
+    for (i = 0u; i < ptrWdConfig->ptrCsxTouchBuffer->newPeakNumber; i++)
+    {
+        /* If it is a touchdown debouncing finger its age is set to zero */
+        if (0u != (ptrNewPeak->id & CY_CAPSENSE_CSX_TOUCHPAD_DEBOUNCE_MASK))
+        {
+            /* Set the age to zero - finger is not active */
+            ptrNewPeak->z &= (uint16_t)~CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK;
+        }
+        ptrNewPeak++;
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CalcDistance
+****************************************************************************//**
+*
+* Calculates squared distance between history and active touch structures
+* pointed by the input parameters.
+*
+* \param newIndex
+* The index of touch in the active touch structure.
+*
+* \param oldIndex
+* The index of touch in the history touch structure.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+* \return
+* Returns the squared distance.
+*
+*******************************************************************************/
+static uint32_t Cy_CapSense_CalcDistance(
+                uint32_t newIndex,
+                uint32_t oldIndex,
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    const cy_stc_capsense_position_t * ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[newIndex];
+    const cy_stc_capsense_position_t * ptrOldPeak = &ptrWdConfig->ptrCsxTouchHistory->oldPeak[oldIndex];
+
+    int32_t xDistance = (int32_t)(ptrOldPeak->x) - (int32_t)(ptrNewPeak->x);
+    int32_t yDistance = (int32_t)(ptrOldPeak->y) - (int32_t)(ptrNewPeak->y);
+
+    xDistance *= xDistance;
+    yDistance *= yDistance;
+
+    return ((uint32_t)xDistance + (uint32_t)yDistance);
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_Hungarian
+****************************************************************************//**
+*
+* Executes the Hungarian method on a distance map to track motion of two
+* touch sets (old touches vs new touches).
+*
+* This function uses the Hungarian method described in specification 001-63362.
+* There is no bound checking on the parameters. It is the calling function's
+* responsibility to ensure parameter validity.
+* The function output is a fingerPosIndexMap array stored in the CSX buffer
+* where associations between the previous and current touches are returned.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_Hungarian(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    cy_stc_capsense_csx_touch_buffer_t * ptrBuffer = ptrWdConfig->ptrCsxTouchBuffer;
+    /*
+    * Number of elements in column of distanceMap matrix. This value must
+    * be greater than or equal to 1.
+    */
+    int32_t * col = &ptrBuffer->colMap[0u];
+    /*
+    * Number of elements in row of distanceMap matrix. This value must be
+    * greater than or equal to colCount.
+    */
+    int32_t * row = &ptrBuffer->rowMap[0u];
+    int32_t * mins = &ptrBuffer->minsMap[0u];
+    int8_t * links = &ptrBuffer->linksMap[0u];
+    int8_t * visited = &ptrBuffer->visitedMap[0u];
+    int8_t * markIndices = &ptrBuffer->markIndicesMap[0u];
+    /*
+    * The 2-dimensional map of distances between the nodes in each
+    * coordinate set. The 1st index of distanceMap corresponds to nodes
+    * in the 1st coordinate data set, and the 2nd index of distanceMap
+    * corresponds to the 2nd coordinate data set. Each element in
+    * distanceMap is the square of the distance between the
+    * corresponding coordinates in the 1st and 2nd data set.
+    */
+    int32_t * distance = &ptrBuffer->distanceMap[0u];
+
+    int32_t delta = 0;
+    int32_t colValue = 0;
+    int32_t markedI = 0;
+    int32_t markedJ = 0;
+    int32_t i = 0;
+    int32_t iIndex = 0;
+    int32_t j = 0;
+    int32_t jIndex = 0;
+
+    uint32_t rowCount = ptrBuffer->newPeakNumber;
+    uint32_t colCount = ptrWdConfig->ptrCsxTouchHistory->oldPeakNumber;
+
+    /* Fill distance map */
+    if (rowCount >= colCount)
+    {
+        for (i = (int32_t)rowCount; i-- > 0; )
+        {
+            for (j = (int32_t)colCount; j-- > 0; )
+            {
+                distance[((uint32_t)i * CY_CAPSENSE_CSX_TOUCHPAD_MAX_PEAKS) + (uint32_t)j] = (int32_t)Cy_CapSense_CalcDistance((uint32_t)i, (uint32_t)j, ptrWdConfig);
+            }
+        }
+    }
+    else
+    {
+        for (i = (int32_t)colCount; i-- > 0;)
+        {
+            for (j = (int32_t)rowCount; j-- > 0;)
+            {
+                distance[((uint32_t)i * CY_CAPSENSE_CSX_TOUCHPAD_MAX_PEAKS) + (uint32_t)j] = (int32_t)Cy_CapSense_CalcDistance((uint32_t)j, (uint32_t)i, ptrWdConfig);
+            }
+        }
+        colValue = (int32_t)colCount;
+        colCount = rowCount;
+        rowCount = (uint32_t)colValue;
+    }
+
+    (void)memset(col, 0, (uint32_t)colCount * 4u);
+
+    /* Initialize row and markIndices arrays */
+    for (i = (int32_t)rowCount; i-- > 0;)
+    {
+        row[i] = 0;
+        markIndices[i] = -1;
+    }
+
+    /* Go through all columns */
+    for (i = (int32_t)colCount; i-- > 0;)
+    {
+        /* Initialize visited, links, mins arrays. They are used for every column */
+        for (iIndex = (int32_t)rowCount; iIndex-- > 0;)
+        {
+            visited[iIndex] = 0;
+            links[iIndex] = -1;
+            mins[iIndex] = INT32_MAX;
+        }
+
+        /* Next two variables are used to mark column and row */
+        markedI = i;
+        markedJ = -1;
+
+        while (markedI != -1)
+        {
+            j = -1;
+            colValue = col[markedI];
+
+            /* Go through all rows */
+            for (jIndex = (int32_t)rowCount; jIndex-- > 0;)
+            {
+                if (visited[jIndex] == 0)
+                {
+                    delta = distance[((uint32_t)jIndex * CY_CAPSENSE_CSX_TOUCHPAD_MAX_PEAKS) + (uint32_t)markedI] - row[jIndex] - colValue;
+
+                    /* Find the minimum element index in column i */
+                    if (mins[jIndex] > delta)
+                    {
+                        mins[jIndex] = delta;
+                        links[jIndex] = (int8_t)markedJ;
+                    }
+
+                    if ((j == -1) || (mins[jIndex] < mins[j]))
+                    {
+                        j = jIndex;
+                    }
+                }
+            }
+
+            if(j == -1)
+            {
+                j = 0;
+            }
+
+            delta = mins[j];
+
+            /* Go through all rows */
+            for (jIndex = (int32_t)rowCount; jIndex-- > 0;)
+            {
+                if (visited[jIndex] != 0)
+                {
+                    col[markIndices[jIndex]] += delta;
+                    row[jIndex] -= delta;
+                }
+                else
+                {
+                    mins[jIndex] -= delta;
+                }
+            }
+
+            col[i] +=  delta;
+
+            visited[j] = 1;
+            markedJ = j;
+            markedI = markIndices[j];
+        }
+
+        while (links[j] != -1)
+        {
+            markIndices[j] = markIndices[links[j]];
+            j = links[j];
+        }
+
+        markIndices[j] = (int8_t)i;
+    }
+
+    /* Provide an association between two sets of touches */
+    for (j = (int32_t)rowCount; j-- > 0;)
+    {
+        if (markIndices[j] != -1)
+        {
+            ptrBuffer->fingerPosIndexMap[markIndices[j]] = (int8_t)j;
+        }
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_SortByAge
+****************************************************************************//**
+*
+* Sorts the new touch array by:
+* 1. age (in decrementing order)
+* and
+* 2. id (in incrementing order) fields.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+__STATIC_INLINE void Cy_CapSense_SortByAge(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t i;
+    uint32_t j;
+    cy_stc_capsense_position_t tempPeak;
+    cy_stc_capsense_position_t * ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[0u];
+    cy_stc_capsense_position_t * ptrNewPeakJ;
+    uint32_t newTouchNum = ptrWdConfig->ptrCsxTouchBuffer->newPeakNumber;
+
+    /*
+     * Delete failed touch by coping (rewriting) the last touch content to the failed touch.
+     * If the last touch record is invalid, try the penultimate touch record and so on.
+     */
+    for (i = 0u; i < newTouchNum; i++)
+    {
+        if ((ptrNewPeak->id & CY_CAPSENSE_CSX_TOUCHPAD_ID_MASK) > CY_CAPSENSE_CSX_TOUCHPAD_ID_MAX)
+        {
+            for (j = (newTouchNum - 1u); j > i; j--)
+            {
+                /*
+                * Check the touch records from the last to the current.
+                * If the touch record is valid, then replace the current touch record.
+                */
+                ptrNewPeakJ = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[j];
+                if ((ptrNewPeakJ->id & CY_CAPSENSE_CSX_TOUCHPAD_ID_MASK) <= CY_CAPSENSE_CSX_TOUCHPAD_ID_MAX)
+                {
+                    Cy_CapSense_CopyTouchRecord(ptrNewPeak, ptrNewPeakJ);
+
+                    /* Finish the loop. The valid touch record is found and copied. */
+                    break;
+                }
+                else
+                {
+                    /* Decrement the number of touch records.
+                     * The last touch record is invalid - try the penultimate touch record.
+                     */
+                    newTouchNum--;
+                }
+            }
+
+            /* Decrement the number of touch records.
+             * The last touch record is valid and copied to the current position (i)
+             */
+            newTouchNum--;
+        }
+        ptrNewPeak++;
+    }
+
+    /* Set new number of touches */
+    ptrWdConfig->ptrCsxTouchBuffer->newPeakNumber = (uint8_t)newTouchNum;
+
+    ptrNewPeak = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[0u];
+    /* Sort new touches structure */
+    for (i = 0u; i < newTouchNum; i++)
+    {
+        for (j = (i + 1u); j < newTouchNum; j++)
+        {
+            ptrNewPeakJ = &ptrWdConfig->ptrCsxTouchBuffer->newPeak[j];
+            /* If next touches have higher age or lower id with the same age then swap touches */
+            if (((ptrNewPeak->z & CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK) < (ptrNewPeakJ->z & CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK)) ||
+                (((ptrNewPeak->z & CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK) == (ptrNewPeakJ->z & CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK)) && (ptrNewPeak->id > ptrNewPeakJ->id)))
+            {
+                /* Swap touches */
+                Cy_CapSense_CopyTouchRecord(&tempPeak, ptrNewPeak);
+                Cy_CapSense_CopyTouchRecord(ptrNewPeak, ptrNewPeakJ);
+                Cy_CapSense_CopyTouchRecord(ptrNewPeakJ, &tempPeak);
+            }
+        }
+        ptrNewPeak++;
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CopyTouchRecord
+****************************************************************************//**
+*
+* Copies content from the source touch structure to the destination touch structure.
+*
+* \param destination
+* The pointer to the destination touch structure \ref cy_stc_capsense_position_t.
+*
+* \param source
+* The pointer to the source touch structure \ref cy_stc_capsense_position_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_CopyTouchRecord(
+                cy_stc_capsense_position_t * destination,
+                const cy_stc_capsense_position_t * source)
+{
+    *destination = *source;
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpFilterTouchRecord
+****************************************************************************//**
+*
+* Filters position data of every valid touch if enabled and copies data into
+* public touch array.
+*
+* This function checks every touch in the new touch structure. If the touch is
+* valid (valid id and age > 0), then touch is filtered if the filter is enabled.
+* At the end, the corresponding fields are updated in the public touch structure.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+void Cy_CapSense_DpFilterTouchRecord(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t i;
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_POSITION_FILTER_EN)
+        uint32_t j;
+    #endif
+    uint32_t reportedTouchNum = 0u;
+    uint32_t peakNum = ptrWdConfig->ptrCsxTouchBuffer->newPeakNumber;
+    uint32_t maxTouch;
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_POSITION_FILTER_EN)
+        uint32_t filterSize;
+        uint32_t newTouchFlag = 0u;
+    #endif
+
+    cy_stc_capsense_position_t * ptrWdTouch = ptrWdConfig->ptrWdContext->wdTouch.ptrPosition;
+    cy_stc_capsense_position_t * ptrNewPeak = ptrWdConfig->ptrCsxTouchBuffer->newPeak;
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_POSITION_FILTER_EN)
+        cy_stc_capsense_position_t * ptrHistory;
+        uint32_t historyFlag[CY_CAPSENSE_MAX_CENTROIDS] = {0u};
+    #endif
+
+    /* Define number of touches that should be reported */
+    for (i = 0u; i < CY_CAPSENSE_MAX_CENTROIDS; i++)
+    {
+        /*
+        * Age must be higher than 0 otherwise the touch does not pass
+        * debounce procedure. It exists in the array for correct
+        * touch tracking and debouncing.
+        */
+        if ((i < peakNum) && ((ptrNewPeak->z & CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK) > 0u))
+        {
+            reportedTouchNum++;
+        }
+        ptrNewPeak++;
+    }
+
+    maxTouch = (uint32_t)ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_NUMBER_MASK;
+    if (reportedTouchNum > maxTouch)
+    {
+        reportedTouchNum = maxTouch;
+    }
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_POSITION_FILTER_EN)
+    if (0u != (ptrWdConfig->posFilterConfig & CY_CAPSENSE_POSITION_FILTERS_MASK))
+    {
+        filterSize = (ptrWdConfig->posFilterConfig & CY_CAPSENSE_POSITION_FILTERS_SIZE_MASK) >>
+                        CY_CAPSENSE_POSITION_FILTERS_SIZE_OFFSET;
+
+        /* Go through all new touches */
+        ptrNewPeak = ptrWdConfig->ptrCsxTouchBuffer->newPeak;
+        for (i = 0u; i < reportedTouchNum; i++)
+        {
+            newTouchFlag = 0u;
+            /* Find index in the history array that corresponds to the new touch */
+            ptrHistory = ptrWdConfig->ptrPosFilterHistory->ptrPosition;
+            for (j = 0u; j < maxTouch; j++)
+            {
+                /* ID must match */
+                if (ptrHistory->id == ptrNewPeak->id)
+                {
+                    /* Filter X and Y position of touch that exists from previous scan */
+                    Cy_CapSense_RunPositionFilters(ptrWdConfig, ptrNewPeak, ptrHistory);
+                    /* Mark history touch as assigned */
+                    historyFlag[j] = 1u;
+                    newTouchFlag = 1u;
+                    /* Because the touch is found and processed, go to the next new touch */
+                    break;
+                }
+                ptrHistory += filterSize;
+            }
+            /* The touch is not found in history */
+            if (0u == newTouchFlag)
+            {
+                /* Find a place to keep history and initialize it */
+                ptrHistory = ptrWdConfig->ptrPosFilterHistory->ptrPosition;
+                for (j = 0u; j < maxTouch; j++)
+                {
+                    if (0u == historyFlag[j])
+                    {
+                        Cy_CapSense_InitPositionFilters(ptrWdConfig->posFilterConfig,
+                                                        ptrNewPeak,
+                                                        ptrHistory);
+                        historyFlag[j] = 1u;
+                        /* Assignment is done; go to the next new touch */
+                        break;
+                    }
+                    ptrHistory += filterSize;
+                }
+            }
+            ptrNewPeak++;
+        }
+        /* Reset all non-assigned history IDs */
+        ptrHistory = ptrWdConfig->ptrPosFilterHistory->ptrPosition;
+        for (j = 0u; j < maxTouch; j++)
+        {
+            if (0u == historyFlag[j])
+            {
+                ptrHistory->id = CY_CAPSENSE_CSX_TOUCHPAD_ID_UNDEFINED;
+            }
+            ptrHistory += filterSize;
+        }
+    }
+    #endif /*(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_POSITION_FILTER_EN)*/
+
+    /* Go through all touch fields in the data structure */
+    ptrNewPeak = ptrWdConfig->ptrCsxTouchBuffer->newPeak;
+    for (i = 0u; i < maxTouch; i++)
+    {
+        ptrWdTouch->id = CY_CAPSENSE_CSX_TOUCHPAD_ID_UNDEFINED;
+
+        if (i < reportedTouchNum)
+        {
+            /* Report touch to the data structure */
+            ptrWdTouch->x = ptrNewPeak->x;
+            ptrWdTouch->y = ptrNewPeak->y;
+            ptrWdTouch->z = ptrNewPeak->z;
+            ptrWdTouch->id = ptrNewPeak->id;
+        }
+        ptrNewPeak++;
+        ptrWdTouch++;
+    }
+
+    ptrWdConfig->ptrWdContext->wdTouch.numPosition = (uint8_t)reportedTouchNum;
+    if (0u == reportedTouchNum)
+    {
+        ptrWdConfig->ptrWdContext->status &= (uint8_t)~CY_CAPSENSE_WD_ACTIVE_MASK;
+    }
+    else
+    {
+        ptrWdConfig->ptrWdContext->status = CY_CAPSENSE_WD_ACTIVE_MASK;
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POSITION_FILTER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitPositionFilters
+****************************************************************************//**
+*
+* Initializes history of touch structures by provided current touch states.
+*
+* \param filterConfig
+* The configuration of filters of the widget.
+*
+* \param ptrInput
+* The pointer to the position structure that holds currently detected
+* position values.
+*
+* \param ptrHistory
+* The pointer to the position structure that holds previous historical
+* position values.
+*
+*******************************************************************************/
+void Cy_CapSense_InitPositionFilters(
+                uint32_t filterConfig,
+                const cy_stc_capsense_position_t * ptrInput,
+                cy_stc_capsense_position_t * ptrHistory)
+{
+    cy_stc_capsense_position_t * ptrHistoryIndex = ptrHistory;
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_MEDIAN_FILTER_EN)
+        if (0u != (filterConfig & CY_CAPSENSE_POSITION_MED_MASK))
+        {
+            *ptrHistoryIndex = *ptrInput;
+            ptrHistoryIndex++;
+            *ptrHistoryIndex = *ptrInput;
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_IIR_FILTER_EN)
+        if (0u != (filterConfig & CY_CAPSENSE_POSITION_IIR_MASK))
+        {
+            *ptrHistoryIndex = *ptrInput;
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_ADAPTIVE_FILTER_EN)
+        if (0u != (filterConfig & CY_CAPSENSE_POSITION_AIIR_MASK))
+        {
+            ptrHistoryIndex->x = ptrInput->x;
+            ptrHistoryIndex->y = ptrInput->y;
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_AVERAGE_FILTER_EN)
+        if (0u != (filterConfig & CY_CAPSENSE_POSITION_AVG_MASK))
+        {
+            *ptrHistoryIndex = *ptrInput;
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_JITTER_FILTER_EN)
+        if (0u != (filterConfig & CY_CAPSENSE_POSITION_JIT_MASK))
+        {
+            *ptrHistoryIndex = *ptrInput;
+            ptrHistoryIndex++;
+        }
+    #endif
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunPositionFilters
+****************************************************************************//**
+*
+* Applies enabled filters to position specified by ptrInput argument and stores
+* history into ptrHistory.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+* \param ptrInput
+* The pointer to the position structure that holds currently detected
+* position values.
+*
+* \param ptrHistory
+* The pointer to the position structure that holds previous historical
+* position values.
+*
+*******************************************************************************/
+void Cy_CapSense_RunPositionFilters(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_position_t * ptrInput,
+                cy_stc_capsense_position_t * ptrHistory)
+{
+    #if (CY_CAPSENSE_POS_MEDIAN_FILTER_EN || CY_CAPSENSE_POS_AVERAGE_FILTER_EN)
+        uint32_t temp;
+    #endif
+    uint32_t xPos = ptrInput->x;
+    uint32_t yPos = ptrInput->y;
+    cy_stc_capsense_position_t * ptrHistoryIndex = ptrHistory;
+    uint32_t filterCfg = ptrWdConfig->posFilterConfig;
+    #if (0u != CY_CAPSENSE_POS_IIR_FILTER_EN)
+        uint32_t coeffIIR = (uint32_t)(filterCfg & CY_CAPSENSE_POSITION_IIR_COEFF_MASK) >> CY_CAPSENSE_POSITION_IIR_COEFF_OFFSET;
+    #endif
+
+    #if (0u != CY_CAPSENSE_POS_MEDIAN_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_MED_MASK))
+        {
+            temp = Cy_CapSense_FtMedian((uint32_t)ptrHistoryIndex[1u].x, (uint32_t)ptrHistoryIndex[0u].x, xPos);
+            ptrHistoryIndex[1u].x = ptrHistoryIndex[0u].x;
+            ptrHistoryIndex[0u].x = (uint16_t)xPos;
+            xPos = temp;
+            temp = Cy_CapSense_FtMedian((uint32_t)ptrHistoryIndex[1u].y, (uint32_t)ptrHistoryIndex[0u].y, yPos);
+            ptrHistoryIndex[1u].y = ptrHistoryIndex[0u].y;
+            ptrHistoryIndex[0u].y = (uint16_t)yPos;
+            yPos = temp;
+            ptrHistoryIndex++;
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (0u != CY_CAPSENSE_POS_IIR_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_IIR_MASK))
+        {
+            xPos = Cy_CapSense_FtIIR1stOrder(xPos, (uint32_t)ptrHistoryIndex->x, coeffIIR);
+            ptrHistoryIndex->x = (uint16_t)xPos;
+            yPos = Cy_CapSense_FtIIR1stOrder(yPos, (uint32_t)ptrHistoryIndex->y, coeffIIR);
+            ptrHistoryIndex->y = (uint16_t)yPos;
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_ADAPTIVE_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_AIIR_MASK))
+        {
+            Cy_CapSense_AdaptiveFilterRun_Lib(&ptrWdConfig->aiirConfig, ptrHistoryIndex, &xPos, &yPos);
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (0u != CY_CAPSENSE_POS_AVERAGE_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_AVG_MASK))
+        {
+            temp = xPos;
+            xPos = (xPos + ptrHistoryIndex->x) >> 1u;
+            ptrHistoryIndex->x = (uint16_t)temp;
+            temp = yPos;
+            yPos = (yPos + ptrHistoryIndex->y) >> 1u;
+            ptrHistoryIndex->y = (uint16_t)temp;
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (0u != CY_CAPSENSE_POS_JITTER_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_JIT_MASK))
+        {
+            xPos = Cy_CapSense_FtJitter(xPos, (uint32_t)ptrHistoryIndex->x);
+            ptrHistoryIndex->x = (uint16_t)xPos;
+            yPos = Cy_CapSense_FtJitter(yPos, (uint32_t)ptrHistoryIndex->y);
+            ptrHistoryIndex->y = (uint16_t)yPos;
+        }
+    #endif
+    ptrInput->x = (uint16_t)xPos;
+    ptrInput->y = (uint16_t)yPos;
+}
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_POSITION_FILTER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunPositionFiltersRadial
+****************************************************************************//**
+*
+* Applies enabled filters to position specified by the ptrInput argument and stores
+* history into ptrHistory. Filtering considers specific widget type where
+* the next value after maximum position is zero and vise versa.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+* \param ptrInput
+* The pointer to the position structure that holds currently detected
+* position values.
+*
+* \param ptrHistory
+* The pointer to the position structure that holds previous historical
+* position values.
+*
+*******************************************************************************/
+void Cy_CapSense_RunPositionFiltersRadial(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_position_t * ptrInput,
+                cy_stc_capsense_position_t * ptrHistory)
+{
+    /*
+    * If new position crosses the zero point in one or another direction,
+    * the position variable with the smaller value is increased by the
+    * slider resolution. This is done for the proper filtering. For
+    * example, xResolution = 100, currPosition = 95, newPosition = 5.
+    * If no actions are taken, then the average filter will give a value of
+    * 50 - which is wrong. But if the position values are adjusted as
+    * mentioned here, we will get newPosition equal 105 and the average
+    * will be 100. Later this filtered value will be adjusted further
+    * to not cross the xResolution and it will end up with 0u - which
+    * is correct average result for the provided example.
+    */
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_MEDIAN_FILTER_EN)
+        uint32_t z1;
+        uint32_t z2;
+    #endif
+    #if (CY_CAPSENSE_POS_IIR_FILTER_EN || CY_CAPSENSE_ADAPTIVE_FILTER_EN || CY_CAPSENSE_POS_AVERAGE_FILTER_EN)
+        uint32_t temp;
+    #endif
+    /* The register contains max position value, so therefore it is increased by 1 */
+    uint32_t centroidResolution = (uint32_t)ptrWdConfig->xResolution + 1u;
+    uint32_t halfResolution = centroidResolution >> 1u;
+    uint32_t xPos = ptrInput->x;
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_ADAPTIVE_FILTER_EN)
+        uint32_t yPos = 0u;
+    #endif
+    cy_stc_capsense_position_t * ptrHistoryIndex = ptrHistory;
+    uint32_t filterCfg = ptrWdConfig->posFilterConfig;
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_IIR_FILTER_EN)
+        uint32_t coeffIIR = (uint32_t)(filterCfg & CY_CAPSENSE_POSITION_IIR_COEFF_MASK) >> CY_CAPSENSE_POSITION_IIR_COEFF_OFFSET;
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_MEDIAN_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_MED_MASK))
+        {
+            /* Get the filter history for further zero-cross correction */
+            z1 = ptrHistoryIndex[0u].x;
+            z2 = ptrHistoryIndex[1u].x;
+            /* Preserve the filter history without zero-cross correction */
+            ptrHistoryIndex[1u].x = ptrHistoryIndex[0u].x;
+            ptrHistoryIndex[0u].x = (uint16_t)xPos;
+
+            /* Perform zero-cross correction */
+            if (z1 > (halfResolution + xPos))
+            {
+                xPos += centroidResolution;
+            }
+            if (xPos > (halfResolution + z1))
+            {
+                z1 += centroidResolution;
+                z2 += centroidResolution;
+            }
+            if (z2 > (halfResolution + z1))
+            {
+                z1 += centroidResolution;
+                xPos += centroidResolution;
+            }
+            if (z1 > (halfResolution + z2))
+            {
+                z2 += centroidResolution;
+            }
+
+            /* Perform filtering */
+            xPos = Cy_CapSense_FtMedian(z2, z1, xPos);
+            /* Perform zero-cross correction of filtered position */
+            if (xPos >= centroidResolution)
+            {
+                xPos -= centroidResolution;
+            }
+            ptrHistoryIndex++;
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_IIR_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_IIR_MASK))
+        {
+            /* Perform zero-cross correction */
+            if (ptrHistoryIndex->x > (halfResolution + xPos))
+            {
+                xPos += centroidResolution;
+            }
+            if (xPos > (halfResolution + ptrHistoryIndex->x))
+            {
+                ptrHistoryIndex->x += (uint16_t)centroidResolution;
+            }
+            if (ptrHistoryIndex->x > xPos)
+            {
+                temp = ptrHistoryIndex->x - xPos;
+            }
+            else
+            {
+                temp = xPos - ptrHistoryIndex->x;
+            }
+
+            /*
+            * IIR filter can accumulate a delay up to a full circle and even more.
+            * This situation is not supported by the middleware. If the difference
+            * between the new position and IIR filter history is bigger than
+            * half of resolution, then all enabled position filters are reset.
+            */
+            if(temp >= halfResolution)
+            {
+                /* Perform Initialization */
+                Cy_CapSense_InitPositionFilters(filterCfg, ptrInput, ptrHistory);
+            }
+            else
+            {
+                /* Perform filtering */
+                xPos = Cy_CapSense_FtIIR1stOrder(xPos, (uint32_t)ptrHistoryIndex->x, coeffIIR);
+                /* Perform zero-cross correction of filtered position */
+                if (xPos >= centroidResolution)
+                {
+                    xPos -= centroidResolution;
+                }
+                ptrHistoryIndex->x = (uint16_t)xPos;
+            }
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_ADAPTIVE_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_AIIR_MASK))
+        {
+            /* Perform zero-cross correction */
+            if (ptrHistoryIndex->x > (halfResolution + xPos))
+            {
+                xPos += centroidResolution;
+            }
+            if (xPos > (halfResolution + ptrHistoryIndex->x))
+            {
+                ptrHistoryIndex->x += (uint16_t)centroidResolution;
+            }
+            if (ptrHistoryIndex->x > xPos)
+            {
+                temp = ptrHistoryIndex->x - xPos;
+            }
+            else
+            {
+                temp = xPos - ptrHistoryIndex->x;
+            }
+
+            /*
+            * IIR filter can accumulate delay up to full circle and even more.
+            * This situation is not supported by the middleware. If the difference
+            * between the new position and IIR filter history is bigger than
+            * half of resolution, then all enabled position filters are reset.
+            */
+            if(temp >= halfResolution)
+            {
+                /* Perform Initialization */
+                Cy_CapSense_InitPositionFilters(filterCfg, ptrInput, ptrHistory);
+            }
+            else
+            {
+                /* Perform filtering */
+                Cy_CapSense_AdaptiveFilterRun_Lib(&ptrWdConfig->aiirConfig, ptrHistoryIndex, &xPos, &yPos);
+                /* Perform zero-cross correction of filtered position */
+                if (xPos >= centroidResolution)
+                {
+                    xPos -= centroidResolution;
+                }
+                ptrHistoryIndex->x = (uint16_t)xPos;
+            }
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_AVERAGE_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_AVG_MASK))
+        {
+            temp = xPos;
+            /* Perform zero-cross correction */
+            if (ptrHistoryIndex->x > (halfResolution + xPos))
+            {
+                xPos += centroidResolution;
+            }
+            if (xPos > (halfResolution + ptrHistoryIndex->x))
+            {
+                ptrHistoryIndex->x += (uint16_t)centroidResolution;
+            }
+            /* Perform filtering */
+            xPos = (xPos + ptrHistoryIndex->x) >> 1u;
+            /* Perform zero-cross correction of filtered position */
+            if (xPos >= centroidResolution)
+            {
+                xPos -= centroidResolution;
+            }
+            ptrHistoryIndex->x = (uint16_t)temp;
+            ptrHistoryIndex++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_JITTER_FILTER_EN)
+        if (0u != (filterCfg & CY_CAPSENSE_POSITION_JIT_MASK))
+        {
+            /* Perform zero-cross correction */
+            if (ptrHistoryIndex->x > (halfResolution + xPos))
+            {
+                xPos += centroidResolution;
+            }
+            if (xPos > (halfResolution + ptrHistoryIndex->x))
+            {
+                ptrHistoryIndex->x += (uint16_t)centroidResolution;
+            }
+            /* Perform filtering */
+            xPos = Cy_CapSense_FtJitter(xPos, (uint32_t)ptrHistoryIndex->x);
+            /* Perform zero-cross correction of filtered position */
+            if (xPos >= centroidResolution)
+            {
+                xPos -= centroidResolution;
+            }
+            ptrHistoryIndex->x = (uint16_t)xPos;
+        }
+    #endif
+
+    ptrInput->x = (uint16_t)xPos;
+}
+#endif /*(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_POSITION_FILTER_EN)*/
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_ProcessPositionFilters
+****************************************************************************//**
+*
+* Performs filtering of touch positions applying enabled filters.
+*
+* \param newTouch
+* The pointer to the touch structure.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure
+* \ref cy_stc_capsense_widget_config_t.
+*
+*******************************************************************************/
+void Cy_CapSense_ProcessPositionFilters(
+                cy_stc_capsense_touch_t * newTouch,
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t posIndex;
+    uint32_t filterCfg;
+    uint32_t numPosMin;
+    uint32_t filterSize;
+    cy_stc_capsense_position_t * ptrHistory;
+    cy_stc_capsense_position_t * ptrPos;
+    uint32_t numPos = newTouch->numPosition;
+
+    /* Position filtering */
+    if ((CY_CAPSENSE_POSITION_NONE != numPos) && (CY_CAPSENSE_POSITION_MULTIPLE != numPos))
+    {
+        filterCfg = ptrWdConfig->posFilterConfig;
+        numPosMin = ptrWdConfig->ptrPosFilterHistory->numPosition;
+        ptrPos = newTouch->ptrPosition;
+        ptrHistory = ptrWdConfig->ptrPosFilterHistory->ptrPosition;
+        filterSize = (filterCfg & CY_CAPSENSE_POSITION_FILTERS_SIZE_MASK) >> CY_CAPSENSE_POSITION_FILTERS_SIZE_OFFSET;
+
+        /* The same actions should be done for cases with no touches or multiple touches */
+        if (CY_CAPSENSE_POSITION_MULTIPLE == numPosMin)
+        {
+            numPosMin = CY_CAPSENSE_POSITION_NONE;
+        }
+
+        /* Find number of position that exists from previous processing */
+        if (numPosMin > numPos)
+        {
+            numPosMin = numPos;
+        }
+
+        /* Process touches that exists from previous processing */
+        #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_RADIAL_SLIDER_EN) &&\
+            (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_POSITION_FILTER_EN))
+            if((uint8_t)CY_CAPSENSE_WD_RADIAL_SLIDER_E == ptrWdConfig->wdType)
+            {
+                for (posIndex = 0u; posIndex < numPosMin; posIndex++)
+                {
+                    Cy_CapSense_RunPositionFiltersRadial(ptrWdConfig, ptrPos, ptrHistory);
+                    ptrPos++;
+                    ptrHistory += filterSize;
+                }
+            }
+            else
+            {
+                for (posIndex = 0u; posIndex < numPosMin; posIndex++)
+                {
+                    Cy_CapSense_RunPositionFilters(ptrWdConfig, ptrPos, ptrHistory);
+                    ptrPos++;
+                    ptrHistory += filterSize;
+                }
+            }
+        #else
+            for (posIndex = 0u; posIndex < numPosMin; posIndex++)
+            {
+                Cy_CapSense_RunPositionFilters(ptrWdConfig, ptrPos, ptrHistory);
+                ptrPos++;
+                ptrHistory += filterSize;
+            }
+        #endif
+        /* Initialize all rest newly detected touches */
+        for (; posIndex < numPos; posIndex++)
+        {
+            Cy_CapSense_InitPositionFilters(filterCfg, ptrPos, ptrHistory);
+            ptrPos++;
+            ptrHistory += filterSize;
+        }
+    }
+    /* Finally, copy number of positions */
+    ptrWdConfig->ptrPosFilterHistory->numPosition = (uint8_t)numPos;
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POSITION_FILTER_EN) */
+#endif /* ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_SLIDER_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_TOUCHPAD_EN)) */
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+/* [] END OF FILE */

+ 123 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_centroid.h

@@ -0,0 +1,123 @@
+/***************************************************************************//**
+* \file cy_capsense_centroid.h
+* \version 3.0
+*
+* \brief
+* This file provides the function prototypes for the centroid calculation
+* methods.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_CENTROID_H)
+#define CY_CAPSENSE_CENTROID_H
+
+#include "cy_capsense_lib.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cycfg_capsense_defines.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+#if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_SLIDER_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_TOUCHPAD_EN))
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+/*******************************************************************************
+* Function Prototypes - internal functions
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+#if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_LINEAR_SLIDER_EN) ||\
+    (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_LINEAR_SLIDER_EN))
+    void Cy_CapSense_DpCentroidLinear(
+                    cy_stc_capsense_touch_t * newTouch,
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_RADIAL_SLIDER_EN)
+    void Cy_CapSense_DpCentroidRadial(
+                    cy_stc_capsense_touch_t * newTouch,
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_DIPLEX_SLIDER_EN) ||\
+    (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_DIPLEX_SLIDER_EN))
+    void Cy_CapSense_DpCentroidDiplex(
+                    cy_stc_capsense_touch_t * newTouch,
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)
+    void Cy_CapSense_DpCentroidTouchpad(
+                    cy_stc_capsense_touch_t * newTouch,
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_ADVANCED_CENTROID_5X5_EN)
+    void Cy_CapSense_DpAdvancedCentroidTouchpad(
+                    cy_stc_capsense_touch_t * newTouch,
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    void Cy_CapSense_DpFindLocalMaxDd(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    void Cy_CapSense_DpCalcTouchPadCentroid(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    void Cy_CapSense_DpTouchTracking(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    void Cy_CapSense_DpFilterTouchRecord(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POSITION_FILTER_EN)
+    void Cy_CapSense_InitPositionFilters(
+                    uint32_t filterConfig,
+                    const cy_stc_capsense_position_t * ptrInput,
+                    cy_stc_capsense_position_t * ptrHistory);
+    void Cy_CapSense_RunPositionFilters(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    cy_stc_capsense_position_t * ptrInput,
+                    cy_stc_capsense_position_t * ptrHistory);
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_POSITION_FILTER_EN)
+        void Cy_CapSense_RunPositionFiltersRadial(
+                        const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                        cy_stc_capsense_position_t * ptrInput,
+                        cy_stc_capsense_position_t * ptrHistory);
+    #endif
+    void Cy_CapSense_ProcessPositionFilters(
+                    cy_stc_capsense_touch_t * newTouch,
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+/** \} \endcond */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_SLIDER_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_TOUCHPAD_EN)) */
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+#endif /* CY_CAPSENSE_CENTROID_H */
+
+
+/* [] END OF FILE */

+ 869 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_common.h

@@ -0,0 +1,869 @@
+/***************************************************************************//**
+* \file cy_capsense_common.h
+* \version 3.0
+*
+* \brief
+* This file provides the common CAPSENSE&trade; middleware definitions.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_COMMON_H)
+#define CY_CAPSENSE_COMMON_H
+
+#include "cy_device_headers.h"
+#include "cy_sysint.h"
+#include "cycfg_capsense_defines.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/*******************************************************************************
+* Macros
+*******************************************************************************/
+
+#if (defined(CY_IP_M0S8CSDV2))
+
+    #define CY_CAPSENSE_PLATFORM_DEVICE_PSOC4           (1u)
+    #define CY_CAPSENSE_PLATFORM_DEVICE_PSOC6           (0u)
+
+    #define CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN       (1u)
+    #define CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN        (0u)
+
+    #define CY_CAPSENSE_PSOC4_FOURTH_GEN                (1u)
+    #define CY_CAPSENSE_PSOC6_FOURTH_GEN                (0u)
+    #define CY_CAPSENSE_PSOC4_FIFTH_GEN                 (0u)
+
+#elif (defined(CY_IP_MXCSDV2))
+
+    #define CY_CAPSENSE_PLATFORM_DEVICE_PSOC4           (0u)
+    #define CY_CAPSENSE_PLATFORM_DEVICE_PSOC6           (1u)
+
+    #define CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN       (1u)
+    #define CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN        (0u)
+
+    #define CY_CAPSENSE_PSOC4_FOURTH_GEN                (0u)
+    #define CY_CAPSENSE_PSOC6_FOURTH_GEN                (1u)
+    #define CY_CAPSENSE_PSOC4_FIFTH_GEN                 (0u)
+
+#elif (defined(CY_IP_M0S8MSCV3))
+
+    #define CY_CAPSENSE_PLATFORM_DEVICE_PSOC4           (1u)
+    #define CY_CAPSENSE_PLATFORM_DEVICE_PSOC6           (0u)
+
+    #define CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN       (0u)
+    #define CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN        (1u)
+
+    #define CY_CAPSENSE_PSOC4_FOURTH_GEN                (0u)
+    #define CY_CAPSENSE_PSOC6_FOURTH_GEN                (0u)
+    #define CY_CAPSENSE_PSOC4_FIFTH_GEN                 (1u)
+
+#endif
+
+#define CY_CAPSENSE_PSOC4_CSDV2                         (CY_CAPSENSE_PSOC4_FOURTH_GEN)
+#define CY_CAPSENSE_PSOC6_CSDV2                         (CY_CAPSENSE_PSOC6_FOURTH_GEN)
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+    #include "cy_csd.h"
+#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
+    #include "cy_msc.h"
+#endif
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_general *//** \{ */
+/******************************************************************************/
+/** Middleware major version */
+#define CY_CAPSENSE_MW_VERSION_MAJOR                    (3)
+/** Middleware minor version */
+#define CY_CAPSENSE_MW_VERSION_MINOR                    (0)
+/** Middleware version */
+#define CY_CAPSENSE_MW_VERSION                          (300)
+
+#if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
+    /** Defined supported CSD driver version */
+    #define CY_CSD_DRV_VERSION_REQUIRED                 (100)
+
+    #if !defined (CY_CSD_DRV2_VERSION)
+        /** If CSD driver version not defined by driver then define it here */
+        #define CY_CSD_DRV2_VERSION                     (100)
+    #else
+        /** Use CSD Capture function */
+        #define CY_CAPSENSE_USE_CAPTURE                 (1u)
+    #endif
+
+    /* Check used driver version */
+    #if (CY_CSD_DRV_VERSION_REQUIRED > CY_CSD_DRV2_VERSION)
+        #error Some of the features supported by the CAPSENSE&trade; Middleware version CY_CAPSENSE_MW_VERSION require newer version of the PDL. Update the PDL in your project.
+    #endif
+
+#endif
+
+#if (CY_CAPSENSE_PSOC4_FOURTH_GEN)
+    /** Defined supported CSD driver version */
+    #define CY_CSD_DRV_VERSION_REQUIRED                 (100)
+
+    #if !defined (CY_CSD_DRV2_VERSION)
+        /** If CSD driver version not defined by driver then define it here */
+        #define CY_CSD_DRV2_VERSION                     (100)
+    #else
+        /** Use CSD Capture function */
+        #define CY_CAPSENSE_USE_CAPTURE                 (1u)
+    #endif
+
+    /* Check used driver version */
+    #if (CY_CSD_DRV_VERSION_REQUIRED > CY_CSD_DRV2_VERSION)
+        #error Some of the features supported by the CAPSENSE&trade; Middleware version CY_CAPSENSE_MW_VERSION require newer version of the PDL. Update the PDL in your project.
+    #endif
+
+#endif
+
+#if (CY_CAPSENSE_PSOC4_FIFTH_GEN)
+    /** Defined supported MSC driver version */
+    #define CY_MSC_DRV_VERSION_REQUIRED                 (100)
+
+    #if !defined (CY_MSC_DRV2_VERSION)
+        /** If MSC driver version not defined by driver then define it here */
+        #define CY_MSC_DRV2_VERSION                     (100)
+    #else
+        /** Use MSC Capture function */
+        #define CY_CAPSENSE_USE_CAPTURE                 (1u)
+    #endif
+
+    /* Check used driver version */
+    #if (CY_MSC_DRV_VERSION_REQUIRED > CY_MSC_DRV2_VERSION)
+        #error Some of the features supported by the CAPSENSE&trade; Middleware version CY_CAPSENSE_MW_VERSION require newer version of the PDL. Update the PDL in your project.
+    #endif
+
+#endif
+
+#if !defined (CY_CAPSENSE_USE_CAPTURE)
+    /** Use CSD/MSC Init function */
+    #define CY_CAPSENSE_USE_CAPTURE                     (0u)
+#endif
+
+/** Middleware ID */
+#define CY_CAPSENSE_ID                                  (CY_PDL_DRV_ID(0x07uL))
+
+
+/* Scanning status */
+/** The CAPSENSE&trade; middleware is busy */
+#define CY_CAPSENSE_BUSY                                (0x80u)
+/** The CAPSENSE&trade; middleware is not busy */
+#define CY_CAPSENSE_NOT_BUSY                            (0x00u)
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+    /** The CAPSENSE&trade; middleware busy mask */
+    #define CY_CAPSENSE_BUSY_MASK                       (0xFFu)
+    /** The MSCv3 channel busy mask */
+    #define CY_CAPSENSE_BUSY_CH_MASK                    (0x01u)
+    /** All MSCv3 channels busy mask */
+    #define CY_CAPSENSE_BUSY_ALL_CH_MASK                (0x0Fu)
+#endif
+
+
+/** CAPSENSE&trade; MW initialization is done */
+#define CY_CAPSENSE_INIT_DONE                           (1u)
+/** CAPSENSE&trade; MW initialization is needed */
+#define CY_CAPSENSE_INIT_NEEDED                         (0u)
+
+/** Feature enabled */
+#define CY_CAPSENSE_ENABLE                              (1u)
+/** Feature disabled */
+#define CY_CAPSENSE_DISABLE                             (0u)
+
+/** Sensor active status mask */
+#define CY_CAPSENSE_SNS_TOUCH_STATUS_MASK               (0x01u)
+/** Proximity active status mask */
+#define CY_CAPSENSE_SNS_PROX_STATUS_MASK                (0x02u)
+/** Sensor overflow mask */
+#define CY_CAPSENSE_SNS_OVERFLOW_MASK                   (0x04u)
+/** Widget active status mask */
+#define CY_CAPSENSE_WD_ACTIVE_MASK                      (0x01u)
+/** Widget disable status mask */
+#define CY_CAPSENSE_WD_DISABLE_MASK                     (0x02u)
+/** Widget working status mask */
+#define CY_CAPSENSE_WD_WORKING_MASK                     (0x04u)
+/** \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_mw_state *//** \{ */
+/******************************************************************************/
+/** The BIST is currently in progress */
+#define CY_CAPSENSE_MW_STATE_BIST_MASK                  (0x800u)
+/** The auto-calibration in Single CDAC mode */
+#define CY_CAPSENSE_MW_STATE_CALIBRATION_SINGLE_MASK    (0x1000u)
+/** The auto-calibration is currently in progress */
+#define CY_CAPSENSE_MW_STATE_CALIBRATION_MASK           (0x2000u)
+/** The smart sensing algorithm is currently in progress */
+#define CY_CAPSENSE_MW_STATE_SMARTSENSE_MASK            (0x4000u)
+/** The middleware initialization is currently in progress */
+#define CY_CAPSENSE_MW_STATE_INITIALIZATION_MASK        (0x8000u)
+/** The currently active or last scanned slot ID mask */
+#define CY_CAPSENSE_MW_STATE_SCAN_SLOT_MASK             (0xFFFF0000u)
+/** Current scan slot position in status */
+#define CY_CAPSENSE_MW_STATE_SCAN_SLOT_POS              (16u)
+/** \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_settings *//** \{ */
+/******************************************************************************/
+
+/** Interrupt Driven scanning mode */
+#define CY_CAPSENSE_SCAN_MODE_INT_DRIVEN                (0u)
+/** DMA Driven scanning mode */
+#define CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN                (1u)
+
+/** Sensor connection method through analog mux bus */
+#define CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD       (0u)
+/** Sensor connection method through control mux switches */
+#define CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD    (1u)
+
+/** CIC filter mode */
+#define CY_CAPSENSE_CIC_FILTER                          (0u)
+/** CIC2 filter mode */
+#define CY_CAPSENSE_CIC2_FILTER                         (1u)
+
+/** Raw count counter mode saturate */
+#define CY_CAPSENSE_COUNTER_MODE_SATURATE               (0u)
+/** Raw count counter mode overflow */
+#define CY_CAPSENSE_COUNTER_MODE_OVERFLOW               (1u)
+
+/** Synchronization mode is disabled */
+#define CY_CAPSENSE_SYNC_MODE_OFF                       (0u)
+/** Synchronization is external */
+#define CY_CAPSENSE_SYNC_EXTERNAL                       (1u)
+/** Synchronization is internal */
+#define CY_CAPSENSE_SYNC_INTERNAL                       (2u)
+
+/** Sensing group undefined used at initialization */
+#define CY_CAPSENSE_UNDEFINED_GROUP                     (0u)
+/** CSD sensing group */
+#define CY_CAPSENSE_CSD_GROUP                           (1u)
+/** CSX sensing group */
+#define CY_CAPSENSE_CSX_GROUP                           (2u)
+/** BIST group */
+#define CY_CAPSENSE_BIST_GROUP                          (3u)
+/** BIST CSD sensor capacitance measurement group */
+#define CY_CAPSENSE_BIST_CSD_GROUP                      (4u)
+/** BIST CSX sensor capacitance measurement group */
+#define CY_CAPSENSE_BIST_CSX_GROUP                      (5u)
+/** BIST shield capacitance measurement group */
+#define CY_CAPSENSE_BIST_SHIELD_GROUP                   (6u)
+
+/** Sensing mode undefined */
+#define CY_CAPSENSE_REG_MODE_UNDEFINED                  (255u)
+/** CSD sense mode configuration index */
+#define CY_CAPSENSE_REG_MODE_CSD                        (0u)
+/** CSX sense mode configuration index */
+#define CY_CAPSENSE_REG_MODE_CSX                        (1u)
+/** CSD sense mode configuration index with CapDAC dithering enabled */
+#define CY_CAPSENSE_REG_MODE_CSD_DITHERING              (2u)
+/** CSX sense mode configuration index with CapDAC dithering enabled */
+#define CY_CAPSENSE_REG_MODE_CSX_DITHERING              (3u)
+
+/** First mode index with CapDAC dithering enabled */
+#define CY_CAPSENSE_REG_MODE_DITHERING                  (CY_CAPSENSE_REG_MODE_CSD_DITHERING)
+
+/** Total number of modes */
+#define CY_CAPSENSE_REG_MODE_NUMBER                     (4u)
+
+/* The values of these macros should be not changed due to CY_ID374670 */
+
+/* Initialization Group */
+/** Control mux switch state is ground */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_GND               (0u)
+/** Control mux switch state is High-Z */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_HIGH_Z            (1u)
+/** Control mux switch state defined as CSX Tx electrode */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_TX                (2u)
+/** Control mux switch state defined as CSX Negative Tx electrode */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_TX_NEGATIVE       (4u)
+/* Working Group */
+/** Control mux switch state defined as CSX Rx electrode */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_RX                (3u)
+/** Control mux switch state defined as CSD sensor */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_SNS               (5u)
+/** Control mux switch state defined as connection to shield signal */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_SHIELD            (6u)
+/* Corner Group */
+/** Control mux switch state defined as CSDBUSC connected electrode */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_VDDA2             (7u)
+
+/** Number of CTRLMUX Pin State */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_NUMBER            (8u)
+/** Number of CTRLMUX Pin State MASK registers */
+#define CY_CAPSENSE_CTRLMUX_PIN_STATE_MASK_NUMBER       (3u)
+
+/* Smart sensing algorithm modes */
+/** Manual tuning mode */
+#define CY_CAPSENSE_CSD_SS_DIS                          (0x00u)
+/** Hardware auto-tune mask */
+#define CY_CAPSENSE_CSD_SS_HW_EN                        (0x01u)
+/** Threshold auto-tune mask */
+#define CY_CAPSENSE_CSD_SS_TH_EN                        (0x02u)
+/** Full auto-tune is enabled */
+#define CY_CAPSENSE_CSD_SS_HWTH_EN                      (CY_CAPSENSE_CSD_SS_HW_EN | CY_CAPSENSE_CSD_SS_TH_EN)
+
+/* MFS macros */
+/** Number of multi-frequency scan channels */
+#define CY_CAPSENSE_MAX_SUPPORTED_FREQ_NUM              (3u)
+/** Total number of multi-frequency scan channels */
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+    #define CY_CAPSENSE_CONFIGURED_FREQ_NUM             (3u)
+#else
+    #define CY_CAPSENSE_CONFIGURED_FREQ_NUM             (1u)
+#endif
+/** Multi-frequency channel 0 constant */
+#define CY_CAPSENSE_MFS_CH0_INDEX                       (0u)
+/** Multi-frequency channel 1 constant */
+#define CY_CAPSENSE_MFS_CH1_INDEX                       (1u)
+/** Multi-frequency channel 2 constant */
+#define CY_CAPSENSE_MFS_CH2_INDEX                       (2u)
+
+/* Inactive sensor connection options */
+/** Inactive sensor connection undefined */
+#define CY_CAPSENSE_SNS_CONNECTION_UNDEFINED            (0u)
+/** Inactive sensor connection to ground */
+#define CY_CAPSENSE_SNS_CONNECTION_GROUND               (1u)
+/** Inactive sensor connection to High-Z */
+#define CY_CAPSENSE_SNS_CONNECTION_HIGHZ                (2u)
+/** Inactive sensor connection to shield */
+#define CY_CAPSENSE_SNS_CONNECTION_SHIELD               (4u)
+/** Inactive CSX sensor connection to VDDA/2 voltage driven bus
+ *  \note This field is available only for the fifth-generation CAPSENSE&trade;.
+ */
+#define CY_CAPSENSE_SNS_CONNECTION_VDDA_BY_2            (5u)
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+/* Shield electrode delay macros */
+/** No shield signal delay */
+#define CY_CAPSENSE_SH_DELAY_0NS                        (0u)
+/** Shield signal delay > 5 ns */
+#define CY_CAPSENSE_SH_DELAY_5NS                        (1u)
+/** Shield signal delay > 10 ns */
+#define CY_CAPSENSE_SH_DELAY_10NS                       (2u)
+/** Shield signal delay > 20 ns */
+#define CY_CAPSENSE_SH_DELAY_20NS                       (3u)
+
+/* Idac sensing configuration */
+/** Idac sourcing */
+#define CY_CAPSENSE_IDAC_SOURCING                       (0u)
+/** Idac sinking */
+#define CY_CAPSENSE_IDAC_SINKING                        (1u)
+
+/* Shield tank capacitor pre-charge source options */
+/** Shield tank capacitor pre-charge from Vref */
+#define CY_CAPSENSE_CSH_PRECHARGE_VREF                  (0u)
+/** Shield tank capacitor pre-charge from IO buffer */
+#define CY_CAPSENSE_CSH_PRECHARGE_IO_BUF                (1u)
+#endif
+
+/* Sense clock selection options */
+/** Auto-mode of clock source selection mask */
+#define CY_CAPSENSE_CLK_SOURCE_AUTO_MASK                (0x80u)
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+    /** Clock source selection mask */
+    #define CY_CAPSENSE_CLK_SOURCE_MASK                 (0x0Fu)
+#else
+    /** Clock source selection mask */
+    #define CY_CAPSENSE_CLK_SOURCE_MASK                 (0x03u)
+#endif
+/** Clock source direct */
+#define CY_CAPSENSE_CLK_SOURCE_DIRECT                   (0x00u)
+/** Clock source SSC6 */
+#define CY_CAPSENSE_CLK_SOURCE_SSC6                     (0x01u)
+/** Clock source SSC7 */
+#define CY_CAPSENSE_CLK_SOURCE_SSC7                     (0x02u)
+/** Clock source SSC9 */
+#define CY_CAPSENSE_CLK_SOURCE_SSC9                     (0x03u)
+/** Clock source SSC10 */
+#define CY_CAPSENSE_CLK_SOURCE_SSC10                    (0x04u)
+/** Clock source PRS8 */
+#define CY_CAPSENSE_CLK_SOURCE_PRS8                     (0x05u)
+/** Clock source PRS12 */
+#define CY_CAPSENSE_CLK_SOURCE_PRS12                    (0x06u)
+/** Smart sensing algorithm Clock Source reserved bits */
+#define CY_CAPSENSE_CLK_SOURCE_SMARTSENSE_MASK          (0xF0u)
+/** Smart sensing algorithm Clock Source reserved bits position */
+#define CY_CAPSENSE_CLK_SOURCE_SMARTSENSE_POS           (4u)
+
+/* Sense clock selection options for MSCv3 */
+/** Clock source SSC */
+#define CY_CAPSENSE_CLK_SOURCE_SSC                      (0x01u)
+/** Clock source PRS */
+#define CY_CAPSENSE_CLK_SOURCE_PRS                      (0x02u)
+/** Clock source SSC auto-selection mask */
+#define CY_CAPSENSE_CLK_SOURCE_SSC_AUTO_MASK            (0x04u)
+/** Clock source SSC auto-selection */
+#define CY_CAPSENSE_CLK_SOURCE_SSC_AUTO                 (CY_CAPSENSE_CLK_SOURCE_SSC_AUTO_MASK)
+/** Clock source PRS auto-selection mask */
+#define CY_CAPSENSE_CLK_SOURCE_PRS_AUTO_MASK            (0x08u)
+/** Clock source PRS auto-selection */
+#define CY_CAPSENSE_CLK_SOURCE_PRS_AUTO                 (CY_CAPSENSE_CLK_SOURCE_PRS_AUTO_MASK)
+
+/* LFSR range selection options */
+/** LFSR range auto-selection mask */
+#define CY_CAPSENSE_LFSR_BITS_AUTO_MASK                 (0x80u)
+/** LFSR range mask */
+#define CY_CAPSENSE_LFSR_BITS_RANGE_MASK                (0x03u)
+/** LFSR range auto-selection */
+#define CY_CAPSENSE_LFSR_BITS_AUTO                      (CY_CAPSENSE_LFSR_BITS_AUTO_MASK)
+/** LFSR range for LFSR_BITS=0 */
+#define CY_CAPSENSE_LFSR_BITS_RANGE_0                   (0x00u)
+/** LFSR range for LFSR_BITS=1 */
+#define CY_CAPSENSE_LFSR_BITS_RANGE_1                   (0x01u)
+/** LFSR range for LFSR_BITS=2 */
+#define CY_CAPSENSE_LFSR_BITS_RANGE_2                   (0x02u)
+/** LFSR range for LFSR_BITS=3 */
+#define CY_CAPSENSE_LFSR_BITS_RANGE_3                   (0x03u)
+
+/* Sense clock auto-selection modes for MSCv3 */
+/** This mode implements checking the following rules:
+*     - An LFSR value should be selected so that the max clock dither is limited with the value,
+*       specified by the LFSR Dither Limit parameter.
+*     - 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 of the repeat period
+*        of the polynomial, that is specified by the Sense Clock LFSR Polynomial parameter.
+*/
+#define CY_CAPSENSE_SNS_CLK_SOURCE_AUTO_SEL_MODE_STRONG (0x00u)
+/** This mode implements checking the following rules:
+*     - An LFSR value should be selected so that the max clock dither is limited with the value,
+*       specified by the LFSR Dither Limit parameter.
+*     - At least one full spread spectrum polynomial should pass during the scan time.
+*/
+#define CY_CAPSENSE_SNS_CLK_SOURCE_AUTO_SEL_MODE_MEDIUM (0x01u)
+/** This mode implements checking the following rules:
+*     - An LFSR value should be selected so that the max clock dither is limited with the value,
+*       specified by the LFSR Dither Limit parameter.
+*/
+#define CY_CAPSENSE_SNS_CLK_SOURCE_AUTO_SEL_MODE_WEAK   (0x02u)
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+/* Initialization switch resistance options */
+/** Low switch resistance at initialization */
+#define CY_CAPSENSE_INIT_SW_RES_LOW                     (0x00u)
+/** Medium switch resistance at initialization */
+#define CY_CAPSENSE_INIT_SW_RES_MEDIUM                  (0x01u)
+/** High switch resistance at initialization */
+#define CY_CAPSENSE_INIT_SW_RES_HIGH                    (0x02u)
+
+/* Scanning switch resistance options */
+/** Low switch resistance at scanning */
+#define CY_CAPSENSE_SCAN_SW_RES_LOW                     (0x00u)
+/** Medium switch resistance at scanning */
+#define CY_CAPSENSE_SCAN_SW_RES_MEDIUM                  (0x01u)
+/** High switch resistance at scanning */
+#define CY_CAPSENSE_SCAN_SW_RES_HIGH                    (0x02u)
+
+/* CSD shield switch resistance options */
+/** Low shield switch resistance */
+#define CY_CAPSENSE_SHIELD_SW_RES_LOW                   (0x00u)
+/** Medium shield switch resistance */
+#define CY_CAPSENSE_SHIELD_SW_RES_MEDIUM                (0x01u)
+/** High shield switch resistance */
+#define CY_CAPSENSE_SHIELD_SW_RES_HIGH                  (0x02u)
+/** Low-EMI shield switch resistance */
+#define CY_CAPSENSE_SHIELD_SW_RES_LOW_EMI               (0x03u)
+#endif
+
+/* CSD shield mode options */
+/** Shield disabled */
+#define CY_CAPSENSE_SHIELD_DISABLED                     (0u)
+/** Active shield mode */
+#define CY_CAPSENSE_SHIELD_ACTIVE                       (1u)
+/** Passive shield mode */
+#define CY_CAPSENSE_SHIELD_PASSIVE                      (2u)
+
+/* Vref source options */
+/** Vref source is taken from SRSS */
+#define CY_CAPSENSE_VREF_SRSS                           (0x00u)
+/** Vref source is taken from PASS */
+#define CY_CAPSENSE_VREF_PASS                           (0x01u)
+
+/* Iref source options */
+/** Iref source is taken from SRSS */
+#define CY_CAPSENSE_IREF_SRSS                           (0x00u)
+/** Iref source is taken from PASS */
+#define CY_CAPSENSE_IREF_PASS                           (0x01u)
+
+/** 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)
+/** Median position filter enable mask */
+#define CY_CAPSENSE_POSITION_MED_MASK                   (0x00000001u)
+/** IIR position filter enable mask */
+#define CY_CAPSENSE_POSITION_IIR_MASK                   (0x00000002u)
+/** Adaptive IIR position filter enable mask */
+#define CY_CAPSENSE_POSITION_AIIR_MASK                  (0x00000004u)
+/** Average position filter enable mask */
+#define CY_CAPSENSE_POSITION_AVG_MASK                   (0x00000008u)
+/** Jitter position filter enable mask */
+#define CY_CAPSENSE_POSITION_JIT_MASK                   (0x00000010u)
+/** Mask of position filters history size */
+#define CY_CAPSENSE_POSITION_FILTERS_SIZE_MASK          (0x0000FF00u)
+/** Offset of position filters history size */
+#define CY_CAPSENSE_POSITION_FILTERS_SIZE_OFFSET        (8u)
+/** Mask of IIR coefficient of position filter */
+#define CY_CAPSENSE_POSITION_IIR_COEFF_MASK             (0x00FF0000u)
+/** Offset of IIR coefficient of position filter */
+#define CY_CAPSENSE_POSITION_IIR_COEFF_OFFSET           (16u)
+
+/* Raw count filter macros */
+/** Offset of raw count filter history size */
+#define CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_OFFSET   (0u)
+/** Offset of raw count median filter enable mask */
+#define CY_CAPSENSE_RC_FILTER_MEDIAN_EN_OFFSET          (4u)
+/** Offset of raw count median filter mode mask */
+#define CY_CAPSENSE_RC_FILTER_MEDIAN_MODE_OFFSET        (5u)
+/** Offset of raw count IIR filter enable mask */
+#define CY_CAPSENSE_RC_FILTER_IIR_EN_OFFSET             (7u)
+/** Offset of raw count IIR filter mode mask */
+#define CY_CAPSENSE_RC_FILTER_IIR_MODE_OFFSET           (8u)
+/** Offset of raw count average filter enable mask */
+#define CY_CAPSENSE_RC_FILTER_AVERAGE_EN_OFFSET         (10u)
+/** Offset of raw count average filter mode mask */
+#define CY_CAPSENSE_RC_FILTER_AVERAGE_MODE_OFFSET       (11u)
+
+/** Mask of raw count filter history size */
+#define CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_MASK     ((uint16_t)((uint16_t)0x000Fu << CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_OFFSET))
+/** Median raw count filter enable mask */
+#define CY_CAPSENSE_RC_FILTER_MEDIAN_EN_MASK            ((uint16_t)((uint16_t)0x0001u << CY_CAPSENSE_RC_FILTER_MEDIAN_EN_OFFSET))
+/** Median raw count filter mode mask */
+#define CY_CAPSENSE_RC_FILTER_MEDIAN_MODE_MASK          ((uint16_t)((uint16_t)0x0003u << CY_CAPSENSE_RC_FILTER_MEDIAN_MODE_OFFSET))
+/** IIR raw count filter enable mask */
+#define CY_CAPSENSE_RC_FILTER_IIR_EN_MASK               ((uint16_t)((uint16_t)0x0001u << CY_CAPSENSE_RC_FILTER_IIR_EN_OFFSET))
+/** IIR raw count filter mode mask */
+#define CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK             ((uint16_t)((uint16_t)0x0003u << CY_CAPSENSE_RC_FILTER_IIR_MODE_OFFSET))
+/** Average raw count filter enable mask */
+#define CY_CAPSENSE_RC_FILTER_AVERAGE_EN_MASK           ((uint16_t)((uint16_t)0x0001u << CY_CAPSENSE_RC_FILTER_AVERAGE_EN_OFFSET))
+/** Average raw count filter mode mask */
+#define CY_CAPSENSE_RC_FILTER_AVERAGE_MODE_MASK         ((uint16_t)((uint16_t)0x0003u << CY_CAPSENSE_RC_FILTER_AVERAGE_MODE_OFFSET))
+/** All raw count filters enable mask */
+#define CY_CAPSENSE_RC_FILTER_ALL_EN_MASK               (CY_CAPSENSE_RC_FILTER_MEDIAN_EN_MASK |\
+                                                         CY_CAPSENSE_RC_FILTER_IIR_EN_MASK |\
+                                                         CY_CAPSENSE_RC_FILTER_AVERAGE_EN_OFFSET)
+/** Raw count IIR filter mode standard */
+#define CY_CAPSENSE_IIR_FILTER_STANDARD                 ((uint16_t)((uint16_t)1u << CY_CAPSENSE_RC_FILTER_IIR_MODE_OFFSET))
+/** Raw count IIR filter mode performance */
+#define CY_CAPSENSE_IIR_FILTER_PERFORMANCE              ((uint16_t)((uint16_t)2u << CY_CAPSENSE_RC_FILTER_IIR_MODE_OFFSET))
+/** Raw count average filter mode */
+#define CY_CAPSENSE_AVERAGE_FILTER_LEN_4                ((uint16_t)((uint16_t)2u << CY_CAPSENSE_RC_FILTER_AVERAGE_MODE_OFFSET))
+/** \} */
+
+/* Slot configuration */
+/** Shield only slot */
+#define CY_CAPSENSE_SLOT_SHIELD_ONLY                    (0xFFFDu)
+/** TX only slot */
+#define CY_CAPSENSE_SLOT_TX_ONLY                        (0xFFFEu)
+/** Empty slot */
+#define CY_CAPSENSE_SLOT_EMPTY                          (0xFFFFu)
+
+/* Centroid configuration */
+/** Supported touch count mask */
+#define CY_CAPSENSE_CENTROID_NUMBER_MASK                (0x0003u)
+/** Diplex enable mask */
+#define CY_CAPSENSE_DIPLEXING_MASK                      (0x0004u)
+/** Ballistic multiplier enable mask */
+#define CY_CAPSENSE_CENTROID_BALLISTIC_MASK             (0x0008u)
+/** 3x3 centroid enable mask */
+#define CY_CAPSENSE_CENTROID_3X3_MASK                   (0x0020u)
+/** 5x5 centroid enable mask */
+#define CY_CAPSENSE_CENTROID_5X5_MASK                   (0x0040u)
+/** Edge correction enable mask */
+#define CY_CAPSENSE_EDGE_CORRECTION_MASK                (0x0080u)
+/**
+* Centroid calculation method mask
+* * Direct provides correct calculation but worse linearity on edges
+*   and requires edge correction [MaxPosition / (numSns)]
+* * Approximate provides better linearity on edges that leads to
+*   worse accuracy in general [MaxPosition / (numSns - 1u)]
+*/
+#define CY_CAPSENSE_CALC_METHOD_MASK                    (0x0100u)
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_touch *//** \{ */
+/******************************************************************************/
+/** No touch detected */
+#define CY_CAPSENSE_POSITION_NONE                       (0x00u)
+/** One finger touch detected */
+#define CY_CAPSENSE_POSITION_ONE                        (0x01u)
+/** Two finger touches detected */
+#define CY_CAPSENSE_POSITION_TWO                        (0x02u)
+/** Three finger touches detected */
+#define CY_CAPSENSE_POSITION_THREE                      (0x03u)
+/** Multiple touches detected that exceed number of supported touches */
+#define CY_CAPSENSE_POSITION_MULTIPLE                   (0xFFu)
+/** Maximum possible centroid number */
+#define CY_CAPSENSE_MAX_CENTROIDS                       (3u)
+/** Maximum number of peaks in CSX Touchpad */
+#define CY_CAPSENSE_CSX_TOUCHPAD_MAX_PEAKS              (5u)
+/** Maximum age of a touch */
+#define CY_CAPSENSE_CSX_TOUCHPAD_MAX_AGE                (0xFFu)
+/** Undefined ID */
+#define CY_CAPSENSE_CSX_TOUCHPAD_ID_UNDEFINED           (0x80u)
+/** Non-assigned ID */
+#define CY_CAPSENSE_CSX_TOUCHPAD_ID_ABSENT              (0x40u)
+/** Touch below threshold ID */
+#define CY_CAPSENSE_CSX_TOUCHPAD_ID_ON_FAIL             (0x20u)
+/** Minimum ID */
+#define CY_CAPSENSE_CSX_TOUCHPAD_ID_MIN                 (0u)
+/** Maximum ID */
+#define CY_CAPSENSE_CSX_TOUCHPAD_ID_MAX                 (7u)
+/** ID mask */
+#define CY_CAPSENSE_CSX_TOUCHPAD_ID_MASK                (0x00FFu)
+/** Touch power mask */
+#define CY_CAPSENSE_CSX_TOUCHPAD_Z_MASK                 (0x00FFu)
+/** Age mask */
+#define CY_CAPSENSE_CSX_TOUCHPAD_AGE_MASK               (0xFF00u)
+/** Debounce mask */
+#define CY_CAPSENSE_CSX_TOUCHPAD_DEBOUNCE_MASK          (0xFF00u)
+/** \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_process *//** \{ */
+/******************************************************************************/
+/** Applies all enabled filters in the default order to the raw counts */
+#define CY_CAPSENSE_PROCESS_FILTER                      (0x01u)
+/** Updates baselines using current raw count values for the widget/sensor */
+#define CY_CAPSENSE_PROCESS_BASELINE                    (0x02u)
+/** Calculates differences for the widget/sensor */
+#define CY_CAPSENSE_PROCESS_DIFFCOUNTS                  (0x04u)
+/** Runs the noise envelope filter to measure noise magnitude for the widget/sensor */
+#define CY_CAPSENSE_PROCESS_CALC_NOISE                  (0x08u)
+/** Updates widget thresholds based on raw counts noise magnitude */
+#define CY_CAPSENSE_PROCESS_THRESHOLDS                  (0x10u)
+/** Runs the widget-specific processing algorithms and updates it status */
+#define CY_CAPSENSE_PROCESS_STATUS                      (0x20u)
+/** Applies median filter for MFS widget raw counts (applicable only for fifth-generation CAPSENSE&trade;) */
+#define CY_CAPSENSE_PROCESS_MFS_FILTER                  (0x40u)
+/** Definition that combines all possible processing tasks */
+#define CY_CAPSENSE_PROCESS_ALL                         (CY_CAPSENSE_PROCESS_FILTER | \
+                                                         CY_CAPSENSE_PROCESS_BASELINE | \
+                                                         CY_CAPSENSE_PROCESS_DIFFCOUNTS | \
+                                                         CY_CAPSENSE_PROCESS_CALC_NOISE | \
+                                                         CY_CAPSENSE_PROCESS_THRESHOLDS | \
+                                                         CY_CAPSENSE_PROCESS_STATUS | \
+                                                         CY_CAPSENSE_PROCESS_MFS_FILTER)
+/** Multi-phase TX min order */
+#define CY_CAPSENSE_MPTX_MIN_ORDER                      (4u)
+/** Multi-phase TX max order */
+#define CY_CAPSENSE_MPTX_MAX_ORDER                      (32u)
+/** \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_pin *//** \{ */
+/******************************************************************************/
+/** Connection of pin to ground */
+#define CY_CAPSENSE_GROUND                              (0u)
+/** Connection of pin to High-Z */
+#define CY_CAPSENSE_HIGHZ                               (1u)
+/** Configuring of pin as a shield */
+#define CY_CAPSENSE_SHIELD                              (2u)
+/** Configuring of pin as a CSD sensor */
+#define CY_CAPSENSE_SENSOR                              (3u)
+/** Configuring of pin as a Tx */
+#define CY_CAPSENSE_TX_PIN                              (4u)
+/** Configuring of pin as a Rx */
+#define CY_CAPSENSE_RX_PIN                              (5u)
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+/** Configuring of pin as a negative Tx
+ * \note This macro is available only for the fifth-generation CAPSENSE&trade;.
+ */
+#define CY_CAPSENSE_NEGATIVE_TX_PIN                     (6u)
+#endif /* CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN */
+/** Pin is not connected to scanning bus */
+#define CY_CAPSENSE_SNS_DISCONNECTED                    (0u)
+/** Pin is connected to scanning bus */
+#define CY_CAPSENSE_SNS_CONNECTED                       (1u)
+/** \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_miscellaneous *//** \{ */
+/******************************************************************************/
+/** Defines the communication command complete bit mask */
+#define CY_CAPSENSE_TU_CMD_COMPLETE_BIT                 (0x8000u)
+/** Defines the status if restart was not performed in Cy_CapSense_RunTuner() */
+#define CY_CAPSENSE_STATUS_RESTART_NONE                 (0x00u)
+/** Defines the status if restart was done in Cy_CapSense_RunTuner() */
+#define CY_CAPSENSE_STATUS_RESTART_DONE                 (0x01u)
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+/** Number of supported idac gains */
+#define CY_CAPSENSE_IDAC_GAIN_NUMBER                    (6u)
+#endif
+/** 100% value */
+#define CY_CAPSENSE_PERCENTAGE_100                      (100u)
+
+/* Scope of scanning macros */
+/** Widget scanning scope is a single sensor */
+#define CY_CAPSENSE_SCAN_SCOPE_SNGL_SNS                 (0x0u)
+/** Sensor scanning scope is a single widget */
+#define CY_CAPSENSE_SCAN_SCOPE_ALL_SNS_MASK             (0x01u)
+/** Widget scanning scope is all widgets */
+#define CY_CAPSENSE_SCAN_SCOPE_ALL_WD_MASK              (0x02u)
+/** Single slot scanning */
+#define CY_CAPSENSE_SCAN_SNGL_SLOT                      (0x1u)
+/** Multiple slot scanning */
+#define CY_CAPSENSE_SCAN_MULTIPLE_SLOT                  (0x0u)
+
+
+/** CAPSENSE&trade; related HW state is undefined */
+#define CY_CAPSENSE_HW_CONFIG_UNDEFINED                 (0u)
+/** CAPSENSE&trade; related HW is captured and configured to the default state */
+#define CY_CAPSENSE_HW_CONFIG_CAPTURED_DEFAULT          (1u)
+/** CAPSENSE&trade; related HW is configured to the standard regular scanning */
+#define CY_CAPSENSE_HW_CONFIG_REGULAR_SCANNING          (2u)
+/** CAPSENSE&trade; related HW is configured to execute the BIST functions */
+#define CY_CAPSENSE_HW_CONFIG_BIST_FUNCTIONALITY        (3u)
+
+/** \} */
+
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_bist *//** \{ */
+/******************************************************************************/
+/** The mask for a widget CRC test */
+#define CY_CAPSENSE_BIST_CRC_WDGT_MASK                              ((uint32_t)CY_CAPSENSE_TST_WDGT_CRC_EN << 0uL)
+/** The mask for a baseline integrity test */
+#define CY_CAPSENSE_BIST_BSLN_INTEGRITY_MASK                        ((uint32_t)CY_CAPSENSE_TST_BSLN_INTEGRITY_EN << 1uL)
+/** The mask for a rawcount integrity test */
+#define CY_CAPSENSE_BIST_RAW_INTEGRITY_MASK                         ((uint32_t)CY_CAPSENSE_TST_RAW_INTEGRITY_EN << 2uL)
+/** The mask for a pin integrity test */
+#define CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK                         ((uint32_t)CY_CAPSENSE_TST_SNS_SHORT_EN << 3uL)
+/** The mask for a sensor capacitance measurement test */
+#define CY_CAPSENSE_BIST_SNS_CAP_MASK                               ((uint32_t)CY_CAPSENSE_TST_SNS_CAP_EN << 4uL)
+/** The mask for a shield capacitance measurement test */
+#define CY_CAPSENSE_BIST_SHIELD_CAP_MASK                            ((uint32_t)CY_CAPSENSE_TST_SH_CAP_EN << 5uL)
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+    /** The mask for an external capacitor capacitance measurement test */
+    #define CY_CAPSENSE_BIST_EXTERNAL_CAP_MASK                      ((uint32_t)CY_CAPSENSE_TST_EXTERNAL_CAP_EN << 6uL)
+    /** The mask for a VDDA measurement test */
+    #define CY_CAPSENSE_BIST_VDDA_MASK                              ((uint32_t)CY_CAPSENSE_TST_VDDA_EN << 7uL)
+#else
+    /** The mask for an electrode capacitance measurement test */
+    #define CY_CAPSENSE_BIST_ELTD_CAP_MASK                          ((uint32_t)CY_CAPSENSE_TST_ELTD_CAP_EN << 8uL)
+#endif
+
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+    /** The mask for all enabled self-test functions */
+    #define CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK           (CY_CAPSENSE_BIST_CRC_WDGT_MASK | \
+                                                                    CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK | \
+                                                                    CY_CAPSENSE_BIST_SNS_CAP_MASK | \
+                                                                    CY_CAPSENSE_BIST_EXTERNAL_CAP_MASK |\
+                                                                    CY_CAPSENSE_BIST_VDDA_MASK |\
+                                                                    CY_CAPSENSE_BIST_SHIELD_CAP_MASK)
+
+    /** The mask for all enabled measurement self-test functions */
+    #define CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN                    (CY_CAPSENSE_BIST_EN && \
+                                                                    (CY_CAPSENSE_TST_SNS_CAP_EN || \
+                                                                    CY_CAPSENSE_TST_SH_CAP_EN ||\
+                                                                    CY_CAPSENSE_TST_VDDA_EN ||\
+                                                                    CY_CAPSENSE_TST_EXTERNAL_CAP_EN))
+
+    /** The mask for all enabled self-test functions which changes HW configuration */
+    #define CY_CAPSENSE_TST_HW_GROUP_EN                             (CY_CAPSENSE_BIST_EN && \
+                                                                    (CY_CAPSENSE_TST_SNS_SHORT_EN ||\
+                                                                    CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN))
+
+#else
+
+    /** The mask for all enabled self-test functions */
+    #define CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK           (CY_CAPSENSE_BIST_CRC_WDGT_MASK | \
+                                                                    CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK | \
+                                                                    CY_CAPSENSE_BIST_SNS_CAP_MASK | \
+                                                                    CY_CAPSENSE_BIST_ELTD_CAP_MASK | \
+                                                                    CY_CAPSENSE_BIST_SHIELD_CAP_MASK)
+
+    /** The mask for all enabled measurement self-test functions */
+    #define CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN                    (CY_CAPSENSE_BIST_EN && \
+                                                                    (CY_CAPSENSE_TST_SNS_CAP_EN || \
+                                                                    CY_CAPSENSE_TST_SH_CAP_EN ||\
+                                                                    CY_CAPSENSE_TST_ELTD_CAP_EN))
+
+    /** The mask for all enabled self-test functions which changes HW configuration */
+    #define CY_CAPSENSE_TST_HW_GROUP_EN                             (CY_CAPSENSE_BIST_EN && \
+                                                                    (CY_CAPSENSE_TST_SNS_SHORT_EN ||\
+                                                                    CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN))
+
+#endif
+
+/** \} */
+
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_status *//** \{ */
+/******************************************************************************/
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Successfully */
+#define CY_CAPSENSE_STATUS_SUCCESS                      (0x00u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Bad input parameter */
+#define CY_CAPSENSE_STATUS_BAD_PARAM                    (0x01u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Received wrong data */
+#define CY_CAPSENSE_STATUS_BAD_DATA                     (0x02u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Timeout */
+#define CY_CAPSENSE_STATUS_TIMEOUT                      (0x04u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Invalid state */
+#define CY_CAPSENSE_STATUS_INVALID_STATE                (0x08u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Bad configuration */
+#define CY_CAPSENSE_STATUS_BAD_CONFIG                   (0x10u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Overflow */
+#define CY_CAPSENSE_STATUS_CONFIG_OVERFLOW              (0x20u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: HW is busy */
+#define CY_CAPSENSE_STATUS_HW_BUSY                      (0x40u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: HW is locked */
+#define CY_CAPSENSE_STATUS_HW_LOCKED                    (0x80u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Unable to perform calibration */
+#define CY_CAPSENSE_STATUS_CALIBRATION_FAIL             (0x100u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Calibration scan with the maximum CDAC code is saturated */
+#define CY_CAPSENSE_STATUS_CALIBRATION_OVERFLOW         (0x200u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Unable to perform calibration */
+#define CY_CAPSENSE_STATUS_CALIBRATION_CHECK_FAIL       (0x400u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Sense Clock Divider
+*   is out of the valid range for the specified Clock source configuration
+*/
+#define CY_CAPSENSE_STATUS_BAD_CLOCK_CONFIG             (0x800u)
+/** Return status \ref cy_capsense_status_t of CAPSENSE&trade; operation: Unknown */
+#define CY_CAPSENSE_STATUS_UNKNOWN                      (0x80000000u)
+
+/** \} */
+
+#define CY_CAPSENSE_BYTES_IN_16_BITS                    (2u)
+#define CY_CAPSENSE_BYTE_IN_32_BIT                      (4u)
+#define CY_CAPSENSE_CONVERSION_MEGA                     (1000000u)
+#define CY_CAPSENSE_CONVERSION_KILO                     (1000u)
+#define CY_CAPSENSE_DIVIDER_TWO                         (2u)
+#define CY_CAPSENSE_16_BIT_MASK                         (0xFFFFu)
+
+/*
+* These defines are obsolete and kept for backward compatibility only.
+* They will be removed in the future versions.
+*/
+#define CY_CAPSENSE_MDW_VERSION_MAJOR                   (CY_CAPSENSE_MW_VERSION_MAJOR)
+#define CY_CAPSENSE_MDW_VERSION_MINOR                   (CY_CAPSENSE_MW_VERSION_MINOR)
+#define CY_CAPSENSE_MDW_ID                              (CY_CAPSENSE_ID)
+#define CY_CAPSENSE_SW_STS_BUSY                         (CY_CAPSENSE_BUSY)
+
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+#endif /* CY_CAPSENSE_COMMON_H */
+
+
+/* [] END OF FILE */

+ 1563 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_control.c

@@ -0,0 +1,1563 @@
+/***************************************************************************//**
+* \file cy_capsense_control.c
+* \version 3.0
+*
+* \brief
+* This file provides the source code to the Control module functions.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include <stddef.h>
+#include "cy_syslib.h"
+#include "cy_syspm.h"
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_control.h"
+#include "cy_capsense_processing.h"
+#include "cy_capsense_filter.h"
+#include "cy_capsense_tuner.h"
+#include "cy_capsense_sensing.h"
+#include "cy_capsense_selftest.h"
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+    #include "cy_capsense_sensing_v2.h"
+    #include "cy_csd.h"
+#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
+    #include "cy_capsense_sensing_v3.h"
+    #include "cy_msc.h"
+#endif
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_Init
+****************************************************************************//**
+*
+* Captures HW blocks (one or more) for CAPSENSE&trade; operations and configures them
+* to the default state. Call this function with the application program
+* prior to calling any other function of the middleware.
+*
+* The following tasks are executed:
+* 1. Capturing not used HW blocks. If any
+*    of HW block is
+*    already in use, then the function returns the fail status, and
+*    the application program should perform corresponding actions. For example, releasing
+*    the HW block captured by another middleware.
+* 2. If the HW block has been captured successfully, this function configures it
+*    to the default state.
+*
+* After the middleware is configured using the Cy_CapSense_Init() function,
+* the application program configures and enables the HW block interrupt(s),
+* and then call of the Cy_CapSense_Enable() function to complete the
+* middleware initialization process.
+* See the function usage example below for more details.
+*
+* When the middleware operation is stopped by the Cy_CapSense_DeInit()
+* function, subsequent call of the Cy_CapSense_Init() function repeats
+* initialization process and it is not needed to call the Cy_CapSense_Enable()
+* function second time. However, to implement time-multiplexed mode
+* (sharing the HW block(s) between multiple middleware)
+* the Cy_CapSense_Save() and Cy_CapSense_Restore() functions should be used
+* instead of the Cy_CapSense_DeInit() and Cy_CapSense_Init() functions for
+* further compatibility.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t
+* generated by the CAPSENSE&trade; Configurator tool. The structure contains both, CAPSENSE&trade;
+* configuration and internal data and it is used during whole CAPSENSE&trade; operation.
+*
+* \return
+* Returns the status of the initialization process. If CY_CAPSENSE_STATUS_SUCCESS is not
+* received, some of the initialization fails, the middleware may not operate
+* as expected, and repeating of initialization is required.
+*
+* \funcusage
+*
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Initialization
+* The 'cy_capsense_context' variable that is used as the parameter of the
+* Cy_CapSense_Init() and Cy_CapSense_Enable() functions is declared in the
+* cycfg_capsense.h file.
+*
+* The CapSense_ISR_cfg variable should be declared by the application
+* program according to the examples below:<br>
+* For PSoC&trade; 4 CPU or for PSoC&trade; 6 CM0+ core:
+* \snippet capsense/snippet/main.c snippet_m0p_capsense_interrupt_source_declaration
+*
+* For CM4 core:
+* \snippet capsense/snippet/main.c snippet_m4_capsense_interrupt_source_declaration
+*
+* The CAPSENSE&trade; interrupt handler should be declared by the application program
+* according to the example below:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_IntHandler
+*
+* The CapSense_HW is the pointer to the base register address of
+* the CAPSENSE&trade; HW block. A macro for the pointer is in the cycfg_peripherals.h
+* file defined as \<Personality_Name\>_HW. If no name is specified,
+* the following default names are used:
+* * csd_\<Block_Number\>_csd_\<Block_Number\>_HW - for forth-generation CAPSENSE&trade; HW.
+* * msc_\<Block_Number\>_msc_\<Block_Number\>_HW - for fifth-generation CAPSENSE&trade; HW.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_Init(cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t result = CY_CAPSENSE_STATUS_BAD_PARAM;
+    cy_stc_capsense_internal_context_t * ptrInternalCxt;
+
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+        #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN) || \
+             (CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_HW_EN))
+            uint32_t wdIndex;
+            cy_stc_capsense_widget_context_t * ptrWdCxt;
+            const cy_stc_capsense_widget_config_t * ptrWdCfg;
+        #endif
+        const cy_stc_capsense_common_config_t * ptrCommonCfg;
+    #endif
+
+    if (NULL != context)
+    {
+        ptrInternalCxt = context->ptrInternalContext;
+        ptrInternalCxt->intrCsdInactSnsConn = CY_CAPSENSE_SNS_CONNECTION_UNDEFINED;
+        ptrInternalCxt->intrCsxInactSnsConn = CY_CAPSENSE_SNS_CONNECTION_UNDEFINED;
+        ptrInternalCxt->ptrSSCallback = NULL;
+        ptrInternalCxt->ptrEOSCallback = NULL;
+        ptrInternalCxt->ptrTunerReceiveCallback = NULL;
+        ptrInternalCxt->ptrTunerSendCallback = NULL;
+
+        #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+            #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN) || \
+                 (CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_HW_EN))
+                ptrWdCfg = context->ptrWdConfig;
+                for (wdIndex = 0u; wdIndex < context->ptrCommonConfig->numWd; wdIndex++)
+                {
+                    ptrWdCxt = ptrWdCfg->ptrWdContext;
+                    if(CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod)
+                    {
+                        ptrWdCxt->snsClk = CY_CAPSENSE_SMARTSENSE_PRELIMINARY_SCAN_SNS_CLK;
+                        ptrWdCxt->rowSnsClk = CY_CAPSENSE_SMARTSENSE_PRELIMINARY_SCAN_SNS_CLK;
+                    }
+
+                    ptrWdCfg++;
+                }
+            #endif
+
+            ptrCommonCfg = context->ptrCommonConfig;
+            result = Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_UNDEFINED, context);
+
+            ptrInternalCxt->ptrEODsInitCallback = NULL;
+
+            ptrInternalCxt->numEpiCycles = ptrCommonCfg->numEpiCycles;
+            ptrInternalCxt->numCoarseInitChargeCycles = ptrCommonCfg->numCoarseInitChargeCycles;
+            ptrInternalCxt->numCoarseInitSettleCycles = ptrCommonCfg->numCoarseInitSettleCycles;
+            ptrInternalCxt->numFineInitWaitCycles = context->ptrCommonContext->numFineInitWaitCycles;
+            ptrInternalCxt->numProOffsetCycles = ptrCommonCfg->numProOffsetCycles;
+            ptrInternalCxt->proOffsetCdacComp = ptrCommonCfg->proOffsetCdacComp;
+
+            /* Set auto-calibration internal parameters */
+            ptrInternalCxt->intrCsdRawTarget = ptrCommonCfg->csdRawTarget;
+            ptrInternalCxt->intrCsxRawTarget = ptrCommonCfg->csxRawTarget;
+
+            #if (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE)
+                /* Set undefined value to initiate DMA configuration in Cy_CapSense_ScanSlots() function */
+                context->ptrInternalContext->currentSlotIndex = CY_CAPSENSE_SLOT_COUNT_MAX_VALUE;
+            #endif
+
+            if (CY_CAPSENSE_STATUS_SUCCESS == result)
+            {
+                result = Cy_CapSense_Restore(context);
+            }
+        #else
+            result = Cy_CapSense_Restore(context);
+        #endif
+
+        /* The time interval is required for settling analog part of the HW block. */
+        Cy_SysLib_DelayUs(CY_CAPSENSE_ANALOG_SETTLING_TIME_US);
+    }
+
+    return result;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_Enable
+****************************************************************************//**
+*
+* Initializes the CAPSENSE&trade; firmware modules.
+*
+* Call the Cy_CapSense_Init() function and configure CAPSENSE&trade; HW block interrupts
+* prior to calling this function.
+* See the function usage example below for details on usage.
+*
+* The following are executed as part of the function:
+* 1. Check CAPSENSE&trade; configuration integrity.
+* 2. Pre-calculate of internal register values to speed up operation.
+* 3. Configure the CAPSENSE&trade; HW block to perform capacitive sensing operation.
+* 4. If the smart sensing algorithm is selected for the CSD Tuning mode in the
+*    Basic tab, the auto-tuning functionality is executed to set the optimal
+*    values for the CAPSENSE&trade; HW block parameters of the widgets/sensors.
+* 5. Calibrate the sensors and find the optimal values for DACs of each widget/sensor,
+*    if the auto-calibration is enabled in the CSD Setting or CSX Setting tabs.
+* 6. Perform scanning for all the sensors and initialize the baseline history.
+* 7. If the firmware filters are enabled in the Advanced General tab, the
+*    filter histories are also initialized.
+*
+* Any subsequent call of this function repeats initialization process.
+* Therefore, it is possible to change the middleware configuration
+* from the application program by writing registers to the data structure
+* and calling this function again.
+*
+* The repeated call of this function is also done inside the
+* Cy_CapSense_RunTuner() function when a restart command is received.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the initialization process. If CY_CAPSENSE_STATUS_SUCCESS is not
+* received, some of the initialization fails.
+*
+* \funcusage
+*
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Initialization
+* The 'cy_capsense_context' variable that is used as the parameter of the
+* Cy_CapSense_Init() and Cy_CapSense_Enable() functions is declared in the
+* cycfg_capsense.h file.
+*
+* The CapSense_ISR_cfg variable should be declared by the application
+* program according to the examples below:<br>
+* For CM0+ core:
+* \snippet capsense/snippet/main.c snippet_m0p_capsense_interrupt_source_declaration
+*
+* For CM4 core:
+* \snippet capsense/snippet/main.c snippet_m4_capsense_interrupt_source_declaration
+*
+* The CAPSENSE&trade; interrupt handler should be declared by the application program
+* according to the example below:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_IntHandler
+*
+* The CapSense_HW is the pointer to the base register address of
+* the CAPSENSE&trade; HW block. A macro for the pointer is in the cycfg_peripherals.h
+* file defined as \<Personality_Name\>_HW. If no name is specified,
+* the following default names are used:
+* * csd_\<Block_Number\>_csd_\<Block_Number\>_HW - for forth-generation CAPSENSE&trade; HW.
+* * msc_\<Block_Number\>_msc_\<Block_Number\>_HW - for fifth-generation CAPSENSE&trade; HW.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_Enable(cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t result;
+    uint32_t cpuFreqMHz;
+    uint32_t watchdogCounter;
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+        context->ptrCommonContext->status |= CY_CAPSENSE_MW_STATE_INITIALIZATION_MASK;
+        uint32_t widgetId;
+    #endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
+
+    /* Approximate duration of Wait For Init loop */
+    const uint32_t isBusyLoopDuration = 5uL;
+
+    /* Wait For Init watchdog timeout in microseconds */
+    const uint32_t isBusyWatchdogTimeUs = 1000000uL;
+
+    /* Initialize CAPSENSE&trade; modules */
+    result = Cy_CapSense_Initialize(context);
+
+    if(CY_CAPSENSE_STATUS_SUCCESS == result)
+    {
+        #if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+            #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN) || \
+                 (CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_HW_EN))
+                result |= Cy_CapSense_SsAutoTune(context);
+            #elif (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN)
+                    result |= Cy_CapSense_CalibrateAllCsdWidgets(context);
+            #endif
+
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN)
+                result |= Cy_CapSense_CalibrateAllCsxWidgets(context);
+            #endif
+        #else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
+            #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN) || \
+                 (CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_HW_EN))
+                result |= Cy_CapSense_SsAutoTune(context);
+            #endif
+            #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) || \
+                (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN))
+                {
+                    result |= Cy_CapSense_CalibrateAllSlots(context);
+                }
+            #endif
+        #endif
+
+        result |= Cy_CapSense_ScanAllWidgets(context);
+
+        /* Init Watchdog Counter to prevent a hang */
+        cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
+        watchdogCounter = Cy_CapSense_WatchdogCyclesNum(isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
+        while (CY_CAPSENSE_NOT_BUSY != Cy_CapSense_IsBusy(context))
+        {
+            if(0uL == watchdogCounter)
+            {
+                break;
+            }
+
+            watchdogCounter--;
+        }
+
+        #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+            for (widgetId = 0u; widgetId < context->ptrCommonConfig->numWd; widgetId++)
+            {
+                Cy_CapSense_PreProcessWidget(widgetId, context);
+                #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_PHASE_ENABLED)
+                    if (CY_CAPSENSE_MPTX_MIN_ORDER <= context->ptrWdConfig[widgetId].mptxOrder)
+                    {
+                        result |= Cy_CapSense_ProcessWidgetMptxDeconvolution(widgetId, context);
+                    }
+                #endif
+            }
+        #endif
+    }
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
+        Cy_CapSense_InitializeAllFilters(context);
+    #endif
+    Cy_CapSense_InitializeAllBaselines(context);
+
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+        context->ptrCommonContext->status &= ~(uint32_t)CY_CAPSENSE_MW_STATE_INITIALIZATION_MASK;
+    #endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
+
+    return result;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_Initialize
+****************************************************************************//**
+*
+* Initializes all sub-modules of the CAPSENSE&trade; middleware.
+*
+* The initialization includes:
+* - Data Structure - set the default middleware parameters based
+*   on configuration.
+* - Data Processing - resets the status all widgets.
+* - Tuner - resets the tuner communication state.
+* - Sensing - prepares the CAPSENSE&trade; HW blocks for operation.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Return CY_CAPSENSE_STATUS_SUCCESS if the initialization was successful.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_Initialize(cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t result;
+
+    result = Cy_CapSense_CheckConfigIntegrity(context);
+    if (CY_CAPSENSE_STATUS_SUCCESS == result)
+    {
+        Cy_CapSense_InitializeAllStatuses(context);
+
+        result |= Cy_CapSense_SsInitialize(context);
+
+        /* The Tuner and the BIST are initialized only once */
+        if (CY_CAPSENSE_INIT_NEEDED == context->ptrCommonContext->initDone)
+        {
+            Cy_CapSense_TuInitialize(context);
+
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN)
+                Cy_CapSense_BistDsInitialize(context);
+            #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) */
+
+            context->ptrCommonContext->initDone = CY_CAPSENSE_INIT_DONE;
+        }
+    }
+
+    return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_DeInit
+****************************************************************************//**
+*
+* Stops the middleware operation and releases the CAPSENSE&trade; captured HW blocks.
+*
+* No sensor scanning can be executed when the middleware is stopped.
+* This function should be called only when no scanning is in progress.
+* I.e. Cy_CapSense_IsBusy() returns a non-busy status.
+*
+* After the middleware stops, the CAPSENSE&trade; HW block(s) may be reconfigured with the
+* application program or other middleware for any other usage.
+*
+* When the middleware operation is stopped by the Cy_CapSense_DeInit()
+* function, subsequent call of the Cy_CapSense_Init() function repeats
+* initialization process and it is not needed to call the Cy_CapSense_Enable()
+* function second time. However, to implement time-multiplexed mode
+* (sharing the CAPSENSE&trade; HW block(s) between multiple middleware)
+* the Cy_CapSense_Save() and Cy_CapSense_Restore() functions should be used
+* instead of the Cy_CapSense_DeInit() and Cy_CapSense_Init() functions for
+* further compatibility.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the stop process. If CY_CAPSENSE_STATUS_SUCCESS is not received,
+* the stop process fails and retries may be required.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_DeInit(cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t result;
+
+    result = Cy_CapSense_Save(context);
+    if (CY_CAPSENSE_STATUS_SUCCESS != result)
+    {
+        result = CY_CAPSENSE_STATUS_BAD_DATA;
+    }
+    else
+    {
+        context->ptrCommonContext->initDone = CY_CAPSENSE_INIT_NEEDED;
+    }
+
+    return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_ProcessAllWidgets
+****************************************************************************//**
+*
+* Performs full data processing of all enabled widgets.
+*
+* This function performs all data processes for all enabled widgets and
+* sensors in the middleware to produce meaningful status output from widgets
+* and sensors. The following tasks are executed as part of processing all the
+* widgets:
+* 1. Apply raw count filters to the raw counts, if they are enabled.
+* 2. Update the thresholds if the smart sensing algorithm Full Auto-Tuning
+*    is enabled.
+* 3. Update the baselines and difference counts for all the sensors.
+* 4. Update the sensor and widget output status. Updates on/off status for
+*    buttons and proximity widgets, centroid/position for
+*    the sliders and the X/Y position for the touchpads.
+*
+* This function is called by the application program only after all the enabled
+* widgets (and sensors) in the middleware are scanned. Calling this function
+* multiple times without sensor scanning causes unexpected behavior.
+*
+* The disabled widgets are not processed by this function.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the processing operation. If CY_CAPSENSE_STATUS_SUCCESS is not received,
+* the processing fails and retries may be required.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_ProcessAllWidgets(cy_stc_capsense_context_t * context)
+{
+    uint32_t wdIndex;
+    cy_capsense_status_t result = CY_CAPSENSE_STATUS_SUCCESS;
+
+    for (wdIndex = context->ptrCommonConfig->numWd; wdIndex-- > 0u;)
+    {
+        #if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) && (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN))
+            if (0u == ((&context->ptrWdConfig[wdIndex])->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_ALL_CH_MASK))
+            {
+                /* Processes all widgets with disabled MFS and all widgets with original (main) frequency */
+                result |= Cy_CapSense_ProcessWidget(wdIndex, context);
+            }
+        #else
+            result |= Cy_CapSense_ProcessWidget(wdIndex, context);
+        #endif
+    }
+    return result;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_ProcessWidget
+****************************************************************************//**
+*
+* Performs full data processing of the specified widget if it is enabled.
+*
+* This function performs exactly the same tasks as
+* Cy_CapSense_ProcessAllWidgets(), but only for a specified widget. This
+* function can be used along with the Cy_CapSense_SetupWidget() and
+* Cy_CapSense_Scan() functions (4th Generation) to scan and process data for a specific
+* widget or with the Cy_CapSense_ScanSlots() function (5th Generation).
+* This function is called only after all the sensors in the
+* widgets are scanned. A disabled widget is not processed by this function.
+*
+* A pipeline scan method (i.e. during scanning of a current widget (N),
+* perform processing of the previously scanned widget (N-1)) can be
+* implemented using this function and it may reduce the total execution time,
+* increase the refresh rate, and decrease the average power consumption.
+* See the function usage example below for details on usage.
+*
+* For the Fifth generation CapSense if the specified widget has the enabled
+* multi-frequency scan feature then the function does the following:
+* - If the specified widget ID refers to main (base) frequency then the function
+* processes raw count processing of all three widgets (main and two sub-widgets)
+* and then status processing of the main widget only.
+* - If the specified widget ID refers to sub-widgets (1st or 2nd frequency channels)
+* then the function returns CY_CAPSENSE_STATUS_BAD_PARAM. To perform customized
+* processing use the Cy_CapSense_ProcessWidgetExt() function.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the widget processing:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is successfully completed
+* - CY_CAPSENSE_STATUS_BAD_PARAM     - The input parameter is invalid
+* - CY_CAPSENSE_STATUS_INVALID_STATE - The specified widget is disabled
+* - CY_CAPSENSE_STATUS_BAD_DATA      - The processing is failed
+*
+* \funcusage
+*
+* An example of pipeline implementation:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_ProcessWidget
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_ProcessWidget(
+                uint32_t widgetId,
+                cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t result = CY_CAPSENSE_STATUS_SUCCESS;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+
+    /* Check parameter validity */
+    if (widgetId >= context->ptrCommonConfig->numWd)
+    {
+        result = CY_CAPSENSE_STATUS_BAD_PARAM;
+    }
+
+    if (CY_CAPSENSE_STATUS_SUCCESS == result)
+    {
+        ptrWdCfg = &context->ptrWdConfig[widgetId];
+        /* Check widget enable status */
+        if (0u != (ptrWdCfg->ptrWdContext->status & CY_CAPSENSE_WD_DISABLE_MASK))
+        {
+            result = CY_CAPSENSE_STATUS_INVALID_STATE;
+        }
+        #if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) && (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN))
+            /* Check for sub-widget */
+            if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_ALL_CH_MASK))
+            {
+                result |= CY_CAPSENSE_STATUS_BAD_PARAM;
+            }
+        #endif
+    }
+
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+        if (CY_CAPSENSE_STATUS_SUCCESS == result)
+        {
+            #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
+                if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK))
+                {
+                    Cy_CapSense_PreProcessWidget(widgetId + CY_CAPSENSE_MFS_CH2_INDEX, context);
+                    Cy_CapSense_PreProcessWidget(widgetId + CY_CAPSENSE_MFS_CH1_INDEX, context);
+                }
+            #endif
+            Cy_CapSense_PreProcessWidget(widgetId, context);
+        }
+    #endif
+
+    if (CY_CAPSENSE_STATUS_SUCCESS == result)
+    {
+        switch(ptrWdCfg->senseMethod)
+        {
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+                case CY_CAPSENSE_CSD_GROUP:
+                    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
+                        if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK))
+                        {
+                            /* Processes all sub-widgets of MFS widgets with derivative frequency */
+                            result |= Cy_CapSense_DpProcessCsdWidgetRawCounts(widgetId + CY_CAPSENSE_MFS_CH2_INDEX, context);
+                            result |= Cy_CapSense_DpProcessCsdWidgetRawCounts(widgetId + CY_CAPSENSE_MFS_CH1_INDEX, context);
+                        }
+                    #endif
+                    result |= Cy_CapSense_DpProcessCsdWidgetRawCounts(widgetId, context);
+                    Cy_CapSense_DpProcessCsdWidgetStatus(ptrWdCfg, context);
+                    break;
+            #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+                case CY_CAPSENSE_CSX_GROUP:
+                    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
+                        if (0u != (ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK))
+                        {
+                            /* Processes all sub-widgets of MFS widgets with derivative frequency */
+                            #if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) && (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_PHASE_ENABLED))
+                                if (CY_CAPSENSE_MPTX_MIN_ORDER <= ptrWdCfg->mptxOrder)
+                                {
+                                    result |= Cy_CapSense_ProcessWidgetMptxDeconvolution(widgetId + CY_CAPSENSE_MFS_CH2_INDEX, context);
+                                    result |= Cy_CapSense_ProcessWidgetMptxDeconvolution(widgetId + CY_CAPSENSE_MFS_CH1_INDEX, context);
+                                }
+                            #endif
+                            result |= Cy_CapSense_DpProcessCsxWidgetRawCounts(widgetId + CY_CAPSENSE_MFS_CH2_INDEX, context);
+                            result |= Cy_CapSense_DpProcessCsxWidgetRawCounts(widgetId + CY_CAPSENSE_MFS_CH1_INDEX, context);
+                        }
+                    #endif
+                    #if ((CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) && (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_PHASE_ENABLED))
+                        if (CY_CAPSENSE_MPTX_MIN_ORDER <= ptrWdCfg->mptxOrder)
+                        {
+                            result |= Cy_CapSense_ProcessWidgetMptxDeconvolution(widgetId, context);
+                        }
+                    #endif
+                    result |= Cy_CapSense_DpProcessCsxWidgetRawCounts(widgetId, context);
+                    Cy_CapSense_DpProcessCsxWidgetStatus(ptrWdCfg);
+                    break;
+            #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+            default:
+                result |= CY_CAPSENSE_STATUS_BAD_PARAM;
+                break;
+        }
+    }
+
+    return result;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_ProcessWidgetExt
+****************************************************************************//**
+*
+* Performs customized data processing on the selected widget.
+*
+* This function performs customized data processing specified by the mode
+* parameter on a widget. This function can be used with any of the
+* available scan functions. This function should be called only after all
+* the sensors in the specified widget are scanned. Calling this function
+* multiple times with the same mode without new sensor scan causes
+* unexpected behavior. This function ignores the value of the
+* wdgtEnable register.
+*
+* The CY_CAPSENSE_PROCESS_CALC_NOISE and CY_CAPSENSE_PROCESS_THRESHOLDS masks
+* for mode parameter are supported only when smart sensing algorithm is enabled
+* for CSD widgets.
+*
+* The execution order of processing tasks starts from LSB to MSB of the
+* mode parameter. To implement a different order of execution, call this
+* function multiple times with the required mode parameter.
+*
+* For more details, refer to function usage example below.
+*
+* \note
+* For the the fifth-generation CAPSENSE&trade; an extra processing should be
+* performed prior a call of this function:
+* * A raw count pre-processing calling either the Cy_CapSense_PreProcessWidget()
+*   or Cy_CapSense_PreProcessSensor() functions.
+* * A deconvolution for widgets with multi-phase Tx calling the
+*   Cy_CapSense_ProcessWidgetMptxDeconvolution() function.
+* In this case a full processing flow consists of the following:
+* * Cy_CapSense_PreProcessWidget()
+* * Cy_CapSense_ProcessWidgetMptxDeconvolution()
+* * Cy_CapSense_ProcessWidgetExt()
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param mode
+* Specifies the type of widget processing to be executed for the
+* specified widget:
+* 1. Bits [31..7] - Reserved.
+* 2. Bits [6..0]  - CY_CAPSENSE_PROCESS_ALL - Execute all of the below tasks.
+* 3. Bit [6]      - CY_CAPSENSE_PROCESS_MFS_FILTER - Run the firmware filters
+*                   for MFS on sensor rawcounts
+*                   (applicable only for fifth-generation CAPSENSE&trade;).
+* 4. Bit [5]      - CY_CAPSENSE_PROCESS_STATUS - Update the status
+*                   (on/off, centroid position).
+* 5. Bit [4]      - CY_CAPSENSE_PROCESS_THRESHOLDS - Update the thresholds
+*                   (only in CSD auto-tuning mode).
+* 6. Bit [3]      - CY_CAPSENSE_PROCESS_CALC_NOISE - Calculate the noise
+*                   (only in CSD auto-tuning mode).
+* 7. Bit [2]      - CY_CAPSENSE_PROCESS_DIFFCOUNTS - Update the difference
+*                   counts of each sensor.
+* 8. Bit [1]      - CY_CAPSENSE_PROCESS_BASELINE - Update the baselines
+*                   for all sensor.
+* 9. Bit [0]      - CY_CAPSENSE_PROCESS_FILTER - Run the firmware filters
+*                   on sensor rawcounts.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the widget processing operation:
+* - CY_CAPSENSE_STATUS_SUCCESS      - The processing is successfully performed.
+* - CY_CAPSENSE_STATUS_BAD_PARAM    - The input parameter is invalid.
+* - CY_CAPSENSE_STATUS_BAD_DATA     - The processing failed.
+*
+* \funcusage
+*
+* An example of customized data processing, changed processing order:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_ProcessWidgetExt
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_ProcessWidgetExt(
+                uint32_t widgetId,
+                uint32_t mode,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+    cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
+    uint32_t snsHistorySize;
+    uint32_t freqChIndex;
+    uint16_t * ptrHistorySns;
+    uint16_t * ptrBslnInvSns;
+    uint8_t * ptrHistoryLowSns = NULL;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxtSns;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+
+    /* Check parameter validity */
+    if (widgetId < context->ptrCommonConfig->numWd)
+    {
+        ptrWdCfg = &context->ptrWdConfig[widgetId];
+        snsHistorySize = (uint32_t)ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_MASK;
+
+        /* Run the desired processing for the all CSD widget sensors */
+        for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+        {
+            ptrSnsCxtSns = &ptrWdCfg->ptrSnsContext[freqChIndex * context->ptrCommonConfig->numSns];
+            ptrBslnInvSns = &ptrWdCfg->ptrBslnInv[freqChIndex * context->ptrCommonConfig->numSns];
+            ptrHistorySns = &ptrWdCfg->ptrRawFilterHistory[freqChIndex * (CY_CAPSENSE_RAW_HISTORY_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)];
+            if(CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
+            {
+                ptrHistoryLowSns = &ptrWdCfg->ptrRawFilterHistoryLow[freqChIndex *
+                        (CY_CAPSENSE_IIR_HISTORY_LOW_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)];
+            }
+
+            for (snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
+            {
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+                    if (CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod)
+                    {
+                            capStatus = Cy_CapSense_DpProcessCsxSensorRawCountsExt(ptrWdCfg, ptrSnsCxtSns,
+                                    ptrHistorySns, ptrHistoryLowSns, mode, ptrBslnInvSns, context);
+                    }
+                #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+                    if (CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod)
+                    {
+                        capStatus = Cy_CapSense_DpProcessCsdSensorRawCountsExt(ptrWdCfg, ptrSnsCxtSns,
+                                ptrHistorySns, ptrHistoryLowSns, mode, ptrBslnInvSns, context);
+                    }
+                #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+                /* Placeholder for further methods */
+
+                ptrSnsCxtSns++;
+                ptrBslnInvSns++;
+                ptrHistorySns += snsHistorySize;
+                if(NULL != ptrHistoryLowSns)
+                {
+                    ptrHistoryLowSns++;
+                }
+            }
+        }
+
+        #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN) && \
+            (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN))
+            ptrSnsCxtSns = ptrWdCfg->ptrSnsContext;
+            for (snsIndex = ptrWdCfg->numSns; snsIndex-- > 0u;)
+            {
+                Cy_CapSense_RunMfsFiltering(ptrSnsCxtSns, context);
+                ptrSnsCxtSns++;
+            }
+        #endif
+
+        #if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN) && \
+             (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN))
+            if (0u != (mode & CY_CAPSENSE_PROCESS_MFS_FILTER))
+            {
+                (void) Cy_CapSense_RunMfsMedian(widgetId, context);
+            }
+        #endif
+
+        if (0u != (mode & CY_CAPSENSE_PROCESS_STATUS))
+        {
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+                if (CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod)
+                {
+                    Cy_CapSense_DpProcessCsxWidgetStatus(ptrWdCfg);
+                }
+            #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+                if (CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod)
+                {
+                    Cy_CapSense_DpProcessCsdWidgetStatus(ptrWdCfg, context);
+                }
+            #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+            /* Placeholder for further methods */
+        }
+    }
+    return capStatus;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_ProcessSensorExt
+****************************************************************************//**
+*
+* Performs customized data processing on the selected sensor.
+*
+* This function performs customized data processing specified by the mode
+* parameter on a sensor. This function performs the exact same task
+* of the Cy_CapSense_ProcessWidgetExt() function but only on the specified
+* sensor instead of all sensors in the widget.
+*
+* The pipeline scan method (i.e. during scanning of a sensor, processing
+* of a previously scanned sensor is performed) can be implemented using this
+* function and it may reduce the total scan/process time, increase the refresh
+* rate, and decrease the power consumption. For more details, refer to
+* function usage example below.
+*
+* \note
+* For the the fifth CAPSENSE&trade; HW generation an extra processing should be
+* performed prior a call of this function:
+* * A raw count pre-processing calling either the Cy_CapSense_PreProcessWidget()
+*   or Cy_CapSense_PreProcessSensor() functions.
+* * A deconvolution for widgets with multi-phase Tx calling the
+*   Cy_CapSense_ProcessWidgetMptxDeconvolution() function.
+* In this case a full processing flow consists of the following:
+* * Cy_CapSense_PreProcessWidget()
+* * Cy_CapSense_ProcessWidgetMptxDeconvolution()
+* * Cy_CapSense_ProcessSensorExt() - each sensor
+* * Cy_CapSense_ProcessWidgetExt()
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* file defined as CY_CAPSENSE_<WIDGET_NAME>_SNS<SENSOR_NUMBER>_ID.
+*
+* \param mode
+* Specifies the type of the sensor processing that must be executed for the
+* specified sensor:
+* 1. Bits [31..5] - Reserved
+* 2. Bits [4..0]  - CY_CAPSENSE_PROCESS_ALL - Executes all the tasks
+* 3. Bit [4]      - CY_CAPSENSE_PROCESS_THRESHOLDS - Updates the thresholds
+*                   (only in auto-tuning mode)
+* 4. Bit [3]      - CY_CAPSENSE_PROCESS_CALC_NOISE - Calculates the noise
+*                   (only in auto-tuning mode)
+* 5. Bit [2]      - CY_CAPSENSE_PROCESS_DIFFCOUNTS - Updates the diff count
+* 6. Bit [1]      - CY_CAPSENSE_PROCESS_BASELINE - Updates the baseline
+* 7. Bit [0]      - CY_CAPSENSE_PROCESS_FILTER - Runs the firmware filters
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the sensor process operation:
+* - CY_CAPSENSE_STATUS_SUCCESS      - The processing is successfully performed.
+* - CY_CAPSENSE_STATUS_BAD_PARAM    - The input parameter is invalid.
+* - CY_CAPSENSE_STATUS_BAD_DATA     - The processing failed.
+*
+* \funcusage
+*
+* An example demonstrates pipeline implementation of sensor scanning and
+* processing:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_ProcessSensorExt
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_ProcessSensorExt(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                uint32_t mode,
+                const cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
+    uint32_t freqChIndex;
+    uint32_t snsHistorySize;
+    uint16_t * ptrSnsBslnInv;
+    uint16_t * ptrHistory;
+    uint8_t  * ptrHistoryLow = NULL;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+
+    if (widgetId < context->ptrCommonConfig->numWd)
+    {
+        ptrWdCfg = &context->ptrWdConfig[widgetId];
+        if (sensorId < ptrWdCfg->numSns)
+        {
+            snsHistorySize = (uint32_t)ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_MASK;
+            capStatus = CY_CAPSENSE_STATUS_SUCCESS;
+
+            for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+            {
+                ptrSnsCxt = &ptrWdCfg->ptrSnsContext[sensorId + (freqChIndex * context->ptrCommonConfig->numSns)];
+                ptrSnsBslnInv = &ptrWdCfg->ptrBslnInv[sensorId + (freqChIndex * context->ptrCommonConfig->numSns)];
+                ptrHistory = &ptrWdCfg->ptrRawFilterHistory[(freqChIndex * (CY_CAPSENSE_RAW_HISTORY_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)) +
+                                                            (snsHistorySize * sensorId)];
+                if(CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
+                {
+                    ptrHistoryLow = &ptrWdCfg->ptrRawFilterHistoryLow[freqChIndex *
+                            (CY_CAPSENSE_IIR_HISTORY_LOW_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)];
+                }
+
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+                    if (CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod)
+                    {
+                        capStatus = Cy_CapSense_DpProcessCsxSensorRawCountsExt(ptrWdCfg, ptrSnsCxt,
+                                ptrHistory, ptrHistoryLow, mode, ptrSnsBslnInv, context);
+                    }
+                #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+                    if (CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod)
+                    {
+                        capStatus = Cy_CapSense_DpProcessCsdSensorRawCountsExt(ptrWdCfg, ptrSnsCxt,
+                                ptrHistory, ptrHistoryLow, mode, ptrSnsBslnInv, context);
+                    }
+                #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+                /* Placeholder for further methods */
+            }
+            #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+                ptrSnsCxt = ptrWdCfg->ptrSnsContext;
+                Cy_CapSense_RunMfsFiltering(ptrSnsCxt, context);
+            #endif
+        }
+    }
+    return capStatus;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_Wakeup
+****************************************************************************//**
+*
+* Resumes the middleware after System Deep Sleep.
+*
+* This function is used to resume the middleware operation after exiting
+* System Deep Sleep. After the CAPSENSE&trade; HW block is powered off,
+* an extra delay is required to establish the correct operation of
+* the CAPSENSE&trade; HW block.
+*
+* This function is called by the Cy_CapSense_DeepSleepCallback() function after
+* exiting System Deep Sleep if the CAPSENSE&trade; Deep Sleep callback is registered.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_Wakeup(const cy_stc_capsense_context_t * context)
+{
+    Cy_SysLib_DelayUs((uint16_t)context->ptrCommonConfig->analogWakeupDelay);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_DeepSleepCallback
+****************************************************************************//**
+*
+* Handles CPU active to System Deep Sleep power mode transition for the CAPSENSE&trade;
+* 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&trade; 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 an input, this
+* function returns CY_SYSPM_SUCCESS if no scanning is in progress or not
+* a single HW block is captured by the CAPSENSE&trade; middleware. 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.
+*
+* When this function is called with CY_SYSPM_AFTER_TRANSITION as an input, then
+* the Cy_CapSense_Wakeup() function is called to resume the middleware
+* operation after exiting System Deep Sleep. If there are no CAPSENSE&trade; captured
+* HW blocks the Cy_CapSense_Wakeup() function calling is omitted and restoring
+* CAPSENSE&trade; immediately after Deep Sleep without the wake-up delay can lead to
+* unpredictable behavior.
+*
+* For details of SysPm types and macros refer to the SysPm section of the
+* PDL documentation.
+*
+* \param callbackParams
+* Refer to the description of the cy_stc_syspm_callback_params_t type in the
+* Peripheral Driver Library documentation.
+*
+* \param mode
+* Specifies mode cy_en_syspm_callback_mode_t.
+*
+* \return
+* Returns the status cy_en_syspm_status_t of the operation requested
+* by the mode parameter:
+* - 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(
+                cy_stc_syspm_callback_params_t * callbackParams,
+                cy_en_syspm_callback_mode_t mode)
+{
+    cy_en_syspm_status_t retVal = CY_SYSPM_SUCCESS;
+    const cy_stc_capsense_context_t * capsenseCxt = (cy_stc_capsense_context_t *)callbackParams->context;
+
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+        cy_en_csd_key_t mwKey;
+
+        switch(mode)
+        {
+            case CY_SYSPM_CHECK_READY:
+                mwKey = Cy_CSD_GetLockStatus(capsenseCxt->ptrCommonConfig->ptrCsdBase, capsenseCxt->ptrCommonConfig->ptrCsdContext);
+
+                if (CY_CSD_CAPSENSE_KEY == mwKey)
+                {
+                    if (CY_CAPSENSE_NOT_BUSY != Cy_CapSense_IsBusy(capsenseCxt))
+                    {
+                        retVal = CY_SYSPM_FAIL;
+                    }
+                }
+                break;
+
+            case CY_SYSPM_AFTER_TRANSITION:
+                mwKey = Cy_CSD_GetLockStatus(capsenseCxt->ptrCommonConfig->ptrCsdBase, capsenseCxt->ptrCommonConfig->ptrCsdContext);
+
+                if (CY_CSD_CAPSENSE_KEY == mwKey)
+                {
+                    Cy_CapSense_Wakeup(capsenseCxt);
+                }
+                break;
+
+            default:
+                /* No action for other modes */
+                break;
+        }
+    #else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
+        uint32_t curChIndex;
+        const cy_stc_msc_channel_config_t * ptrMscChCfg = &capsenseCxt->ptrCommonConfig->ptrMscChConfig[0u];
+
+        switch(mode)
+        {
+            case CY_SYSPM_CHECK_READY:
+                if (CY_CAPSENSE_NOT_BUSY != Cy_CapSense_IsBusy(capsenseCxt))
+                {
+                    retVal = CY_SYSPM_FAIL;
+                }
+                break;
+
+            case CY_SYSPM_AFTER_TRANSITION:
+                for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+                {
+                    if (CY_MSC_CAPSENSE_KEY == Cy_MSC_GetLockStatus(ptrMscChCfg->ptrMscBase,
+                                                                    ptrMscChCfg->ptrMscContext))
+                    {
+                        Cy_CapSense_Wakeup(capsenseCxt);
+                        break;
+                    }
+                    ptrMscChCfg++;
+                }
+                break;
+
+            default:
+                /* No action for other modes */
+                break;
+        }
+    #endif
+
+    return(retVal);
+}
+
+#if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_GESTURE_EN) || \
+     (CY_CAPSENSE_DISABLE != CY_CAPSENSE_BALLISTIC_MULTIPLIER_EN))
+/*******************************************************************************
+* Function Name: Cy_CapSense_IncrementGestureTimestamp
+****************************************************************************//**
+*
+* Increments the timestamp register for the predefined timestamp interval.
+*
+* A timestamp is required for operation of the Gesture and Ballistic multiplier
+* feature. Hence this function and timestamp is required only if the Gesture
+* detection or Ballistic multiplier feature is enabled.
+*
+* This function increments the timestamp by the interval specified
+* in the context->ptrCommonContext->timestampInterval register. The unit for
+* the timestamp and timestamp interval is milliseconds and the default value of the
+* interval is 1.
+*
+* The application program must periodically call this
+* function or register a periodic callback to this function to keep the
+* timestamp updated and operational for the operation of the Gesture and
+* Ballistic multiplier feature.
+*
+* The timestamp can be updated in one of the three methods:
+* 1. Register a periodic callback for the
+*    Cy_CapSense_IncrementGestureTimestamp() function.
+* 2. Periodically call the Cy_CapSense_IncrementGestureTimestamp() function
+*    from the application program.
+* 3. Directly modify the timestamp using the
+*    Cy_CapSense_SetGestureTimestamp() function.
+*
+* See the function usage example below for more details.
+*
+* The interval at which this function is called should match with interval
+* defined in context->ptrCommonContext->timestampInterval register. Either the
+* register value can be updated to match the callback interval or the callback
+* can be made at interval set in the register.
+*
+* If a timestamp is available from another source, the application program
+* may choose to periodically update the timestamp by using the
+* Cy_CapSense_SetGestureTimestamp() function instead of
+* registering a callback.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \funcusage
+*
+* An example of timestamp updating:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Timestamp
+*
+*******************************************************************************/
+void Cy_CapSense_IncrementGestureTimestamp(cy_stc_capsense_context_t * context)
+{
+    context->ptrCommonContext->timestamp +=
+                context->ptrCommonContext->timestampInterval;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SetGestureTimestamp
+****************************************************************************//**
+*
+* Rewrites the timestamp register by the specified value.
+*
+* This function writes the specified value into the middleware timestamp
+* context->ptrCommonContext->timestamp register.
+*
+* If a timestamp is available from another source, the application program
+* may choose to periodically update the timestamp by using this function
+* instead of registering a callback.
+*
+* Do not modify the timestamp arbitrarily or simultaneously use with
+* the Cy_CapSense_IncrementGestureTimestamp() function, which may result in
+* unexpected result.
+*
+* \param value
+* Specifies the timestamp value (in ms).
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_SetGestureTimestamp(
+                uint32_t value,
+                cy_stc_capsense_context_t * context)
+{
+    context->ptrCommonContext->timestamp = value;
+}
+#endif /* ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_GESTURE_EN) || \
+           (CY_CAPSENSE_DISABLE != CY_CAPSENSE_BALLISTIC_MULTIPLIER_EN)) */
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_Restore
+****************************************************************************//**
+*
+* Resumes the middleware operation if the Cy_CapSense_Save() function was
+* called previously.
+*
+* This function, along with the Cy_CapSense_Save() function is specifically
+* designed for ease of use and supports time multiplexing of the CAPSENSE&trade; HW
+* block among multiple middleware. When the CAPSENSE&trade; HW blocks are shared by
+* multiple middleware, this function can be used to restore the previous state of
+* the CAPSENSE&trade; HW block(s) and CAPSENSE&trade; Middleware is saved using the
+* Cy_CapSense_Save() function. See the function usage example below for
+* details on usage.
+*
+* This function performs the same tasks as Cy_CapSense_Init() function and is
+* kept for API consistency among middlewares. It is recommended to use
+* Cy_CapSense_Save() and Cy_CapSense_Restore() functions to implement
+* time-multiplexed mode instead of Cy_CapSense_DeInit() and Cy_CapSense_Init()
+* functions for further compatibility.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the resume process. If CY_CAPSENSE_STATUS_SUCCESS is not
+* received, the resume process fails and retries may be required.
+*
+* \funcusage
+*
+* An example of sharing the CAPSENSE&trade; HW block by CAPSENSE&trade; and CSDADC middleware:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_TimeMultiplex
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_Restore(cy_stc_capsense_context_t * context)
+{
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+
+        cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
+        cy_en_csd_key_t mvKey;
+        cy_en_csd_status_t csdHwStatus;
+        cy_stc_csd_context_t * ptrCsdCxt = context->ptrCommonConfig->ptrCsdContext;
+        CSD_Type * ptrCsdBaseAdd = context->ptrCommonConfig->ptrCsdBase;
+        uint32_t watchdogCounter;
+
+        /* Number of cycle of one for() loop */
+        const uint32_t cyclesPerLoop = 5u;
+        /* Timeout in microseconds */
+        const uint32_t watchdogTimeoutUs = 10000u;
+
+        /* Get the CSD HW block status */
+        mvKey = Cy_CSD_GetLockStatus(ptrCsdBaseAdd, ptrCsdCxt);
+        if(CY_CSD_NONE_KEY == mvKey)
+        {
+            /* Reset CSD HW block sequencer state always to handle a corner case when the sequencer is not in the idle state */
+            context->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK;
+            context->ptrCommonConfig->ptrCsdBase->SEQ_START = CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK;
+            watchdogCounter = Cy_CapSense_WatchdogCyclesNum(watchdogTimeoutUs,
+                context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA, cyclesPerLoop);
+            do
+            {
+                csdHwStatus = Cy_CSD_GetConversionStatus(ptrCsdBaseAdd, ptrCsdCxt);
+                watchdogCounter--;
+            }
+            while((CY_CSD_BUSY == csdHwStatus) && (0u != watchdogCounter));
+
+            if(CY_CSD_SUCCESS == csdHwStatus)
+            {
+                #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_USE_CAPTURE)
+                    csdHwStatus = Cy_CSD_Capture(ptrCsdBaseAdd, CY_CSD_CAPSENSE_KEY, ptrCsdCxt);
+                #else
+                    csdHwStatus = Cy_CSD_Init(ptrCsdBaseAdd, &cy_capsense_csdCfg, CY_CSD_CAPSENSE_KEY, ptrCsdCxt);
+                #endif
+
+                if(CY_CSD_SUCCESS == csdHwStatus)
+                {
+                    capStatus = CY_CAPSENSE_STATUS_SUCCESS;
+                }
+            }
+        }
+        return (capStatus);
+    #else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
+        uint32_t curChIndex;
+        cy_en_msc_status_t mscHwStatus;
+        cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_SUCCESS;
+        const cy_stc_msc_channel_config_t * ptrMscChCfg = &context->ptrCommonConfig->ptrMscChConfig[0u];
+
+        for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+        {
+            /* Get MSC HW blocks statuses */
+            if(CY_MSC_NONE_KEY != Cy_MSC_GetLockStatus(ptrMscChCfg->ptrMscBase, ptrMscChCfg->ptrMscContext))
+            {
+                capStatus = CY_CAPSENSE_STATUS_HW_LOCKED;
+                break;
+            }
+            ptrMscChCfg++;
+        }
+
+        if (capStatus == CY_CAPSENSE_STATUS_SUCCESS)
+        {
+            capStatus = Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_CAPTURED_DEFAULT, context);
+            if (capStatus == CY_CAPSENSE_STATUS_SUCCESS)
+            {
+                ptrMscChCfg = &context->ptrCommonConfig->ptrMscChConfig[0u];
+                /* Capture MSC HW blocks */
+                for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+                {
+                    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_USE_CAPTURE)
+                        mscHwStatus = Cy_MSC_Capture(ptrMscChCfg->ptrMscBase,
+                                                CY_MSC_CAPSENSE_KEY, ptrMscChCfg->ptrMscContext);
+                    #else
+                        mscHwStatus = Cy_MSC_Init(ptrMscChCfg->ptrMscBase, &cy_capsense_mscCfg,
+                                                  CY_MSC_CAPSENSE_KEY, ptrMscChCfg->ptrMscContext);
+                    #endif
+
+                    if(CY_MSC_SUCCESS != mscHwStatus)
+                    {
+                        capStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
+                        break;
+                    }
+                    ptrMscChCfg++;
+                }
+            }
+        }
+
+        return (capStatus);
+    #endif
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_Save
+****************************************************************************//**
+*
+* Saves the state of CAPSENSE&trade; so the functionality can be restored
+* using the Cy_CapSense_Restore() function.
+*
+* This function, along with the Cy_CapSense_Restore() function, is specifically
+* designed for ease of use and supports time multiplexing of the CAPSENSE&trade; HW
+* block among multiple middleware. When the CAPSENSE&trade; HW block is shared by
+* multiple middleware, this function can be used to save the current state of
+* the CAPSENSE&trade; HW block and CAPSENSE&trade; Middleware prior to releasing the
+* CAPSENSE&trade; HW block for use by other middleware. See the function usage example
+* below for details on usage.
+*
+* This function performs the same tasks as the Cy_CapSense_DeInit() function and is
+* kept for API consistency among middlewares. It is recommended to use
+* Cy_CapSense_Save() and Cy_CapSense_Restore() functions to implement
+* Time-multiplexed mode instead of Cy_CapSense_DeInit() and Cy_CapSense_Init()
+* functions for further compatibility.
+*
+* This function performs the following operations:
+* * Releases the CAPSENSE&trade; HW block.
+* * Configures sensor pins to the default state and disconnects them from
+*   analog buses.
+* * Disconnects external capacitors from analog buses.
+* * Sets the middleware state to default.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the process. If CY_CAPSENSE_STATUS_SUCCESS is not received,
+* the save process fails and retries may be required.
+*
+* \funcusage
+*
+* An example of sharing the CAPSENSE&trade; HW block by the CapSense and CSDADC middleware.<br>
+* 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
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_Save(cy_stc_capsense_context_t * context)
+{
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+
+        cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
+        cy_en_csd_status_t initStatus;
+
+        if (CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(context))
+        {
+            /* Disconnect external capacitors and sensor pins from analog bus */
+            (void)Cy_CapSense_SwitchSensingMode(CY_CAPSENSE_UNDEFINED_GROUP, context);
+
+            /* Release the CSD HW block */
+            initStatus = Cy_CSD_DeInit(
+                            context->ptrCommonConfig->ptrCsdBase,
+                            CY_CSD_CAPSENSE_KEY,
+                            context->ptrCommonConfig->ptrCsdContext);
+
+            if (CY_CSD_SUCCESS == initStatus)
+            {
+                capStatus = CY_CAPSENSE_STATUS_SUCCESS;
+            }
+        }
+
+        return capStatus;
+
+    #else /* (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN) */
+
+        uint32_t curChIndex;
+        cy_en_msc_status_t initStatus;
+        cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_SUCCESS;
+        const cy_stc_msc_channel_config_t * ptrMscChannel = context->ptrCommonConfig->ptrMscChConfig;
+
+        if (CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(context))
+        {
+            for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+            {
+                /* Get MSC HW blocks statuses */
+                if(CY_MSC_CAPSENSE_KEY != Cy_MSC_GetLockStatus(ptrMscChannel[curChIndex].ptrMscBase, ptrMscChannel[curChIndex].ptrMscContext))
+                {
+                    capStatus = CY_CAPSENSE_STATUS_HW_LOCKED;
+                    break;
+                }
+            }
+
+            if (CY_CAPSENSE_STATUS_SUCCESS == capStatus)
+            {
+                capStatus = Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_UNDEFINED, context);
+                if (capStatus == CY_CAPSENSE_STATUS_SUCCESS)
+                {
+                    for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+                    {
+                        initStatus = Cy_MSC_DeInit(ptrMscChannel[curChIndex].ptrMscBase, CY_MSC_CAPSENSE_KEY, ptrMscChannel[curChIndex].ptrMscContext);
+                        if (CY_MSC_SUCCESS != initStatus)
+                        {
+                            capStatus = CY_CAPSENSE_STATUS_HW_LOCKED;
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+        else
+        {
+            capStatus = CY_CAPSENSE_STATUS_HW_BUSY;
+        }
+
+        return capStatus;
+
+    #endif
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_RegisterCallback
+****************************************************************************//**
+*
+* Registers a ures's callback function.
+*
+* The registered function will be called by the CAPSENSE&trade; middleware when
+* the specified event \ref cy_en_capsense_callback_event_t has occurred in
+* the CAPSENSE&trade; middleware.
+*
+* \param callbackType
+* The event on which the registered user's function is called by the CAPSENSE&trade;
+* middleware. Refer to \ref cy_en_capsense_callback_event_t for the list of
+* supported events.
+*
+* \param callbackFunction
+* The pointer to the user's callback function to be called by the middleware.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the callback registration:
+* - CY_CAPSENSE_STATUS_SUCCESS      - The action performed successfully.
+* - CY_CAPSENSE_STATUS_BAD_PARAM    - The input parameter is invalid.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_RegisterCallback(
+                cy_en_capsense_callback_event_t callbackType,
+                cy_capsense_callback_t callbackFunction,
+                cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t retVal = CY_CAPSENSE_STATUS_SUCCESS;
+
+    if((NULL != callbackFunction) && (NULL != context))
+    {
+
+        switch(callbackType)
+        {
+            case CY_CAPSENSE_START_SAMPLE_E:
+                context->ptrInternalContext->ptrSSCallback = callbackFunction;
+                break;
+            case CY_CAPSENSE_END_OF_SCAN_E:
+                context->ptrInternalContext->ptrEOSCallback = callbackFunction;
+                break;
+            default:
+                retVal = CY_CAPSENSE_STATUS_BAD_PARAM;
+                break;
+        }
+    }
+    else
+    {
+        retVal = CY_CAPSENSE_STATUS_BAD_PARAM;
+    }
+
+    return(retVal);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_UnRegisterCallback
+****************************************************************************//**
+*
+* This function unregisters a previously registered user's callback function
+* in the CAPSENSE&trade; middleware.
+*
+* \param callbackType
+* The event on which the callback function should be unregistered.
+* Refer to \ref cy_en_capsense_callback_event_t for the list of
+* supported events.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the callback deregistration:
+* - CY_CAPSENSE_STATUS_SUCCESS      - The action performed successfully.
+* - CY_CAPSENSE_STATUS_BAD_PARAM    - The input parameter is invalid.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_UnRegisterCallback(
+                cy_en_capsense_callback_event_t callbackType,
+                cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t retVal = CY_CAPSENSE_STATUS_SUCCESS;
+
+    if(NULL != context)
+    {
+        switch(callbackType)
+        {
+            case CY_CAPSENSE_START_SAMPLE_E:
+                context->ptrInternalContext->ptrSSCallback = NULL;
+                break;
+            case CY_CAPSENSE_END_OF_SCAN_E:
+                context->ptrInternalContext->ptrEOSCallback = NULL;
+                break;
+            default:
+                retVal = CY_CAPSENSE_STATUS_BAD_PARAM;
+                break;
+        }
+    }
+    else
+    {
+        retVal = CY_CAPSENSE_STATUS_BAD_PARAM;
+    }
+
+    return(retVal);
+
+}
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+
+/* [] END OF FILE */

+ 119 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_control.h

@@ -0,0 +1,119 @@
+/***************************************************************************//**
+* \file cy_capsense_control.h
+* \version 3.0
+*
+* \brief
+* This file provides the function prototypes of the Control module.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_CONTROL_H)
+#define CY_CAPSENSE_CONTROL_H
+
+#include "cy_syspm.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_common.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/*******************************************************************************
+* Local definition
+*******************************************************************************/
+#define CY_CAPSENSE_ANALOG_SETTLING_TIME_US             (25u)
+
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+/******************************************************************************/
+/** \addtogroup group_capsense_high_level *//** \{ */
+/******************************************************************************/
+
+cy_capsense_status_t Cy_CapSense_Init(cy_stc_capsense_context_t * context);
+cy_capsense_status_t Cy_CapSense_DeInit(cy_stc_capsense_context_t * context);
+
+cy_capsense_status_t Cy_CapSense_Enable(cy_stc_capsense_context_t * context);
+
+cy_capsense_status_t Cy_CapSense_Save(cy_stc_capsense_context_t * context);
+cy_capsense_status_t Cy_CapSense_Restore(cy_stc_capsense_context_t * context);
+
+cy_capsense_status_t Cy_CapSense_ProcessAllWidgets(
+                cy_stc_capsense_context_t * context);
+cy_capsense_status_t Cy_CapSense_ProcessWidget(
+                uint32_t widgetId,
+                cy_stc_capsense_context_t * context);
+
+#if ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_GESTURE_EN) || \
+     (CY_CAPSENSE_DISABLE != CY_CAPSENSE_BALLISTIC_MULTIPLIER_EN))
+    void Cy_CapSense_IncrementGestureTimestamp(cy_stc_capsense_context_t * context);
+    void Cy_CapSense_SetGestureTimestamp(
+                    uint32_t value,
+                    cy_stc_capsense_context_t * context);
+#endif
+
+void Cy_CapSense_Wakeup(const cy_stc_capsense_context_t * context);
+
+cy_en_syspm_status_t Cy_CapSense_DeepSleepCallback(
+                cy_stc_syspm_callback_params_t * callbackParams,
+                cy_en_syspm_callback_mode_t mode);
+
+cy_capsense_status_t Cy_CapSense_RegisterCallback(
+                cy_en_capsense_callback_event_t callbackType,
+                cy_capsense_callback_t callbackFunction,
+                cy_stc_capsense_context_t * context);
+cy_capsense_status_t Cy_CapSense_UnRegisterCallback(
+                cy_en_capsense_callback_event_t callbackType,
+                cy_stc_capsense_context_t * context);
+
+
+/** \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_low_level *//** \{ */
+/******************************************************************************/
+
+cy_capsense_status_t Cy_CapSense_ProcessWidgetExt(
+                uint32_t widgetId,
+                uint32_t mode,
+                cy_stc_capsense_context_t * context);
+cy_capsense_status_t Cy_CapSense_ProcessSensorExt(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                uint32_t mode,
+                const cy_stc_capsense_context_t * context);
+/** \} */
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+cy_capsense_status_t Cy_CapSense_Initialize(
+    cy_stc_capsense_context_t * context);
+
+/** \} \endcond */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+#endif /* CY_CAPSENSE_CONTROL_H */
+
+
+/* [] END OF FILE */

+ 2151 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_csd_v2.c

@@ -0,0 +1,2151 @@
+/***************************************************************************//**
+* \file cy_capsense_csd_v2.c
+* \version 3.0
+*
+* \brief
+* This file defines the data structure global variables and provides
+* implementation for the low-level functions of the CSD part of
+* the Sensing module. The file contains the functions used for the CSD HW block
+* initialization, calibration, and scanning.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include <stddef.h>
+#include "cy_device_headers.h"
+#include "cy_sysclk.h"
+#include "cy_syslib.h"
+#include "cy_gpio.h"
+#include "cy_csd.h"
+
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_sensing_v2.h"
+#include "cy_capsense_csd_v2.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+
+
+/*******************************************************************************
+* Local definition
+*******************************************************************************/
+/* CY_ID285392, CY_ID515 */
+#define CY_CAPSENSE_FILTER_DELAY_MAX                        (CY_CAPSENSE_CSD_CONFIG_FILTER_DELAY_4_CYCLES)
+#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
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+__STATIC_INLINE void Cy_CapSense_CSDChangeClkFreq(uint32_t channelIndex, cy_stc_capsense_context_t * context);
+#endif
+
+static void Cy_CapSense_CSDInitNextSnsScan(cy_stc_capsense_context_t * context);
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+static void Cy_CapSense_CSDInitNextChScan(cy_stc_capsense_context_t * context);
+#endif
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+static void Cy_CapSense_CSDEnableShieldElectrodes(const cy_stc_capsense_context_t * context);
+#endif
+
+static void Cy_CapSense_CSDTriggerScan(cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN)
+static void Cy_CapSense_CSDCalibrate(
+                uint32_t widgetId, uint32_t target,
+                cy_stc_capsense_context_t * context);
+
+    #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_AUTO_GAIN_EN)
+    static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * context);
+    #endif
+
+    #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN)
+    static void Cy_CapSense_CSDNormalizeIdac(
+                    cy_stc_capsense_widget_config_t const * ptrWdConfig,
+                    uint32_t target,
+                    const cy_stc_capsense_context_t * context);
+    #endif
+#endif
+
+/** \} \endcond */
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDDisableMode
+****************************************************************************//**
+*
+* This function disables CSD mode.
+*
+* To disable CSD mode the following tasks are performed:
+* 1. Disconnect Cmod from AMUXBUS-A.
+* 2. Disconnect previous CSX electrode if it has been connected.
+* 3. Disconnect Csh from AMUXBUS-B.
+* 4. Disable Shield Electrodes.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDDisableMode(cy_stc_capsense_context_t * context)
+{
+    /* Cmod pin to default state */
+    Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_GPIO);
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        /* Disconnect shields */
+        Cy_CapSense_CSDDisableShieldElectrodes(context);
+
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN)
+            /* Csh pin to default state */
+            Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_GPIO);
+        #endif
+    #endif
+
+    /* Disconnect IDACA, IDACB and RefGen input */
+    context->ptrCommonConfig->ptrCsdBase->SW_REFGEN_SEL = 0u;
+
+    /* Disconnect previous CSD sensor if it has been connected */
+    Cy_CapSense_CSDSnsStateCheck(context);
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDEnableShieldElectrodes
+****************************************************************************//**
+*
+* This internal function initializes Shield Electrodes.
+*
+* The function sets the bit in the HSIOM register which enables the shield electrode
+* functionality on the pin. The port and pin configurations are stored in
+* the cy_capsense_shieldIoList structure.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_CSDEnableShieldElectrodes(const cy_stc_capsense_context_t * context)
+{
+    uint32_t shieldIndex;
+    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_CAPSENSE_DM_SHIELD, CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD);
+        ptrShieldPin++;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDDisableShieldElectrodes
+****************************************************************************//**
+*
+* This internal function disables Shield Electrodes.
+*
+* 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.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDDisableShieldElectrodes(const cy_stc_capsense_context_t * context)
+{
+    uint32_t shieldIndex;
+    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_CAPSENSE_DM_GPIO_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
+        Cy_GPIO_Clr(ptrShieldPin->pcPtr, (uint32_t)ptrShieldPin->pinNumber);
+
+        ptrShieldPin++;
+    }
+}
+#endif
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDInitialize
+****************************************************************************//**
+*
+* This function initializes the CSD module.
+*
+* The function performs the following steps:
+* 1) Sets GPIO output to "0" for all sensor pins;
+* 2) Connects CMOD to AMUXBUS-A and to CSDBUS-A;
+* 3) Connects CMOD to (sense path) to CSDCOMP;
+* 4) Connects Csh_tank to AMUXBUS-B and to CSDBUS-B;
+* 5) Connects VREF to REFGEN;
+* 6) Configures REFGEN and sets the reference voltage;
+* 7) Connects VREF to CSDCOMP and HSCOMP;
+* 8) Configures IDAC and connect to CSDBUS-A (to drive CMOD);
+* 9) Configures ModClk;
+* 10) Configure SnsClk source;
+* 11) Sets other CSD configurations (Csd Auto Zero time,
+* Sample Init period, interrupts,
+* CMOD and Csh_tank/shield initialization switch resistance).
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDInitialize(cy_stc_capsense_context_t * context)
+{
+    uint32_t interruptState;
+
+    /* Set all the sensors to inactive state */
+    Cy_CapSense_CSDClearSensors(context);
+    Cy_CapSense_DischargeExtCapacitors(context);
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        /* Connect shields to AMUX-B bus (config HSIOM regs) */
+        Cy_CapSense_CSDEnableShieldElectrodes(context);
+
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN)
+            Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXB);
+        #endif
+    #endif
+
+    /* Initialize the unused CSD IP registers to default state */
+    context->ptrCommonConfig->ptrCsdBase->HSCMP = 0u;
+    context->ptrCommonConfig->ptrCsdBase->SEQ_TIME = 0u;
+    context->ptrCommonConfig->ptrCsdBase->SENSE_DUTY = CY_CAPSENSE_CSD_SENSE_DUTY_CFG;
+    #if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
+        context->ptrCommonConfig->ptrCsdBase->IO_SEL = context->ptrInternalContext->csdRegIoSel;
+    #endif
+    context->ptrCommonConfig->ptrCsdBase->INTR_SET = CY_CAPSENSE_DEFAULT_CSD_INTR_SET;
+    context->ptrCommonConfig->ptrCsdBase->SW_DSI_SEL = context->ptrInternalContext->csdRegSwDsiSel;
+    context->ptrCommonConfig->ptrCsdBase->ADC_CTL = CY_CAPSENSE_DEFAULT_CSD_ADC_CTL;
+
+    context->ptrCommonConfig->ptrCsdBase->SW_SHIELD_SEL = 0u;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_MOD_SEL = 0u;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_TANK_SEL = 0u;
+    context->ptrCommonConfig->ptrCsdBase->SW_AMUXBUF_SEL = context->ptrInternalContext->csdRegSwAmuxbufSel;
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_P_SEL = context->ptrInternalContext->csdRegSwHsPSelScan;
+
+    /* Connection AMUXBUS-A to CSDBUS-A / AMUXBUS-B to CSDBUS-B */
+    context->ptrCommonConfig->ptrCsdBase->SW_BYP_SEL = context->ptrInternalContext->csdRegSwBypSel;
+
+    /* Connect CMOD to AMUXBUS-A */
+    interruptState = Cy_SysLib_EnterCriticalSection();
+    Cy_GPIO_SetDrivemode((GPIO_PRT_Type*)context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod, CY_CAPSENSE_DM_GPIO_ANALOG);
+    Cy_GPIO_SetHSIOM((GPIO_PRT_Type*)context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+    Cy_SysLib_ExitCriticalSection(interruptState);
+
+    /* Select CMOD and Csh_tank/shield initialization switch resistance */
+    context->ptrCommonConfig->ptrCsdBase->SW_RES = context->ptrInternalContext->csdRegSwResScan;
+    /* Set the number of dummy fine initialization cycles */
+    context->ptrCommonConfig->ptrCsdBase->SEQ_INIT_CNT = (uint32_t)context->ptrCommonConfig->csdFineInitTime;
+
+    /* Connect CMOD to (sense path) to CSDCOMP */
+    context->ptrCommonConfig->ptrCsdBase->SW_CMP_P_SEL = context->ptrInternalContext->csdRegSwCmpPSel;
+
+    /* Configure VREF */
+    context->ptrCommonConfig->ptrCsdBase->SW_REFGEN_SEL = context->ptrInternalContext->csdRegSwRefGenSel;
+    context->ptrCommonConfig->ptrCsdBase->AMBUF = context->ptrInternalContext->csdRegAmuxbufInit;
+
+    /* Connect VREFHI to HSCOMP */
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_N_SEL = CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_CLOSE;
+    context->ptrCommonConfig->ptrCsdBase->SW_CMP_N_SEL = context->ptrInternalContext->csdRegSwCmpNSel;
+    context->ptrCommonConfig->ptrCsdBase->REFGEN = context->ptrInternalContext->csdRegRefgen;
+
+    /* Configure IDACs mode */
+    context->ptrCommonConfig->ptrCsdBase->IDACA = context->ptrInternalContext->csdIdacAConfig;
+    context->ptrCommonConfig->ptrCsdBase->IDACB = context->ptrInternalContext->csdIdacBConfig;
+    context->ptrCommonConfig->ptrCsdBase->CONFIG = context->ptrInternalContext->csdRegConfig;
+
+    /* Configure ModClk */
+    Cy_CapSense_SetClkDivider((uint32_t)context->ptrCommonContext->modCsdClk - 1u, context);
+
+    /* Set all sensor states to the defined ISC state */
+    Cy_CapSense_SetIOsInDesiredState(context->ptrInternalContext->csdInactiveSnsDm, 0u,
+                                     context->ptrInternalContext->csdInactiveSnsHsiom, context);
+
+    /* Setup ISR handler to single-sensor scan function */
+    context->ptrInternalContext->ptrISRCallback = &Cy_CapSense_CSDScanISR;
+
+    context->ptrActiveScanSns->mfsChannelIndex = 0u;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDSnsStateCheck
+****************************************************************************//**
+*
+* Checks if electrodes were previously connected using
+* Cy_CapSense_CSDSetupWidgetExt() and if yes disconnects them.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDSnsStateCheck(cy_stc_capsense_context_t * context)
+{
+    if (CY_CAPSENSE_SNS_CONNECTED == context->ptrActiveScanSns->connectedSnsState)
+    {
+        Cy_CapSense_CSDDisconnectSnsExt(context);
+    }
+}
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDSetUpIdacs
+****************************************************************************//**
+*
+* 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
+* widget/sensor by Cy_CapSense_InitActivePtr() before calling this function.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDSetUpIdacs(cy_stc_capsense_context_t * context)
+{
+    uint32_t regValue;
+
+    const cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
+
+    const uint32_t idacaBitsToWrite = CSD_IDACA_VAL_Msk |
+                                      CSD_IDACA_RANGE_Msk |
+                                      CSD_IDACA_LEG1_EN_Msk |
+                                      CSD_IDACA_LEG2_EN_Msk;
+
+    #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN)
+        const uint32_t idacbBitsToWrite = CSD_IDACB_VAL_Msk     |
+                                          CSD_IDACB_RANGE_Msk   |
+                                          CSD_IDACB_LEG1_EN_Msk |
+                                          CSD_IDACB_LEG2_EN_Msk |
+                                          CSD_IDACB_LEG3_EN_Msk;
+    #endif
+
+    /* IDAC A Code */
+    if (ptrActive->ptrWdConfig->numCols > ptrActive->sensorIndex)
+    {
+        regValue = ptrActive->ptrWdContext->idacMod[ptrActive->mfsChannelIndex];
+    }
+    else
+    {
+        regValue = ptrActive->ptrWdContext->rowIdacMod[ptrActive->mfsChannelIndex];
+    }
+
+    regValue |= context->ptrCommonConfig->idacGainTable[ptrActive->ptrWdContext->idacGainIndex].gainReg;
+
+    context->ptrCommonConfig->ptrCsdBase->IDACA =
+            (context->ptrCommonConfig->ptrCsdBase->IDACA & ~idacaBitsToWrite) |
+            (regValue & idacaBitsToWrite);
+
+    #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN)
+        /* IDAC B Code */
+        regValue = ptrActive->ptrSnsContext->idacComp;
+        regValue |= context->ptrCommonConfig->idacGainTable[ptrActive->ptrWdContext->idacGainIndex].gainReg;
+
+        context->ptrCommonConfig->ptrCsdBase->IDACB =
+                (context->ptrCommonConfig->ptrCsdBase->IDACB & ~idacbBitsToWrite) |
+                (regValue & idacbBitsToWrite);
+    #endif
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDGetNumberOfConversions
+****************************************************************************//**
+*
+* This function calculate number of sub-conversions.
+*
+* \param snsClkDivider
+* The divider value of the sense clock.
+*
+* \param resolution
+* The widget resolution.
+*
+* \param snsClkSrc
+* The widget Sense Clock Source.
+*
+* \return
+* Returns the number of sub-conversions.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_CSDGetNumberOfConversions(uint32_t snsClkDivider, uint32_t resolution, uint32_t snsClkSrc)
+{
+    /* CY_ID304273 */
+    uint32_t conversionsNum = 1uL << resolution;
+    uint32_t extraCounts = 0u;
+    uint32_t snsClkDividerLocal = snsClkDivider;
+
+    if (0u == snsClkDividerLocal)
+    {
+        snsClkDividerLocal = 1u;
+    }
+
+    if ((CY_CAPSENSE_CLK_SOURCE_PRS8 == snsClkSrc) || (CY_CAPSENSE_CLK_SOURCE_PRS12 == snsClkSrc))
+    {
+        snsClkDividerLocal <<= 1u;
+    }
+
+    if(CY_CAPSENSE_16_BIT_RESOLUTION <= resolution)
+    {
+        /* CY_ID285392 */
+        extraCounts = CY_CAPSENSE_EXTRA_COUNTS_MAX;
+    }
+
+    conversionsNum = (conversionsNum - extraCounts) / snsClkDividerLocal;
+
+    return((conversionsNum > 0u) ? (conversionsNum) : 1u);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDConfigClock
+****************************************************************************//**
+*
+* This function configure sense clock for different modes.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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 regValue = 0u;
+
+    /* Getting row clock divider for matrix buttons or touchpad widgets */
+    if (context->ptrActiveScanSns->ptrWdConfig->numCols <= context->ptrActiveScanSns->sensorIndex)
+    {
+        snsClkDivider = ptrWdCxt->rowSnsClk;
+    }
+    else
+    {
+        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))
+    {
+        regValue = CY_CAPSENSE_CSD_SENSE_PERIOD_SEL_LFSR_MSB_MSK;
+        snsClkDivider >>= 1u;
+    }
+
+    /* Check divider value */
+    if (0u == snsClkDivider)
+    {
+        snsClkDivider = 1u;
+    }
+
+    regValue |= ((snsClkSrc << CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_POS) | (snsClkDivider - 1u));
+
+    /* Update reg value with divider and configuration */
+    context->ptrCommonConfig->ptrCsdBase->SENSE_PERIOD = regValue;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDCalculateScanDuration
+****************************************************************************//**
+*
+* Calculates Scan Duration which is defined by scan resolution
+*
+* The function calculates the number of conversions and updates
+* SEQ_NORM_CNT register. The number of conversions depends on resolution and
+* snsClk divider.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDCalculateScanDuration(cy_stc_capsense_context_t * context)
+{
+    uint32_t subConv;
+    const 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,
+                ((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 */
+    context->ptrCommonConfig->ptrCsdBase->SEQ_NORM_CNT = (subConv & CY_CAPSENSE_CSD_SEQ_NORM_CNT_CONV_CNT_MSK);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDSetupWidget
+****************************************************************************//**
+*
+* Performs the initialization required to scan the specified CSD widget.
+*
+* \deprecated 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
+* 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.
+* 2. Initialize the CSD HW block with specific sensing configuration (e.g.
+* sensor clock, scan resolution) used by the widget.
+* 3. Disconnect all previously connected electrodes, if the electrodes
+* connected by the Cy_CapSense_CSDSetupWidgetExt(),
+* Cy_CapSense_CSXSetupWidgetExt() functions are not disconnected.
+*
+* 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
+* 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()
+* 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
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * context)
+{
+    #if((CY_CAPSENSE_DISABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN) &&\
+        ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) ||\
+         (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)))
+        const cy_stc_capsense_widget_config_t * ptrWdCfg;
+    #endif
+
+    /* Setup new scanning mode */
+    (void)Cy_CapSense_SwitchSensingMode(CY_CAPSENSE_CSD_GROUP, context);
+
+    /* Disconnect previous sensors if they have been connected */
+    Cy_CapSense_CSDSnsStateCheck(context);
+
+    /* Save widget Id to have assess to it after scanning  */
+    Cy_CapSense_InitActivePtr(widgetId, 0u, context);
+
+    /*
+     * Configuring the Sense Clock and the Scan Duration if the
+     * MFS feature is disabled, and the one-dimension widget will be scanned.
+     * If the MFS feature is enabled, or the two-dimension widget will be scanned,
+     * the Sense Clock and the Scan Duration will be configured for each call
+     * of the Cy_CapSense_CSDScan() function.
+     */
+    #if(CY_CAPSENSE_DISABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) ||\
+            (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+            ptrWdCfg = context->ptrActiveScanSns->ptrWdConfig;
+            if(((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E != ptrWdCfg->wdType) &&
+               ((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E != ptrWdCfg->wdType))
+            {
+                Cy_CapSense_CSDCalculateScanDuration(context);
+                Cy_CapSense_CSDConfigClock(context);
+            }
+        #else
+            Cy_CapSense_CSDCalculateScanDuration(context);
+            Cy_CapSense_CSDConfigClock(context);
+        #endif
+    #endif
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDSetupWidgetExt
+****************************************************************************//**
+*
+* Performs extended initialization required to scan a specified sensor in
+* a widget using CSD sensing method.
+*
+* \deprecated 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
+* 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
+* would cause unexpected result.
+*
+* 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
+* 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
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* file defined as CY_CAPSENSE_<WIDGET_NAME>_SNS<SENSOR_NUMBER>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDSetupWidgetExt(uint32_t widgetId, uint32_t sensorId, cy_stc_capsense_context_t * context)
+{
+    /* Switch Mode if needed */
+    (void)Cy_CapSense_SwitchSensingMode(CY_CAPSENSE_CSD_GROUP, context);
+
+    /* Disconnect previous sensors if they have been connected */
+    Cy_CapSense_CSDSnsStateCheck(context);
+    Cy_CapSense_InitActivePtr(widgetId, sensorId, context);
+
+    /*
+    * Set up of the Sense Clock, the Scan Duration and the IDACs
+    * if the MFS feature is disabled.
+    * If the MFS feature is enabled, the Sense Clock, the
+    * Scan Duration and the IDACs will be configured with the
+    * MFS channel #0 settings each call of the Cy_CapSense_CSDScan()
+    * function.
+    */
+    #if (CY_CAPSENSE_DISABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        Cy_CapSense_CSDSetUpIdacs(context);
+        Cy_CapSense_CSDCalculateScanDuration(context);
+        Cy_CapSense_CSDConfigClock(context);
+    #endif
+
+    /* Setup new widget/sensor */
+    Cy_CapSense_CSDConnectSnsExt(context);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDStartSample
+****************************************************************************//**
+*
+* Starts the CSD conversion.
+*
+* This function assumes that the CSD HW block is already set up using
+* the Cy_CapSense_CSDSetupWidget() and the sensor port-pin is connected to the CSD
+* block using Cy_CapSense_CSDConnectSns().
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDStartSample(cy_stc_capsense_context_t * context)
+{
+    if(NULL != context->ptrInternalContext->ptrSSCallback)
+    {
+        context->ptrInternalContext->ptrSSCallback(context->ptrActiveScanSns);
+    }
+
+    /* Precharging Cmod and Csh */
+    Cy_CapSense_CSDCmodPrecharge(context);
+
+    /* Trigger Scan */
+    Cy_CapSense_CSDTriggerScan(context);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDScanExt
+****************************************************************************//**
+*
+* Starts the CSD conversion on the preconfigured sensor.
+*
+* \deprecated 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
+* 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,
+* 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
+* made by this function.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDScanExt(cy_stc_capsense_context_t * context)
+{
+    cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
+
+    /* Set MFS channel index to 0 */
+    ptrActive->mfsChannelIndex = 0u;
+
+    /* Initialize the Active Context pointer with the CH0 context */
+    ptrActive->ptrSnsContext = &ptrActive->ptrWdConfig->ptrSnsContext[ptrActive->sensorIndex];
+
+    /* Set Start of sensor scan flag */
+    Cy_CapSense_SetBusyFlags(context);
+
+    /* Set scope flag */
+    ptrActive->scanScope = CY_CAPSENSE_SCAN_SCOPE_SNGL_SNS;
+
+    /*
+    * Configuring of the Sense Clock, the Scan Duration and
+    * the IDACs with the MFS channel #0 settings if the MFS
+    * feature is enabled.
+    * If the MFS feature is disabled, the Sense Clock, the
+    * Scan Duration and the IDACs are configured only once
+    * in scope of the Cy_CapSense_CSDSetupWidgetExt() function.
+    */
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        Cy_CapSense_CSDSetUpIdacs(context);
+        Cy_CapSense_CSDCalculateScanDuration(context);
+        Cy_CapSense_CSDConfigClock(context);
+    #endif
+
+    /* Initiate scan */
+    Cy_CapSense_CSDStartSample(context);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDScan
+****************************************************************************//**
+*
+* This function initiates a scan for the sensors of the widget initialized
+* by the Cy_CapSense_CSDSetupWidget() function.
+*
+* \deprecated 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:
+* 1. Connects the first sensor of the widget.
+* 2. Configures the IDAC value.
+* 3. Starts scanning for the first sensor in the widget.
+*
+* This function is called by the Cy_CapSense_Scan() if the given
+* widget uses the CSD sensing method.
+*
+* 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 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 the Cy_CapSense_CSDSetupWidget() function prior
+* to calling this function.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDScan(cy_stc_capsense_context_t * context)
+{
+    #if((CY_CAPSENSE_DISABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN) &&\
+        ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) ||\
+         (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)))
+        const cy_stc_capsense_widget_config_t * ptrWdCfg;
+    #endif
+
+    Cy_CapSense_InitActivePtrSns(0u, context);
+
+    /* Setup Idac Value */
+    Cy_CapSense_CSDSetUpIdacs(context);
+    /*
+    * Configuring the Sense Clock and the Scan Duration with the settings of the
+    * widget's Row, if the two-dimension widget is scanned and with the MFS channel #0
+    * settings, if the MFS feature is enabled.
+    * If the MFS feature is disabled and the one-dimension widget is scanned,
+    * the Sense Clock and the Scan Duration will be configured only once in the scope
+    * of the Cy_CapSense_CSDSetupWidget() function.
+    */
+    #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        Cy_CapSense_CSDCalculateScanDuration(context);
+        Cy_CapSense_CSDConfigClock(context);
+    #elif((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) ||\
+          (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+        ptrWdCfg = context->ptrActiveScanSns->ptrWdConfig;
+        if(((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType) ||
+           ((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType))
+        {
+            Cy_CapSense_CSDCalculateScanDuration(context);
+            Cy_CapSense_CSDConfigClock(context);
+        }
+    #endif
+
+    Cy_CapSense_CSDConnectSnsExt(context);
+
+    context->ptrActiveScanSns->scanScope |= CY_CAPSENSE_SCAN_SCOPE_ALL_SNS_MASK;
+
+    /* Set Start of sensor scan flag */
+    Cy_CapSense_SetBusyFlags(context);
+    /* Initiate scan */
+    Cy_CapSense_CSDStartSample(context);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDConnectSnsExt
+****************************************************************************//**
+*
+* Connects a ganged sensor port-pin to the CSD HW block via the AMUX bus.
+*
+* The function gets the IO 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.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDConnectSnsExt(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;
+
+    /* Connect all pins of current sensors */
+    for(i = 0u; i < ptrActiveSns->numPins; i++)
+    {
+        Cy_CapSense_CSDConnectSns(ptrActivePin, context);
+        ptrActivePin++;
+    }
+    ptrActive->connectedSnsState = CY_CAPSENSE_SNS_CONNECTED;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDDisconnectSnsExt
+****************************************************************************//**
+*
+* Disconnects a ganged sensor port-pin from the CSD HW block and AMUX bus.
+* Sets the default state of the un-scanned sensor.
+*
+* The function gets the IO configuration registers addresses, their shifts and
+* masks from the cy_stc_capsense_pin_config_t object. Based on this data and
+* the Inactive sensor connection parameter, it updates the HSIOM, PC, and DR registers.
+* The HSIOM register is updated only when the Inactive sensor connection parameter
+* is set to Shield.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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 */
+    for(i = 0u; i < ptrActiveSns->numPins; i++)
+    {
+        Cy_CapSense_CSDDisconnectSns(ptrActivePin, context);
+        ptrActivePin++;
+    }
+    ptrActive->connectedSnsState = CY_CAPSENSE_SNS_DISCONNECTED;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDConnectSns
+****************************************************************************//**
+*
+* Connects port pin to the CSD HW block using AMUX bus.
+*
+* \deprecated This function is obsolete and kept for backward compatibility only.
+* The Cy_CapSense_SetPinState() function should be used instead.
+*
+* 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
+* only use GPIOs that are already assigned to CAPSENSE&trade; 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)
+* or with low-level functions that perform a single-sensor scanning.
+*
+* Scanning should be completed before calling this function.
+*
+* \param snsAddrPtr
+* Specifies the pointer to the cy_stc_capsense_pin_config_t object belonging to
+* a sensor that is to be connected to the CSD HW block.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \funcusage
+*
+* 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,
+                const cy_stc_capsense_context_t * context)
+{
+    (void) context;
+    Cy_CapSense_SsConfigPinRegisters(snsAddrPtr->pcPtr, (uint32_t)snsAddrPtr->pinNumber, CY_CAPSENSE_CSD_SCAN_PIN_DM, CY_CAPSENSE_HSIOM_SEL_CSD_SENSE);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDDisconnectSns
+****************************************************************************//**
+*
+* Disconnects port pin from the CSD HW block by disconnecting it from AMUX bus.
+*
+* \deprecated This function is obsolete and kept for backward compatibility only.
+* The Cy_CapSense_SetPinState() function should be used instead.
+*
+* 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.
+*
+* \param  snsAddrPtr
+* Specifies the pointer to the cy_stc_capsense_pin_config_t object belonging to
+* a sensor that should be disconnected from the CSD HW block.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \funcusage
+*
+* 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_context_t * context)
+{
+    Cy_CapSense_SsConfigPinRegisters(snsAddrPtr->pcPtr, (uint32_t)snsAddrPtr->pinNumber,
+                                     context->ptrInternalContext->csdInactiveSnsDm,
+                                     context->ptrInternalContext->csdInactiveSnsHsiom);
+    Cy_GPIO_Clr(snsAddrPtr->pcPtr, (uint32_t)snsAddrPtr->pinNumber);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDClearSensors
+****************************************************************************//**
+*
+* Resets all the CSD sensors to the non-sampling state by sequentially
+* disconnecting all the sensors from the Analog MUX bus and putting them to
+* an inactive state.
+*
+* The function goes through all the widgets and updates appropriate bits in
+* the IO HSIOM, PC and DR registers depending on the Inactive sensor connection
+* parameter. DR register bits are set to zero when the Inactive sensor
+* connection is Ground or Hi-Z.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDClearSensors(const cy_stc_capsense_context_t * context)
+{
+    uint32_t wdgtIndex;
+    uint32_t snsIndex;
+    uint32_t pinIndex;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+    const cy_stc_capsense_electrode_config_t * ptrSnsCfg;
+    const cy_stc_capsense_pin_config_t * ptrPin;
+
+    /* Go through all CSD widgets and configure each sensor/pin to the defined state */
+    for (wdgtIndex = 0u; wdgtIndex < context->ptrCommonConfig->numWd; wdgtIndex++)
+    {
+        ptrWdCfg = &context->ptrWdConfig[wdgtIndex];
+        if (CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod)
+        {
+            ptrSnsCfg = ptrWdCfg->ptrEltdConfig;
+            /* Go through all sensors in widget */
+            for (snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
+            {
+                ptrPin = ptrSnsCfg->ptrPin;
+                /* Go through all pins in sensor */
+                for(pinIndex = 0u; pinIndex < ptrSnsCfg->numPins; pinIndex++)
+                {
+                    /* Set CSD pin default state */
+                    Cy_CapSense_CSDDisconnectSns(ptrSnsCfg->ptrPin, context);
+                    ptrPin++;
+                }
+                ptrSnsCfg++;
+            }
+        }
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDSetWidgetSenseClkSrc
+****************************************************************************//**
+*
+* Sets a source for the sense clock for a widget.
+*
+* \param ptrWdConfig
+* The pointer to the widget context structure.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDSetWidgetSenseClkSrc(const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t lfsrSize;
+    uint32_t conversionsNum;
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+    #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+        uint32_t rowLfsrSize;
+        uint8_t widgetType = ptrWdConfig->wdType;
+    #endif
+
+    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);
+        lfsrSize = Cy_CapSense_SsCalcLfsrSize((uint32_t)ptrWdCxt->snsClk, conversionsNum);
+        if (CY_CAPSENSE_CLK_SOURCE_DIRECT == lfsrSize)
+        {
+            lfsrSize = Cy_CapSense_CSDCalcPrsSize((uint32_t)ptrWdCxt->snsClk << 1uL, (uint32_t)ptrWdCxt->resolution);
+        }
+
+        #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+            if (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == widgetType) || ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == widgetType))
+            {
+                if (ptrWdCxt->rowSnsClk != ptrWdCxt->snsClk)
+                {
+                    conversionsNum = Cy_CapSense_CSDGetNumberOfConversions((uint32_t)ptrWdCxt->rowSnsClk, (uint32_t)ptrWdCxt->resolution, CY_CAPSENSE_CLK_SOURCE_DIRECT);
+                    rowLfsrSize = Cy_CapSense_SsCalcLfsrSize((uint32_t)ptrWdCxt->rowSnsClk, conversionsNum);
+                    if (CY_CAPSENSE_CLK_SOURCE_DIRECT == rowLfsrSize)
+                    {
+                        rowLfsrSize = Cy_CapSense_CSDCalcPrsSize((uint32_t)ptrWdCxt->rowSnsClk << 1uL, (uint32_t)ptrWdCxt->resolution);
+                    }
+                    /* Select sense clock source based on both dimensions */
+                    if (rowLfsrSize != lfsrSize)
+                    {
+                        lfsrSize = CY_CAPSENSE_CLK_SOURCE_DIRECT;
+                    }
+                }
+            }
+        #endif
+        ptrWdCxt->snsClkSource = (uint8_t)lfsrSize | CY_CAPSENSE_CLK_SOURCE_AUTO_MASK;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDCalcPrsSize
+****************************************************************************//**
+*
+* The function finds PRS polynomial size when clock source is set to Auto mode.
+*
+* The PRS polynomial size in the Auto mode is found based on the following
+* requirements:
+* - at least one full spread spectrum polynomial should pass during scan time.
+*
+* \param snsClkDivider
+* The divider value for the sense clock.
+*
+* \param resolution
+* The widget resolution.
+*
+* \return
+* Returns the size of PRS value for SENSE_PERIOD register.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_CSDCalcPrsSize(uint32_t snsClkDivider, uint32_t resolution)
+{
+    uint32_t prsSize;
+
+    if ((snsClkDivider * CY_CAPSENSE_PRS_LENGTH_12_BITS) <= ((0x00000001uL << resolution) - 1u))
+    {
+        /* Set PRS12 mode */
+        prsSize = CY_CAPSENSE_CLK_SOURCE_PRS12;
+    }
+    else if ((snsClkDivider * CY_CAPSENSE_PRS_LENGTH_8_BITS) <= ((0x00000001uL << resolution) - 1u))
+    {
+        /* Set PRS8 mode */
+        prsSize = CY_CAPSENSE_CLK_SOURCE_PRS8;
+    }
+    else
+    {
+        prsSize = CY_CAPSENSE_CLK_SOURCE_DIRECT;
+    }
+
+    return prsSize;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDDischargeCmod
+****************************************************************************//**
+*
+* Discharges Cmod capacitor related to CSD sensing method and restores
+* it state.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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);
+    Cy_GPIO_SetHSIOM(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod,
+                                                            CY_CAPSENSE_HSIOM_SEL_GPIO);
+    Cy_SysLib_ExitCriticalSection(interruptState);
+
+    /* Set port configuration register (drive mode) to STRONG mode */
+    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_CAPSENSE_DM_GPIO_STRONG_IN_OFF);
+    Cy_SysLib_ExitCriticalSection(interruptState);
+
+    /* Now external CSD-related capacitors discharging */
+    Cy_SysLib_DelayUs(CY_CAPSENSE_EXT_CAP_DISCHARGE_TIME);
+
+    /* Restore Ext Cap settings */
+    interruptState = Cy_SysLib_EnterCriticalSection();
+    Cy_GPIO_SetDrivemode(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod, pcReg);
+    Cy_GPIO_SetHSIOM(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod, hsiomReg);
+    Cy_SysLib_ExitCriticalSection(interruptState);
+}
+
+
+#if((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) && \
+    (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN))
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDNormalizeIdac
+****************************************************************************//**
+*
+* This function normalizes compensation IDAC.
+*
+* \param ptrWdConfig
+* Specifies the pointer to a widget configuration structure.
+*
+* \param target
+* Raw count target in percentage.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_CSDNormalizeIdac(
+                cy_stc_capsense_widget_config_t const * ptrWdConfig,
+                uint32_t target,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+    uint32_t maxIdac;
+    uint32_t minIdac;
+    uint32_t minRaw;
+    uint32_t rawLevel;
+    uint32_t iMod;
+
+    uint32_t freqChIndex;
+
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+    uint32_t maxRawLevel = ptrWdCxt->maxRawCount;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+    for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+    {
+        /* Find maximum and minimum IDACs */
+        maxIdac = ptrWdConfig->ptrWdContext->idacMod[freqChIndex];
+        minIdac = maxIdac;
+        ptrSnsCxt = &ptrWdConfig->ptrSnsContext[freqChIndex * context->ptrCommonConfig->numSns];
+        minRaw = ptrSnsCxt->raw;
+        for(snsIndex = 0u; snsIndex < ptrWdConfig->numCols; snsIndex++)
+        {
+            if (minIdac > ptrSnsCxt->idacComp)
+            {
+                minIdac = ptrSnsCxt->idacComp;
+                minRaw = ptrSnsCxt->raw;
+            }
+            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) +
+                CY_CAPSENSE_PERCENTAGE_100) * ptrSnsCxt->idacComp;
+            if (rawLevel < (iMod * target))
+            {
+                ptrSnsCxt->idacComp = 0u;
+            }
+            else
+            {
+                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((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+            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 */
+                maxIdac = ptrWdCxt->rowIdacMod[freqChIndex];
+                minIdac = ptrWdCxt->rowIdacMod[freqChIndex];
+                ptrSnsCxt = &(ptrWdConfig->ptrSnsContext[(freqChIndex * context->ptrCommonConfig->numSns) + ptrWdConfig->numCols]);
+                minRaw = ptrSnsCxt->raw;
+                for(snsIndex = ptrWdConfig->numCols; snsIndex < ptrWdConfig->numSns; snsIndex++)
+                {
+                    if (minIdac > ptrSnsCxt->idacComp)
+                    {
+                        minIdac = ptrSnsCxt ->idacComp;
+                        minRaw = ptrSnsCxt->raw;
+                    }
+                    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) +
+                        CY_CAPSENSE_PERCENTAGE_100) * ptrSnsCxt->idacComp;
+                    if (rawLevel < (iMod * target))
+                    {
+                        ptrSnsCxt->idacComp = 0u;
+                    }
+                    else
+                    {
+                        ptrSnsCxt->idacComp = (uint8_t)(((rawLevel - (iMod * target)) +
+                            (CY_CAPSENSE_PERCENTAGE_100 >> 1u)) / CY_CAPSENSE_PERCENTAGE_100);
+                    }
+                    ptrSnsCxt++;
+                }
+            }
+        #endif /* ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) */
+    }
+}
+#endif
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN)
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_AUTO_GAIN_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_SsCSDSwitchIdacGain
+****************************************************************************//**
+*
+* Switches to the lower IDAC gain is possible.
+*
+* This internal function switches to the lower IDAC gain is possible.
+* Conditions of switching to the lower IDAC gains:
+* 1. The current IDAC gain is not the lowest one.
+* 2. The maximum IDAC at gain switching will not be out of range.
+* 3. The minimum IDAC is still below the acceptable range.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return Returns the status of the operation:
+* - Zero     - Gain switching is not needed.
+* - Non-Zero - Gain was switched to the lower one.
+*
+*******************************************************************************/
+static uint32_t Cy_CapSense_CSDSwitchIdacGain(cy_stc_capsense_context_t * context)
+{
+    uint32_t ratio;
+    uint32_t maxIdac;
+    uint32_t minIdac;
+    uint32_t swStatus = 0u;
+    const cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
+    uint32_t gainIndex = ptrActive->ptrWdContext->idacGainIndex;
+    uint32_t idacVal;
+    uint32_t freqChIndex;
+
+    maxIdac = 0u;
+    minIdac = CY_CAPSENSE_CAL_IDAC_MAX_VALUE;
+
+    #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN)
+        const cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+        uint32_t snsIndex;
+    #endif
+
+    for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+    {
+        /* Find maximum and minimum IDACs */
+        idacVal = ptrActive->ptrWdContext->idacMod[freqChIndex];
+        if (maxIdac < idacVal)
+        {
+            maxIdac = idacVal;
+        }
+        if (minIdac > idacVal)
+        {
+            minIdac = idacVal;
+        }
+        /* Check for sensorIndex >= numCols added and choose rowIdac if needed */
+        #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+            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))
+            {
+                idacVal = ptrActive->ptrWdContext->rowIdacMod[freqChIndex];
+                if (maxIdac < idacVal)
+                {
+                    maxIdac = idacVal;
+                }
+                if (minIdac > idacVal)
+                {
+                    minIdac = idacVal;
+                }
+            }
+        #endif
+
+        /* Set value for iDac comp */
+        #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN)
+            for(snsIndex = 0u; snsIndex < ptrActive->ptrWdConfig->numSns; snsIndex++)
+            {
+                ptrSnsCxt = &ptrActive->ptrWdConfig->ptrSnsContext[snsIndex];
+                idacVal = ptrSnsCxt[freqChIndex * context->ptrCommonConfig->numSns].idacComp;
+                if (minIdac > idacVal)
+                {
+                    minIdac = idacVal;
+                }
+            }
+        #endif
+    }
+
+    /* Check gain switch conditions */
+    if (gainIndex != 0u)
+    {
+        if (minIdac < context->ptrCommonConfig->csdIdacMin)
+        {
+            ratio = context->ptrCommonConfig->idacGainTable[gainIndex].gainValue /
+                    context->ptrCommonConfig->idacGainTable[gainIndex - 1u].gainValue;
+            if ((maxIdac * ratio) < CY_CAPSENSE_CAL_IDAC_MAX_VALUE)
+            {
+                /* Switch to lower idac gain */
+                ptrActive->ptrWdContext->idacGainIndex--;
+                swStatus = 1u;
+            }
+        }
+    }
+    return (swStatus);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_AUTO_GAIN_EN) */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDCalibrate
+****************************************************************************//**
+*
+* Implements IDAC calibration for a desired widget using successive
+* approximation algorithm.
+*
+* 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
+* 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
+* 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
+* equal values of modulator and compensation IDAC.
+*
+* 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
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param target
+* Specifies the calibration target in percentages of the maximum raw count.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_CSDCalibrate(
+                uint32_t widgetId,
+                uint32_t target,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t freqChIndex;
+    uint32_t snsIndex;
+    uint32_t rawTarget;
+    uint32_t modClkDivider;
+    uint32_t cpuFreqMHz;
+    uint32_t watchdogCounter;
+
+    uint8_t calMask;
+    uint8_t * ptrIdacMod;
+    uint8_t * ptrIdacMax;
+    uint8_t maxColIdac[CY_CAPSENSE_MAX_SUPPORTED_FREQ_NUM] = {0u, 0u, 0u};
+    uint8_t maxRowIdac[CY_CAPSENSE_MAX_SUPPORTED_FREQ_NUM] = {0u, 0u, 0u};
+
+    cy_stc_capsense_widget_config_t const * ptrWdCfg = &context->ptrWdConfig[widgetId];
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdCfg->ptrWdContext;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+
+    #if (((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) &&\
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_ROW_COL_ALIGN_EN))
+        uint32_t tmpVal;
+    #endif
+
+    /* Approximate duration of Wait For Init loop */
+    const uint32_t isBusyLoopDuration = 5uL;
+
+    /* Wait For Init watchdog timeout in microseconds */
+    uint64_t isBusyWatchdogTimeUs = 0u;
+
+    rawTarget = ((uint32_t)ptrWdCxt->maxRawCount * target) / CY_CAPSENSE_PERCENTAGE_100;
+
+    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;
+            ptrIdacMax = maxColIdac;
+        }
+        else
+        {
+            ptrIdacMod = ptrWdCxt->rowIdacMod;
+            ptrIdacMax = maxRowIdac;
+        }
+
+        for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+        {
+            ptrIdacMod[freqChIndex] = calMask;
+            #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN)
+                ptrSnsCxt[freqChIndex * context->ptrCommonConfig->numSns].idacComp = calMask;
+            #endif
+        }
+
+        modClkDivider = context->ptrCommonContext->modCsdClk;
+        if(0u == modClkDivider)
+        {
+            modClkDivider = 1u;
+        }
+
+        isBusyWatchdogTimeUs  = (uint64_t)CY_CAPSENSE_CONFIGURED_FREQ_NUM * 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 */
+            Cy_CapSense_CSDSetupWidgetExt(widgetId, snsIndex, context);
+            /* Need to discharge Cmod capacitor */
+            Cy_CapSense_CSDDischargeCmod(context);
+            /* Scan the sensor */
+            Cy_CapSense_CSDScanExt(context);
+
+            cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
+            watchdogCounter = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
+            /* Wait for EOS */
+            while (CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
+            {
+                if(0uL == watchdogCounter)
+                {
+                    break;
+                }
+                watchdogCounter--;
+            }
+
+            /* Switch to the lower IDAC mask */
+            for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+            {
+                /* Update IDAC based on scan result */
+                if (ptrSnsCxt[freqChIndex * context->ptrCommonConfig->numSns].raw < rawTarget)
+                {
+                    ptrIdacMod[freqChIndex] &= (uint8_t)(~calMask);
+                }
+
+                ptrIdacMod[freqChIndex] |= (uint8_t)(calMask >> 1u);
+
+                if(0u == ptrIdacMod[freqChIndex])
+                {
+                    ptrIdacMod[freqChIndex] = 1u;
+                }
+                #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN)
+                    ptrSnsCxt[freqChIndex * context->ptrCommonConfig->numSns].idacComp = ptrIdacMod[freqChIndex];
+                #endif
+            }
+            calMask >>= 1u;
+        }
+        while(calMask != 0u);
+
+        for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+        {
+            /* Set the max Idac value */
+            if (ptrIdacMax[freqChIndex] < ptrIdacMod[freqChIndex])
+            {
+                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((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
+        /* Wait for EOS */
+        while (CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
+        {
+            if(0uL == watchdogCounter)
+            {
+                break;
+            }
+            watchdogCounter--;
+        }
+    }
+
+    for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+    {
+        ptrWdCxt->idacMod[freqChIndex] = maxColIdac[freqChIndex];
+
+        #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+            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];
+
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_ROW_COL_ALIGN_EN)
+                    if (((uint32_t)ptrWdCxt->idacMod[freqChIndex] * ptrWdCxt->snsClk) <
+                        ((uint32_t)ptrWdCxt->rowIdacMod[freqChIndex] * ptrWdCxt->rowSnsClk))
+                    {
+                        tmpVal = ((uint32_t)ptrWdCxt->rowIdacMod[freqChIndex] * ptrWdCxt->rowSnsClk) / ptrWdCxt->snsClk;
+                        if (tmpVal > CY_CAPSENSE_CAL_IDAC_MAX_VALUE)
+                        {
+                            tmpVal = CY_CAPSENSE_CAL_IDAC_MAX_VALUE;
+                        }
+                        ptrWdCxt->idacMod[freqChIndex] = (uint8_t)tmpVal;
+                    }
+                    else
+                    {
+                        tmpVal = ((uint32_t)ptrWdCxt->idacMod[freqChIndex] * ptrWdCxt->snsClk) / ptrWdCxt->rowSnsClk;
+                        if (tmpVal > CY_CAPSENSE_CAL_IDAC_MAX_VALUE)
+                        {
+                            tmpVal = CY_CAPSENSE_CAL_IDAC_MAX_VALUE;
+                        }
+                        ptrWdCxt->rowIdacMod[freqChIndex] = (uint8_t)tmpVal;
+                    }
+            #endif
+            }
+        #endif /* ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)) */
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDCalibrateWidget
+****************************************************************************//**
+*
+* Executes the IDAC calibration for all the sensors in the widget specified in
+* the input.
+*
+* \deprecated 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
+* specified by the target parameter.
+*
+* Calibration returns CY_CAPSENSE_STATUS_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 smart sensing algorithm auto-tuning mode is configured.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param target
+* Specifies the calibration target in percentages of the maximum raw count.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the specified widget calibration:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is successfully completed.
+* - CY_CAPSENSE_STATUS_BAD_PARAM     - The input parameter is invalid.
+* - CY_CAPSENSE_STATUS_BAD_DATA      - The calibration failed and CAPSENSE&trade; may not operate
+*                          as expected.
+* - CY_CAPSENSE_STATUS_INVALID_STATE - The previous scanning is not completed, and
+*                         the CAPSENSE&trade; middleware is busy.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_CSDCalibrateWidget(
+                uint32_t widgetId,
+                uint32_t target,
+                cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t calibrateStatus = CY_CAPSENSE_STATUS_SUCCESS;
+    uint32_t cpuFreqMHz;
+    uint32_t watchdogCounter;
+    uint32_t modClkDivider;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+
+    #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_AUTO_GAIN_EN)
+        uint32_t gainSwitch;
+    #endif
+
+    /* Approximate duration of Wait For Init loop */
+    const uint32_t isBusyLoopDuration = 5uL;
+
+    /* Wait For Init watchdog timeout in microseconds */
+    uint64_t isBusyWatchdogTimeUs;
+
+    if(context->ptrCommonConfig->numWd <= widgetId)
+    {
+        calibrateStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
+    }
+
+    if(CY_CAPSENSE_CSD_GROUP != context->ptrWdConfig[widgetId].senseMethod)
+    {
+        calibrateStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
+    }
+
+    if(CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
+    {
+        /* Previous widget is being scanned, return error */
+        calibrateStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
+    }
+
+    if(CY_CAPSENSE_STATUS_SUCCESS == calibrateStatus)
+    {
+        ptrWdCfg = &context->ptrWdConfig[widgetId];
+        ptrWdCfg->ptrWdContext->idacGainIndex = context->ptrCommonConfig->csdIdacGainInitIndex;
+
+        /* Perform calibration */
+        #if(CY_CAPSENSE_DISABLE == CY_CAPSENSE_CSD_IDAC_AUTO_GAIN_EN)
+            Cy_CapSense_CSDCalibrate(widgetId, target, context);
+        #else
+            do
+            {
+                Cy_CapSense_CSDCalibrate(widgetId, target, context);
+                gainSwitch = Cy_CapSense_CSDSwitchIdacGain(context);
+            } while(0u != gainSwitch);
+        #endif
+
+        #if(CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_IDAC_COMP_EN)
+            /* IDAC Normalization in Dual IDAC mode */
+            Cy_CapSense_CSDNormalizeIdac(ptrWdCfg, target, context);
+        #endif
+
+        /* Perform specified widget scan to check calibration result */
+        Cy_CapSense_CSDSetupWidget(widgetId, context);
+        Cy_CapSense_CSDScan(context);
+
+        modClkDivider = context->ptrCommonContext->modCsdClk;
+        if(0u == modClkDivider)
+        {
+            modClkDivider = 1u;
+        }
+
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+            isBusyWatchdogTimeUs  = (uint64_t)CY_CAPSENSE_MAX_SUPPORTED_FREQ_NUM * ptrWdCfg->numSns * ptrWdCfg->ptrWdContext->maxRawCount;
+        #else
+            isBusyWatchdogTimeUs  = (uint64_t)ptrWdCfg->numSns * ptrWdCfg->ptrWdContext->maxRawCount;
+        #endif
+        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((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
+        while (CY_CAPSENSE_BUSY == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
+        {
+            if(0uL == watchdogCounter)
+            {
+                break;
+            }
+            watchdogCounter--;
+        }
+
+        /* Verification of calibration result */
+
+        calibrateStatus = Cy_CapSense_CalibrateCheck(widgetId, target, CY_CAPSENSE_CSD_GROUP, context);
+    }
+
+    return calibrateStatus;
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN) */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDCmodPrecharge
+****************************************************************************//**
+*
+* Initializes the Cmod charging to Vref.
+*
+* This function performs coarse initialization for Cmod and Csh.
+* The coarse initialization is performed by HSCOMP.
+* The HSCOMP monitors the Cmod voltage via Cmod sense path
+* and charges the Cmod using HCAV switch via CSDBUS-A, AMUXBUS-A
+* and static connection of Cmod to AMUXBUS-A.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDCmodPrecharge(cy_stc_capsense_context_t * context)
+{
+    uint32_t cpuFreqMHz;
+    uint32_t watchdogCounter;
+
+    /* Approximate duration of Wait For Init loop */
+    const uint32_t intrInitLoopDuration = 5uL;
+
+    /* Wait For Init watchdog timeout in microseconds */
+    const uint32_t initWatchdogTimeUs = CY_CAPSENSE_CSD_PRECHARGE_WATCHDOG_TIME_US;
+
+    /* Disable INIT interrupt */
+    context->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK;
+    (void)context->ptrCommonConfig->ptrCsdBase->INTR_MASK;
+
+    context->ptrCommonConfig->ptrCsdBase->HSCMP = context->ptrInternalContext->csdRegHscmpInit;
+    context->ptrCommonConfig->ptrCsdBase->CSDCMP = CY_CAPSENSE_CSD_CSDCMP_CSDCMP_EN_MSK;
+
+    context->ptrCommonConfig->ptrCsdBase->SW_RES = context->ptrInternalContext->csdRegSwResInit;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_MOD_SEL = 0u;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_TANK_SEL = 0u;
+
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+        (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN))
+        context->ptrCommonConfig->ptrCsdBase->SW_SHIELD_SEL = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_HSCMP;
+        context->ptrCommonConfig->ptrCsdBase->SW_HS_P_SEL = context->ptrInternalContext->csdRegSwHsPSelCtankInit;
+
+        /* Start SEQUENCER for coarse initialization for Csh */
+        context->ptrCommonConfig->ptrCsdBase->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)
+        {
+            /* Set sequencer to idle state if coarse initialization fails */
+            context->ptrCommonConfig->ptrCsdBase->SEQ_START = CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK;
+        }
+    #endif
+
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_P_SEL = context->ptrInternalContext->csdRegSwHsPSelCmodInit;
+    context->ptrCommonConfig->ptrCsdBase->SW_SHIELD_SEL = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_HSCMP;
+
+    /* Start SEQUENCER for coarse initialization for Cmod */
+    context->ptrCommonConfig->ptrCsdBase->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)
+    {
+        /* Set sequencer to idle state if coarse initialization fails */
+        context->ptrCommonConfig->ptrCsdBase->SEQ_START = CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDTriggerScan
+****************************************************************************//**
+*
+* Triggers the scanning.
+*
+* 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
+* to CSDBUS-A and then the AMUXBUS-A.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_CSDTriggerScan(cy_stc_capsense_context_t * context)
+{
+    /* Clear previous interrupts */
+    context->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)context->ptrCommonConfig->ptrCsdBase->INTR;
+
+    /* Enable SAMPLE interrupt */
+    context->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK;
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_P_SEL = context->ptrInternalContext->csdRegSwHsPSelScan;
+
+    /* Set scanning configuration for switches */
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_MOD_SEL = 0u;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_TANK_SEL = 0u;
+    context->ptrCommonConfig->ptrCsdBase->SW_SHIELD_SEL = context->ptrInternalContext->csdRegSwShieldSelScan;
+
+    context->ptrCommonConfig->ptrCsdBase->SW_RES = context->ptrInternalContext->csdRegSwResScan;
+    context->ptrCommonConfig->ptrCsdBase->HSCMP = context->ptrInternalContext->csdRegHscmpScan;
+
+    /* Force the LFSR to it's initial state (all ones) */
+    context->ptrCommonConfig->ptrCsdBase->SENSE_PERIOD =
+            context->ptrCommonConfig->ptrCsdBase->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 */
+    context->ptrCommonConfig->ptrCsdBase->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;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDScanISR
+****************************************************************************//**
+*
+* 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
+*   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
+*   conversions is greater than the Noise Metric Threshold.
+* - Initiate the scan of the next sensor for multiple sensor scanning mode.
+* - Update the status register in the data structure.
+* - Switch the CSD HW block to the default state if scanning of all the sensors is
+*   completed.
+*
+* This is an internal ISR function for the single-sensor scanning implementation.
+*
+* \param capsenseContext
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSDScanISR(void * capsenseContext)
+{
+    uint32_t rawData;
+    uint32_t maxCount;
+    cy_stc_capsense_context_t * cxt = (cy_stc_capsense_context_t *)capsenseContext;
+    const cy_stc_active_scan_sns_t * ptrActive = cxt->ptrActiveScanSns;
+
+    /* Clear pending interrupt */
+    cxt->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)cxt->ptrCommonConfig->ptrCsdBase->INTR;
+
+    /* Open HCBV and HCBG switches */
+    cxt->ptrCommonConfig->ptrCsdBase->SW_SHIELD_SEL = 0u;
+
+    /* Save raw count */
+    maxCount = (1uL << ptrActive->ptrWdContext->resolution) - 1uL;
+    rawData = cxt->ptrCommonConfig->ptrCsdBase->RESULT_VAL1 & CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK;
+
+    if(rawData > maxCount)
+    {
+        rawData = maxCount;
+    }
+    ptrActive->ptrSnsContext->raw = (uint16_t)rawData;
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        /* Either complete scan or initiate new one */
+        if (ptrActive->mfsChannelIndex < CY_CAPSENSE_MFS_CH2_INDEX)
+        {
+            Cy_CapSense_CSDInitNextChScan(cxt);
+        }
+        else if (CY_CAPSENSE_SCAN_SCOPE_SNGL_SNS == ptrActive->scanScope)
+        {
+            Cy_CapSense_ClrBusyFlags(cxt);
+        }
+        else
+        {
+            /* Disable sensor */
+            Cy_CapSense_CSDDisconnectSnsExt(cxt);
+            /* Scan the next sensor */
+            Cy_CapSense_CSDInitNextSnsScan(cxt);
+        }
+    #else
+        if (CY_CAPSENSE_SCAN_SCOPE_SNGL_SNS == ptrActive->scanScope)
+        {
+            Cy_CapSense_ClrBusyFlags(cxt);
+        }
+        else
+        {
+            /* Disable sensor */
+            Cy_CapSense_CSDDisconnectSnsExt(cxt);
+            /* Scan the next sensor */
+            Cy_CapSense_CSDInitNextSnsScan(cxt);
+        }
+    #endif
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDInitNextSnsScan
+****************************************************************************//**
+*
+* This function initializes the next sensor scan.
+*
+* 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
+* widget until all the widgets are scanned.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_CSDInitNextSnsScan(cy_stc_capsense_context_t * context)
+{
+    const 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)
+    {
+        /* Switch to the next sensor */
+        Cy_CapSense_InitActivePtrSns(sensorId, context);
+
+        Cy_CapSense_CSDCalculateScanDuration(context);
+        Cy_CapSense_CSDConfigClock(context);
+        Cy_CapSense_CSDConnectSnsExt(context);
+        Cy_CapSense_CSDSetUpIdacs(context);
+
+        Cy_CapSense_CSDStartSample(context);
+    }
+    else
+    {
+        if (0u != (ptrActive->scanScope & CY_CAPSENSE_SCAN_SCOPE_ALL_WD_MASK))
+        {
+            /* Configure and begin scanning next widget */
+            Cy_CapSense_SsPostAllWidgetsScan(context);
+        }
+        else
+        {
+            /* All the widgets are scanned */
+            Cy_CapSense_ClrBusyFlags(context);
+        }
+    }
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDInitNextChScan
+****************************************************************************//**
+*
+* This function initializes the next frequency of the sensor scan.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_CSDInitNextChScan(cy_stc_capsense_context_t * context)
+{
+    cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
+
+    ptrActive->mfsChannelIndex++;
+    ptrActive->ptrSnsContext += context->ptrCommonConfig->numSns;
+
+    Cy_CapSense_CSDChangeClkFreq((uint32_t)ptrActive->mfsChannelIndex, context);
+    Cy_CapSense_CSDSetUpIdacs(context);
+    Cy_CapSense_CSDStartSample(context);
+}
+
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSDChangeClkFreq
+****************************************************************************//**
+*
+*  This function changes the sensor clock frequency by configuring
+*  the corresponding divider.
+*
+* \param channelIndex
+*  The frequency channel index.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+__STATIC_INLINE void Cy_CapSense_CSDChangeClkFreq(uint32_t channelIndex, 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 regValue = 0u;
+    uint32_t freqOffset;
+    uint32_t conversionsNum;
+
+    /* Getting row clock divider for matrix buttons or touchpad widgets */
+    if (context->ptrActiveScanSns->ptrWdConfig->numCols <= context->ptrActiveScanSns->sensorIndex)
+    {
+        snsClkDivider = ptrWdCxt->rowSnsClk;
+    }
+    else
+    {
+        snsClkDivider = ptrWdCxt->snsClk;
+    }
+
+    /* Change the divider based on the chId */
+    switch (channelIndex)
+    {
+        case CY_CAPSENSE_MFS_CH1_INDEX:
+        {
+            freqOffset = context->ptrCommonConfig->csdMfsDividerOffsetF1;
+            break;
+        }
+        case CY_CAPSENSE_MFS_CH2_INDEX:
+        {
+            freqOffset = context->ptrCommonConfig->csdMfsDividerOffsetF2;
+            break;
+        }
+        default:
+        {
+            freqOffset = 0u;
+            break;
+        }
+    }
+
+    if ((CY_CAPSENSE_CLK_SOURCE_PRS8 == snsClkSrc) || (CY_CAPSENSE_CLK_SOURCE_PRS12 == snsClkSrc))
+    {
+        freqOffset <<= 1uL;
+    }
+
+    snsClkDivider += freqOffset;
+
+    /* Set Number Of Conversions based on scanning resolution */
+    conversionsNum = Cy_CapSense_CSDGetNumberOfConversions(snsClkDivider, (uint32_t)ptrWdCxt->resolution, (uint32_t)snsClkSrc);
+    context->ptrCommonConfig->ptrCsdBase->SEQ_NORM_CNT = (conversionsNum & CY_CAPSENSE_CSD_SEQ_NORM_CNT_CONV_CNT_MSK);
+
+    /* Configuring PRS SEL_BIT  and decreasing divider in case of PRS */
+    if ((CY_CAPSENSE_CLK_SOURCE_PRS8 == snsClkSrc) || (CY_CAPSENSE_CLK_SOURCE_PRS12 == snsClkSrc))
+    {
+        regValue = CY_CAPSENSE_CSD_SENSE_PERIOD_SEL_LFSR_MSB_MSK;
+        snsClkDivider >>= 1u;
+    }
+
+    /* Check divider value */
+    if (0u == snsClkDivider)
+    {
+        snsClkDivider = 1u;
+    }
+
+    regValue |= ((snsClkSrc << CY_CAPSENSE_CSD_SENSE_PERIOD_LFSR_SIZE_POS) | (snsClkDivider - 1u));
+
+    /* Update reg value with divider and configuration */
+    context->ptrCommonConfig->ptrCsdBase->SENSE_PERIOD = regValue;
+}
+#endif
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2)) */
+
+
+/* [] END OF FILE */

+ 101 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_csd_v2.h

@@ -0,0 +1,101 @@
+/***************************************************************************//**
+* \file cy_capsense_csd_v2.h
+* \version 3.0
+*
+* \brief
+* This file provides the function prototypes specific to the CSD sensing
+* method implementation.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_CSD_V2_H)
+#define CY_CAPSENSE_CSD_V2_H
+
+#include "cy_syslib.h"
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/****************************************************************************
+* Register and mode mask definition
+****************************************************************************/
+#define CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL                      (0x00000000uL)
+#define CY_CAPSENSE_DEFAULT_CSD_INTR_SET                        (0x00000000uL)
+#define CY_CAPSENSE_DEFAULT_SW_HS_N_SEL                         (0x00000000uL)
+#define CY_CAPSENSE_DEFAULT_CSD_ADC_CTL                         (0x00000000uL)
+
+#define CY_CAPSENSE_EXT_CAP_DISCHARGE_TIME                      (1u)
+
+/***************************************
+* Function Prototypes
+**************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CALIBRATION_EN)
+cy_capsense_status_t Cy_CapSense_CSDCalibrateWidget(uint32_t widgetId, uint32_t target, cy_stc_capsense_context_t * context);
+#endif
+void Cy_CapSense_CSDSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * context);
+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, 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);
+
+void Cy_CapSense_CSDDisableMode(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSDInitialize(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSDStartSample(cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+void Cy_CapSense_CSDDisableShieldElectrodes(const cy_stc_capsense_context_t * context);
+#endif
+
+uint32_t Cy_CapSense_CSDGetNumberOfConversions(uint32_t snsClkDivider, uint32_t resolution, uint32_t snsClkSrc);
+void Cy_CapSense_CSDSetUpIdacs(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSDSnsStateCheck(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSDCalculateScanDuration(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSDConnectSnsExt(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSDDisconnectSnsExt(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSDConfigClock(cy_stc_capsense_context_t * context);
+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 */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2)) */
+
+#endif /* CY_CAPSENSE_CSD_V2_H */
+
+
+/* [] END OF FILE */

+ 1410 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_csx_v2.c

@@ -0,0 +1,1410 @@
+/***************************************************************************//**
+* \file cy_capsense_csx_v2.c
+* \version 3.0
+*
+* \brief
+* This file defines the data structure global variables and provides
+* implementation for the low-level functions of the CSX part of
+* the Sensing module. The file contains the functions used for the CSD HW block
+* initialization, calibration, and scanning.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include <stddef.h>
+#include "cy_syslib.h"
+#include "cy_sysclk.h"
+#include "cy_gpio.h"
+#include "cy_csd.h"
+
+#include "cy_device_headers.h"
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_csx_v2.h"
+#include "cy_capsense_sensing_v2.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+
+
+/*******************************************************************************
+* Local function declarations
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+static void Cy_CapSense_CSXSetSnsClkFreq(uint32_t channelIndex, cy_stc_capsense_context_t * context);
+static void Cy_CapSense_CSXStartSample(cy_stc_capsense_context_t * context);
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+static void Cy_CapSense_CSXInitNextChScan(cy_stc_capsense_context_t * context);
+#endif
+static void Cy_CapSense_CSXInitNextScan(cy_stc_capsense_context_t * context);
+
+__STATIC_INLINE void Cy_CapSense_CSXStartSampleExt(cy_stc_capsense_context_t * context);
+
+/** \} \endcond */
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXInitialize
+****************************************************************************//**
+*
+* Performs hardware and firmware initialization required for the CSX operation
+* of the CAPSENSE&trade; 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
+* 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
+* in the CAPSENSE&trade; 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
+* called.
+*
+* Similarly, set up and scan all the CSX widgets in such
+* a sequence that the Cy_CapSense_SetupWidget() does not need to perform
+* hardware sensing-configuration switches.
+*
+* Do not call this function directly from
+* the application program.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSXInitialize(cy_stc_capsense_context_t * context)
+{
+    uint32_t modClkDivider;
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        uint32_t shieldIndex;
+        const cy_stc_capsense_pin_config_t * ptrShieldPin = context->ptrShieldPinConfig;
+    #endif
+
+    Cy_CapSense_DischargeExtCapacitors(context);
+
+    Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA, (uint32_t)context->ptrCommonConfig->pinCintA, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_CSX_CINT_SCAN_PIN_HSIOM);
+    Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB, (uint32_t)context->ptrCommonConfig->pinCintB, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_CSX_CINT_SCAN_PIN_HSIOM);
+
+    /* Clear all pending interrupts of the CSD HW block */
+    context->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+
+    /* Enable the End Of Scan interrupt */
+    context->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_DEFAULT_CSD_INTR_MASK_CFG;
+    context->ptrCommonConfig->ptrCsdBase->INTR_SET = 0u;
+    context->ptrCommonConfig->ptrCsdBase->HSCMP = CY_CAPSENSE_DEFAULT_CSD_HSCMP_CFG;
+    context->ptrCommonConfig->ptrCsdBase->AMBUF = context->ptrInternalContext->csxRegAMuxBuf;
+    context->ptrCommonConfig->ptrCsdBase->REFGEN = context->ptrInternalContext->csxRegRefgen;
+    context->ptrCommonConfig->ptrCsdBase->CSDCMP = CY_CAPSENSE_DEFAULT_CSD_CSDCMP_CFG;
+    context->ptrCommonConfig->ptrCsdBase->IDACA = CY_CAPSENSE_DEFAULT_CSD_IDACA_CFG;
+    context->ptrCommonConfig->ptrCsdBase->IDACB = CY_CAPSENSE_DEFAULT_CSD_IDACB_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_RES = context->ptrInternalContext->csxRegSwResInit;
+    context->ptrCommonConfig->ptrCsdBase->SENSE_DUTY = CY_CAPSENSE_DEFAULT_CSD_SENSE_DUTY_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_P_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_HS_P_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_N_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_HS_N_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_SHIELD_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_SHIELD_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_AMUXBUF_SEL = context->ptrInternalContext->csxRegRefgenSel;
+    context->ptrCommonConfig->ptrCsdBase->SW_BYP_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_BYP_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_CMP_P_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_CMP_P_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_CMP_N_SEL = context->ptrInternalContext->csxRegSwCmpNSel;
+    context->ptrCommonConfig->ptrCsdBase->SW_REFGEN_SEL = context->ptrInternalContext->csxRegSwRefGenSel;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_MOD_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_FW_MOD_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_TANK_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_FW_TANK_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_DSI_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SEQ_TIME = 0u;
+    context->ptrCommonConfig->ptrCsdBase->SEQ_INIT_CNT = (uint32_t)context->ptrCommonConfig->csxFineInitTime;
+    context->ptrCommonConfig->ptrCsdBase->SEQ_NORM_CNT = CY_CAPSENSE_DEFAULT_CSD_SEQ_NORM_CNT_CFG;
+    context->ptrCommonConfig->ptrCsdBase->ADC_CTL = CY_CAPSENSE_DEFAULT_CSD_ADC_CTL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SEQ_START = CY_CAPSENSE_DEFAULT_CSD_SEQ_START_CFG;
+    context->ptrCommonConfig->ptrCsdBase->CONFIG = context->ptrInternalContext->csxRegConfigInit;
+
+    #if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
+        context->ptrCommonConfig->ptrCsdBase->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 sensor states to the defined ISC state including shield (if enabled) */
+    Cy_CapSense_SetIOsInDesiredState(context->ptrInternalContext->csxInactiveSnsDm, 0u,
+                                     context->ptrInternalContext->csxInactiveSnsHsiom, context);
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && (0u != CY_CAPSENSE_SHIELD_PIN_COUNT))
+        /* Connect shields to CSX ISC */
+        for (shieldIndex = 0u; shieldIndex < CY_CAPSENSE_SHIELD_PIN_COUNT; shieldIndex++)
+        {
+            Cy_CapSense_SsConfigPinRegisters(ptrShieldPin->pcPtr, (uint32_t)ptrShieldPin->pinNumber,
+                                             context->ptrInternalContext->csxInactiveSnsDm,
+                                             context->ptrInternalContext->csxInactiveSnsHsiom);
+            ptrShieldPin++;
+        }
+    #endif
+
+    /* Enable the CSD HW block interrupt and set interrupt vector to CSX sensing method */
+    context->ptrInternalContext->ptrISRCallback = &Cy_CapSense_CSXScanISR;
+
+    context->ptrActiveScanSns->mfsChannelIndex = 0u;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXElectrodeCheck
+****************************************************************************//**
+*
+* Check whether electrodes were previously connected using
+* the Cy_CapSense_CSXSetupWidgetExt() function and if yes, disconnect them.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSXElectrodeCheck(cy_stc_capsense_context_t * context)
+{
+    if (CY_CAPSENSE_SNS_CONNECTED == context->ptrActiveScanSns->connectedSnsState)
+    {
+        /* Disconnect all Tx pins */
+        Cy_CapSense_CSXDisconnectTxExt(context);
+        /* Disconnect all Rx pins */
+        Cy_CapSense_CSXDisconnectRxExt(context);
+        /* Mark the current sensor as disconnected */
+        context->ptrActiveScanSns->connectedSnsState = CY_CAPSENSE_SNS_DISCONNECTED;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXDisableMode
+****************************************************************************//**
+*
+* This function disables CSX mode.
+*
+* 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_GPIO);
+    Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB, (uint32_t)context->ptrCommonConfig->pinCintB, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_GPIO);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXSetupWidget
+****************************************************************************//**
+*
+* Performs the initialization required to scan the specified CSX widget.
+*
+* \deprecated 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
+* 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.
+* 2. Initialize the CSD HW block with specific sensing configuration (e.g.
+* sensor clock, scan resolution) used by the widget.
+* 3. Disconnect all previously connected electrodes, if the electrodes
+* connected by the Cy_CapSense_CSDSetupWidgetExt(),
+* Cy_CapSense_CSXSetupWidgetExt() functions are not disconnected.
+*
+* 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
+* 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()
+* 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
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSXSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * context)
+{
+    /* variable to access widget details */
+    uint32_t tmpRegVal;
+
+    (void)Cy_CapSense_SwitchSensingMode(CY_CAPSENSE_CSX_GROUP, context);
+    /*
+    * Check whether CSX electrodes were previously connected using
+    * Cy_CapSense_CSXSetupWidgetExt and if yes, disconnect them
+    */
+    Cy_CapSense_CSXElectrodeCheck(context);
+    /* 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;
+    context->ptrCommonConfig->ptrCsdBase->SEQ_NORM_CNT = tmpRegVal;
+    context->ptrActiveScanSns->ptrWdContext->maxRawCount = (uint16_t)tmpRegVal *
+        (context->ptrActiveScanSns->ptrWdContext->snsClk - CY_CAPSENSE_CSX_DEADBAND_CYCLES_NUMBER);
+
+        /* SnsClk setup */
+    #if (CY_CAPSENSE_ENABLE != CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        Cy_CapSense_CSXSetSnsClkFreq(CY_CAPSENSE_MFS_CH0_INDEX, context);
+    #endif
+}
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXSetupWidgetExt
+****************************************************************************//**
+*
+* Performs extended initialization required to scan a specified sensor in
+* a widget using CSX sensing method.
+*
+* \deprecated 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
+* 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
+* would cause an unexpected result.
+*
+* 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
+* 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
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* file defined as CY_CAPSENSE_<WIDGET_NAME>_SNS<SENSOR_NUMBER>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSXSetupWidgetExt(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                cy_stc_capsense_context_t * context)
+{
+    /* Initialize widget */
+    Cy_CapSense_CSXSetupWidget(widgetId, context);
+
+    /* 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
+    */
+    Cy_CapSense_CSXConnectTxExt(context);
+    Cy_CapSense_CSXConnectRxExt(context);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXScan
+****************************************************************************//**
+*
+* This function initiates a scan for the sensors of the widget initialized
+* by the Cy_CapSense_CSXSetupWidget() function.
+*
+* \deprecated 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:
+* 1. Connects the first sensor of the widget.
+* 2. Configures the IDAC value.
+* 3. Starts scanning for the first sensor in the widget.
+*
+* This function is called by the Cy_CapSense_Scan() if the given
+* widget uses the CSX sensing method.
+*
+* 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 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 the Cy_CapSense_CSXSetupWidget() function prior
+* to calling this function.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSXScan(cy_stc_capsense_context_t * context)
+{
+    Cy_CapSense_InitActivePtrSns(0u, context);
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        Cy_CapSense_CSXSetSnsClkFreq(CY_CAPSENSE_MFS_CH0_INDEX, context);
+    #endif
+
+    context->ptrActiveScanSns->scanScope |= CY_CAPSENSE_SCAN_SCOPE_ALL_SNS_MASK;
+
+    /* Connect electrodes */
+    Cy_CapSense_CSXConnectTxExt(context);
+    Cy_CapSense_CSXConnectRxExt(context);
+
+    /* Set Start of scan flag */
+    Cy_CapSense_SetBusyFlags(context);
+    Cy_CapSense_CSXStartSample(context);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXScanExt()
+****************************************************************************//**
+*
+* Starts the CSD conversion on the preconfigured sensor.
+*
+* \deprecated 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
+* 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.
+*
+* 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
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSXScanExt(cy_stc_capsense_context_t * context)
+{
+    cy_stc_active_scan_sns_t * ptrActive = context->ptrActiveScanSns;
+
+    /* Set busy flag and start conversion */
+    Cy_CapSense_SetBusyFlags(context);
+
+    /* Set scope flag */
+    ptrActive->scanScope = CY_CAPSENSE_SCAN_SCOPE_SNGL_SNS;
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        if(0u != ptrActive->mfsChannelIndex)
+        {
+            Cy_CapSense_InitActivePtrSns(ptrActive->sensorIndex, context);
+            Cy_CapSense_CSXSetSnsClkFreq(CY_CAPSENSE_MFS_CH0_INDEX, context);
+        }
+    #endif
+
+    Cy_CapSense_CSXStartSample(context);
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXCalibrateWidget
+****************************************************************************//**
+*
+* Executes the IDAC calibration for all the sensors in the widget specified in
+* the input.
+*
+* \deprecated 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
+* the raw count to the level specified by the target parameter.
+*
+* Calibration returns CY_CAPSENSE_STATUS_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.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param target
+* Specifies the calibration target in percentages of the maximum raw count.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the specified widget calibration:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is successfully completed.
+* - CY_CAPSENSE_STATUS_BAD_PARAM     - The input parameter is invalid.
+* - CY_CAPSENSE_STATUS_BAD_DATA      - The calibration failed and CAPSENSE&trade; may not operate
+*                         as expected.
+* - CY_CAPSENSE_STATUS_INVALID_STATE - The previous scanning is not completed, and
+*                         the CAPSENSE&trade; middleware is busy.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_CSXCalibrateWidget(
+                uint32_t widgetId,
+                uint32_t target,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t cpuFreqMHz;
+    uint32_t watchdogCounter;
+    uint32_t freqChIndex;
+
+    cy_capsense_status_t calibrateStatus = CY_CAPSENSE_STATUS_SUCCESS;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+    cy_stc_capsense_sensor_context_t * ptrActSnsContext;
+
+    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 = ((uint8_t)CY_CAPSENSE_CAL_MIDDLE_VALUE) >> 1u;
+
+    /* Approximate duration of Wait For Init loop */
+    const uint32_t isBusyLoopDuration = 5u;
+
+    /* Wait For Init watchdog timeout in microseconds */
+    uint64_t isBusyWatchdogTimeUs = 0u;
+
+
+    if((context->ptrCommonConfig->numWd <= widgetId) ||
+        (CY_CAPSENSE_DISABLE == context->ptrCommonConfig->csxIdacAutocalEn))
+    {
+        calibrateStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
+    }
+
+    if(CY_CAPSENSE_CSX_GROUP != context->ptrWdConfig[widgetId].senseMethod)
+    {
+        calibrateStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
+    }
+
+    if(CY_CAPSENSE_BUSY  == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
+    {
+        /* Previous widget is being scanned, return error */
+        calibrateStatus = CY_CAPSENSE_STATUS_INVALID_STATE;
+    }
+
+    if(CY_CAPSENSE_STATUS_SUCCESS == calibrateStatus)
+    {
+        ptrWdCfg = &context->ptrWdConfig[widgetId];
+        ptrActSnsContext = ptrWdCfg->ptrSnsContext;
+        totalSns = ptrWdCfg->numSns;
+
+        /* Calculate target raw count */
+        rawTarget = ((uint32_t)context->ptrWdContext[widgetId].maxRawCount * target) / CY_CAPSENSE_PERCENTAGE_100;
+
+        /* Clear raw count registers and IDAC registers of all the sensors/nodes */
+        for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+        {
+            /* Clear raw count registers and IDAC registers of all the sensors/nodes */
+            for (calibrationIndex = 0u; calibrationIndex < totalSns; calibrationIndex++)
+            {
+                ptrActSnsContext[calibrationIndex + (freqChIndex * context->ptrCommonConfig->numSns)].raw = 0u;
+                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 == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+            if(context->ptrCommonConfig->csxMfsDividerOffsetF1 >
+               context->ptrCommonConfig->csxMfsDividerOffsetF2)
+            {
+                snsClkDivider += context->ptrCommonConfig->csxMfsDividerOffsetF1;
+            }
+            else
+            {
+                snsClkDivider += context->ptrCommonConfig->csxMfsDividerOffsetF2;
+            }
+
+            isBusyWatchdogTimeUs  = (uint64_t)totalSns * CY_CAPSENSE_MAX_SUPPORTED_FREQ_NUM * ptrWdCfg->ptrWdContext->resolution;
+        #else
+            isBusyWatchdogTimeUs  = (uint64_t)totalSns * ptrWdCfg->ptrWdContext->resolution;
+        #endif
+
+        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
+        {
+            /* Scan all the sensors/nodes in widget */
+            (void)Cy_CapSense_SetupWidget(widgetId, context);
+            (void)Cy_CapSense_Scan(context);
+
+            cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
+            watchdogCounter = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
+            /* Wait for EOS */
+            while (CY_CAPSENSE_BUSY  == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
+            {
+                if(0uL == watchdogCounter)
+                {
+                    break;
+                }
+
+                watchdogCounter--;
+            }
+
+            /* Set pointer to the widget's first sensor data */
+            ptrActSnsContext = ptrWdCfg->ptrSnsContext;
+
+            /* Check raw count and adjust IDAC, loop through all the sensors/nodes */
+            for (freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+            {
+                for (calibrationIndex = 0u; calibrationIndex < totalSns; calibrationIndex++)
+                {
+                    /* Check whether the current raw count is above target.
+                    * If yes, clear the MS bit of bit.
+                    * If no, keep the MS bit and set next bit.
+                    */
+                    if (ptrActSnsContext[calibrationIndex + (freqChIndex * context->ptrCommonConfig->numSns)].raw > rawTarget)
+                    {
+                        ptrActSnsContext[calibrationIndex + (freqChIndex * context->ptrCommonConfig->numSns)].idacComp &= (uint8_t)(~curIdacMask);
+                    }
+                    ptrActSnsContext[calibrationIndex + (freqChIndex * context->ptrCommonConfig->numSns)].idacComp |= nextIdacMask;
+                }
+            }
+
+            /* Shift both current IDAC and pre IDAC values to the right by 1 */
+            curIdacMask = nextIdacMask;
+            nextIdacMask = nextIdacMask >> 1u;
+        }
+        while (curIdacMask != 0u);
+        calibrateStatus = CY_CAPSENSE_STATUS_SUCCESS;
+    }
+
+    if(CY_CAPSENSE_STATUS_SUCCESS == calibrateStatus)
+    {
+        /* Perform specified widget scan to check calibration result */
+        /* Scan all the sensors/nodes in widget */
+        (void)Cy_CapSense_SetupWidget(widgetId, context);
+        (void)Cy_CapSense_Scan(context);
+
+        cpuFreqMHz = context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA;
+        watchdogCounter = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs, cpuFreqMHz, isBusyLoopDuration);
+
+        /* Wait for EOS */
+        while (CY_CAPSENSE_BUSY  == (context->ptrCommonContext->status & CY_CAPSENSE_BUSY))
+        {
+            if(0uL == watchdogCounter)
+            {
+                calibrateStatus = CY_CAPSENSE_STATUS_TIMEOUT;
+                break;
+            }
+
+            watchdogCounter--;
+        }
+
+        if(CY_CAPSENSE_STATUS_SUCCESS == calibrateStatus)
+        {
+            calibrateStatus = Cy_CapSense_CalibrateCheck(widgetId, target, CY_CAPSENSE_CSX_GROUP, context);
+        }
+    }
+
+    return(calibrateStatus);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN) */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXSetUpIdacs
+****************************************************************************//**
+*
+* Configures IDAC for the CSX sensing method.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSXSetUpIdacs(cy_stc_capsense_context_t * context)
+{
+    uint32_t tmpRegVal;
+
+    /* Set IDAC gain */
+    tmpRegVal = context->ptrCommonConfig->idacGainTable[context->ptrActiveScanSns->ptrWdContext->idacGainIndex].gainReg;
+    /* Set IDAC code */
+    tmpRegVal |= (uint32_t)context->ptrActiveScanSns->ptrSnsContext->idacComp & CY_CAPSENSE_CSD_IDACA_VAL_MSK;
+    tmpRegVal |= CY_CAPSENSE_DEFAULT_CSD_IDACA_CFG;
+
+    context->ptrCommonConfig->ptrCsdBase->IDACA = tmpRegVal;
+}
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SsCSXStartSample
+****************************************************************************//**
+*
+* Starts scanning for the CSX widget.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_CSXStartSample(cy_stc_capsense_context_t * context)
+{
+    /* Set up IDAC Value */
+    Cy_CapSense_CSXSetUpIdacs(context);
+
+    /* Clear previous interrupts */
+    context->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)context->ptrCommonConfig->ptrCsdBase->INTR;
+
+    /* Enable interrupt */
+    context->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_SAMPLE_MSK;
+
+    if(NULL != context->ptrInternalContext->ptrSSCallback)
+    {
+        context->ptrInternalContext->ptrSSCallback(context->ptrActiveScanSns);
+    }
+
+    Cy_CapSense_CSXStartSampleExt(context);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXConnectRx
+****************************************************************************//**
+*
+* Connects port pin (an Rx electrode) to the CSD HW block using AMUX bus.
+*
+* \deprecated This function is obsolete and kept for backward compatibility only.
+* The Cy_CapSense_SetPinState() function should be used instead.
+*
+* 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
+* only use GPIOs that is already assigned to CAPSENSE&trade; 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)
+* or with low-level functions that perform a single-sensor scanning.
+*
+* Scanning should be completed before calling this function.
+*
+* \param rxPtr
+* Specifies the pointer to the cy_stc_capsense_pin_config_t object belonging to
+* a sensor which to be connected to the CSD HW block as an Rx electrode.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \funcusage
+*
+* 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,
+                const cy_stc_capsense_context_t * context)
+{
+    (void) context;
+    Cy_CapSense_SsConfigPinRegisters(rxPtr->pcPtr, (uint32_t)rxPtr->pinNumber, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXConnectTx
+****************************************************************************//**
+*
+* Connects port pin (a Tx electrode) to the CSD HW block.
+*
+* \deprecated This function is obsolete and kept for backward compatibility only.
+* The Cy_CapSense_SetPinState() function should be used instead.
+*
+* 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
+* only use GPIOs that is already assigned to CAPSENSE&trade; 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)
+* or with low-level functions that perform a single-sensor scanning.
+*
+* Scanning should be completed before calling this function.
+*
+* \param txPtr
+* Specifies the pointer to the cy_stc_capsense_pin_config_t object belonging to
+* a sensor which to be connected to the CSD HW block as a Tx electrode.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \funcusage
+*
+* 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,
+                const cy_stc_capsense_context_t * context)
+{
+    (void) context;
+    Cy_CapSense_SsConfigPinRegisters(txPtr->pcPtr, (uint32_t)txPtr->pinNumber, CY_CAPSENSE_DM_GPIO_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
+* it from the AMUX bus.
+*
+* \deprecated This function is obsolete and kept for backward compatibility only.
+* The Cy_CapSense_SetPinState() function should be used instead.
+*
+* 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.
+*
+* \param rxPtr
+* Specifies the pointer to the cy_stc_capsense_pin_config_t object belonging
+* to an Rx pin sensor to be disconnected from the CSD HW block.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \funcusage
+*
+* 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,
+                const cy_stc_capsense_context_t * context)
+{
+    (void) context;
+    Cy_CapSense_SsConfigPinRegisters(rxPtr->pcPtr, (uint32_t)rxPtr->pinNumber,
+                                     context->ptrInternalContext->csxInactiveSnsDm,
+                                     context->ptrInternalContext->csxInactiveSnsHsiom);
+    Cy_GPIO_Clr(rxPtr->pcPtr, (uint32_t)rxPtr->pinNumber);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXDisconnectTx
+****************************************************************************//**
+*
+* Disconnects port pin (a Tx electrode) from the CSD HW block.
+*
+* \deprecated This function is obsolete and kept for backward compatibility only.
+* The Cy_CapSense_SetPinState() function should be used instead.
+*
+* 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.
+*
+* \param txPtr
+* Specifies the pointer to the cy_stc_capsense_pin_config_t object belonging
+* to a Tx pin sensor to be disconnected from the CSD HW block.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \funcusage
+*
+* 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,
+                const cy_stc_capsense_context_t * context)
+{
+    (void) context;
+    Cy_CapSense_SsConfigPinRegisters(txPtr->pcPtr, (uint32_t)txPtr->pinNumber,
+                                     context->ptrInternalContext->csxInactiveSnsDm,
+                                     context->ptrInternalContext->csxInactiveSnsHsiom);
+    Cy_GPIO_Clr(txPtr->pcPtr, (uint32_t)txPtr->pinNumber);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXConnectTxExt
+****************************************************************************//**
+*
+* Connects a current Tx electrode to the CSX scanning hardware.
+*
+* This function connects all current Tx electrode's pins to the CSD_SENSE signal.
+* It is assumed that drive mode of the port pin is already set to STRONG
+* in the HSIOM_PORT_SELx register.
+*
+* Calling this function directly from the application program is not
+* recommended. This function is used to implement only the user's specific
+* use cases (for faster execution time when there is only one port pin for an
+* electrode for example).
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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);
+        pinPointer++;
+    }
+    context->ptrActiveScanSns->connectedSnsState = CY_CAPSENSE_SNS_CONNECTED;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXConnectRxExt
+****************************************************************************//**
+*
+* Connects a current Rx electrode to the CSX scanning hardware.
+*
+* This function connects all current Rx electrode's pins to the CSD_SENSE signal.
+* It is assumed that drive mode of the port pin is already set to STRONG
+* in the HSIOM_PORT_SELx register.
+*
+* Calling this function directly from the application program is not
+* recommended. This function is used to implement only the user's specific
+* use cases (for faster execution time when there is only one port pin for an
+* electrode for example).
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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);
+        pinPointer++;
+    }
+    context->ptrActiveScanSns->connectedSnsState = CY_CAPSENSE_SNS_CONNECTED;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXDisconnectTxExt
+****************************************************************************//**
+*
+* Disconnects a current Tx electrode from the CSX scanning hardware.
+*
+* This function connects all current Tx electrode's pins to the CSD_SENSE signal.
+* It is assumed that drive mode of the port pin is already set to STRONG
+* in the HSIOM_PORT_SELx register.
+*
+* Calling this function directly from the application program is not
+* recommended. This function is used to implement only the user's specific
+* use cases (for faster execution time when there is only one port pin for an
+* electrode for example).
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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);
+        pinPointer++;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXDisconnectRxExt
+****************************************************************************//**
+*
+* Connects a current Tx electrode to the CSX scanning hardware.
+*
+* This function connects all current Tx electrode's pins to the CSD_SENSE signal.
+* It is assumed that drive mode of the port pin is already set to STRONG
+* in the HSIOM_PORT_SELx register.
+*
+* Calling this function directly from the application program is not
+* recommended. This function is used to implement only the user's specific
+* use cases (for faster execution time when there is only one port pin for an
+* electrode for example).
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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);
+        pinPointer++;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXSetWidgetTxClkSrc
+****************************************************************************//**
+*
+* Sets a source for the Tx clock for a widget.
+*
+* \param ptrWdConfig
+* The pointer to the cy_stc_capsense_widget_context_t structure.
+*
+*******************************************************************************/
+void Cy_CapSense_CSXSetWidgetTxClkSrc(const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+
+    if (0u != (ptrWdCxt->snsClkSource & CY_CAPSENSE_CLK_SOURCE_AUTO_MASK))
+    {
+        ptrWdCxt->snsClkSource = (uint8_t)Cy_CapSense_SsCalcLfsrSize((uint32_t)ptrWdCxt->snsClk, (uint32_t)ptrWdCxt->resolution) | CY_CAPSENSE_CLK_SOURCE_AUTO_MASK;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXScanISR
+****************************************************************************//**
+*
+* This is an internal ISR function to handle the CSX sensing method operation.
+*
+* This handler covers the following functionality:
+* - 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 if the number of bad
+* conversions is greater than the Noise Metric Threshold.
+* - Initiate the scan of the next sensor for multiple sensor scanning mode.
+* - Update the Status register in the data structure.
+* - Switch the HW IP block to the default state if scanning of all the sensors is
+* completed.
+*
+* \param capsenseContext
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_CSXScanISR(void * capsenseContext)
+{
+    uint32_t tmpRawCount;
+    cy_stc_capsense_context_t * cxt = (cy_stc_capsense_context_t *)capsenseContext;
+    const cy_stc_active_scan_sns_t * ptrActive = cxt->ptrActiveScanSns;
+    uint32_t maxCount = (uint32_t) ptrActive->ptrWdContext->maxRawCount;
+
+    cxt->ptrCommonConfig->ptrCsdBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK;
+
+    /* Clear all pending interrupts of the CSD HW block */
+    cxt->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)cxt->ptrCommonConfig->ptrCsdBase->INTR;
+
+
+    tmpRawCount  = (uint16_t)(cxt->ptrCommonConfig->ptrCsdBase->RESULT_VAL1 &
+                                             CY_CAPSENSE_CSD_RESULT_VAL1_VALUE_MSK);
+
+    tmpRawCount += (uint16_t)(cxt->ptrCommonConfig->ptrCsdBase->RESULT_VAL2 &
+                                             CY_CAPSENSE_CSD_RESULT_VAL2_VALUE_MSK);
+
+    /* This workaround needed to prevent overflow in the SW register map. ID #234358 */
+    if(tmpRawCount > maxCount)
+    {
+        tmpRawCount = maxCount;
+    }
+    ptrActive->ptrSnsContext->raw = (uint16_t) (maxCount - tmpRawCount);
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        /* Either complete scan or initiate new one */
+        if(ptrActive->mfsChannelIndex < CY_CAPSENSE_MFS_CH2_INDEX)
+        {
+            Cy_CapSense_CSXInitNextChScan(cxt);
+        }
+        else if (CY_CAPSENSE_SCAN_SCOPE_SNGL_SNS == ptrActive->scanScope)
+        {
+            Cy_CapSense_ClrBusyFlags(cxt);
+            cxt->ptrCommonConfig->ptrCsdBase->CONFIG = cxt->ptrInternalContext->csxRegConfigInit;
+            cxt->ptrCommonConfig->ptrCsdBase->CSDCMP = CY_CAPSENSE_DEFAULT_CSD_CSDCMP_CFG;
+            cxt->ptrCommonConfig->ptrCsdBase->IDACA = CY_CAPSENSE_DEFAULT_CSD_IDACA_CFG;
+        }
+        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);
+        }
+    #else
+        if (CY_CAPSENSE_SCAN_SCOPE_SNGL_SNS == ptrActive->scanScope)
+        {
+            Cy_CapSense_ClrBusyFlags(cxt);
+            cxt->ptrCommonConfig->ptrCsdBase->CONFIG = cxt->ptrInternalContext->csxRegConfigInit;
+            cxt->ptrCommonConfig->ptrCsdBase->CSDCMP = CY_CAPSENSE_DEFAULT_CSD_CSDCMP_CFG;
+            cxt->ptrCommonConfig->ptrCsdBase->IDACA = CY_CAPSENSE_DEFAULT_CSD_IDACA_CFG;
+        }
+        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);
+        }
+    #endif
+
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXInitNextScan
+****************************************************************************//**
+*
+* This function initializes the next sensor scan.
+*
+* 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
+* widget until all the widgets are scanned.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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  */
+            ptrActive->ptrTxConfig++;
+            Cy_CapSense_CSXConnectTxExt(context);
+            /* Initiate a next scan */
+            Cy_CapSense_CSXSetUpIdacs(context);
+            Cy_CapSense_CSXStartSample(context);
+        }
+        /* Check whether all Rx are looped through */
+        else
+        {
+            ptrActive->rxIndex--;
+            if (ptrActive->rxIndex > 0u)
+            {
+                /* Disconnect the current Rx electrode and connect a next Rx electrode */
+                Cy_CapSense_CSXDisconnectRxExt(context);
+                ptrActive->ptrRxConfig++;
+                Cy_CapSense_CSXConnectRxExt(context);
+                /* Re-initialize Tx index to be scanned per Rx and connect the first Tx electrode again */
+                ptrActive->txIndex = ptrActive->ptrWdConfig->numRows;
+                ptrActive->ptrTxConfig = &ptrActive->ptrWdConfig->ptrEltdConfig[ptrActive->ptrWdConfig->numCols];
+                Cy_CapSense_CSXConnectTxExt(context);
+                /* Initiate a next scan */
+                Cy_CapSense_CSXSetUpIdacs(context);
+                Cy_CapSense_CSXStartSample(context);
+            }
+            else
+            {
+                /* If all the sensors are scanned, disconnect the last Rx electrode */
+                Cy_CapSense_CSXDisconnectRxExt(context);
+                ptrActive->connectedSnsState = CY_CAPSENSE_SNS_DISCONNECTED;
+                /* Call scan of next widget if requested. If not, complete scan */
+                if (0u != (ptrActive->scanScope & CY_CAPSENSE_SCAN_SCOPE_ALL_WD_MASK))
+                {
+                    Cy_CapSense_SsPostAllWidgetsScan(context);
+                }
+                else
+                {
+                    /* All pending scans completed, clear busy state as scanning is completed  */
+                    Cy_CapSense_ClrBusyFlags(context);
+            }
+        }
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_SsCSXStartSampleExt
+****************************************************************************//**
+*
+* Starts the HW sequencer to perform the CSX conversion.
+*
+* This function covers the following functionality:
+* 1. Configures the HW sequencer to perform the coarse initialization.
+* 2. Waiting for completion of the coarse initialization.
+* 3. Configures the HW sequencer to perform the normal conversion.
+* 4. Starts the normal conversion
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+__STATIC_INLINE void Cy_CapSense_CSXStartSampleExt(cy_stc_capsense_context_t * context)
+{
+    uint32_t cpuFreqMHz;
+    uint32_t watchdogCounter;
+
+    /* Approximate duration of Wait For Init loop */
+    const uint32_t intrInitLoopDuration = 5uL;
+
+    /* Wait For Init watchdog timeout in microseconds */
+    const uint32_t initWatchdogTimeUs = CY_CAPSENSE_CSX_PRECHARGE_WATCHDOG_TIME_US;
+
+    /* Configure the HW sequencer to perform the coarse initialization. */
+    context->ptrCommonConfig->ptrCsdBase->CONFIG = context->ptrInternalContext->csxRegConfigInit;
+    context->ptrCommonConfig->ptrCsdBase->HSCMP = CY_CAPSENSE_PRECHARGE_CSD_HSCMP_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_P_SEL = CY_CAPSENSE_PRECHARGE_CSD_SW_HS_P_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_N_SEL = CY_CAPSENSE_PRECHARGE_CSD_SW_HS_N_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_DSI_SEL = CY_CAPSENSE_PRECHARGE_CSD_SW_DSI_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_SHIELD_SEL = CY_CAPSENSE_PRECHARGE_CSD_SW_SHIELD_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_MOD_SEL = CY_CAPSENSE_PRECHARGE_CSD_SW_FW_MOD_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_TANK_SEL = CY_CAPSENSE_PRECHARGE_CSD_SW_FW_TANK_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_RES = context->ptrInternalContext->csxRegSwResPrech;
+    context->ptrCommonConfig->ptrCsdBase->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 &
+        context->ptrCommonConfig->ptrCsdBase->SEQ_START)))
+    {
+        if(0uL == watchdogCounter)
+        {
+            break;
+        }
+
+        watchdogCounter--;
+    }
+
+
+    /* Reset the sequencer to the IDLE state if HSCMP not triggered till watchdog period is out. */
+    if(0u != (CY_CAPSENSE_CSD_SEQ_START_START_MSK & context->ptrCommonConfig->ptrCsdBase->SEQ_START))
+    {
+        context->ptrCommonConfig->ptrCsdBase->SEQ_START = CY_CAPSENSE_DEFAULT_CSD_SEQ_START_CFG;
+    }
+
+    /* Configure the HW sequencer to perform the normal conversion. */
+    context->ptrCommonConfig->ptrCsdBase->CONFIG = context->ptrInternalContext->csxRegConfigScan;
+    context->ptrCommonConfig->ptrCsdBase->CSDCMP = CY_CAPSENSE_PRESCAN_CSD_CSDCMP_CFG;
+    context->ptrCommonConfig->ptrCsdBase->HSCMP = CY_CAPSENSE_DEFAULT_CSD_HSCMP_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_P_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_HS_P_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_HS_N_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_HS_N_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_DSI_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_DSI_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_SHIELD_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_SHIELD_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_MOD_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_FW_MOD_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_FW_TANK_SEL = CY_CAPSENSE_DEFAULT_CSD_SW_FW_TANK_SEL_CFG;
+    context->ptrCommonConfig->ptrCsdBase->SW_RES = context->ptrInternalContext->csxRegSwResScan;
+
+    /* Clear all pending interrupts of the CSD HW block */
+    context->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)context->ptrCommonConfig->ptrCsdBase->INTR;
+
+    /* Start the normal conversion */
+    context->ptrCommonConfig->ptrCsdBase->SEQ_START = CY_CAPSENSE_SCAN_CSD_SEQ_START_CFG;
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXInitNextChScan
+****************************************************************************//**
+*
+* This function initializes the next frequency of the sensor scan.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+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;
+
+        Cy_CapSense_CSXSetSnsClkFreq((uint32_t)ptrActive->mfsChannelIndex, context);
+        Cy_CapSense_CSXConnectTxExt(context);
+        Cy_CapSense_CSXSetUpIdacs(context);
+        Cy_CapSense_CSXStartSample(context);
+}
+#endif
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CSXSetSnsClkFreq
+****************************************************************************//**
+*
+* Calculates sensor frequency depending on the specified frequency channel
+* and configures the CSD HW block. If the multi-frequency scan feature is
+* disabled, the function sets the snsClk divider and clock source
+* from the active widget context structure.
+*
+* \param channelIndex
+* Specifies frequency index.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_CSXSetSnsClkFreq(uint32_t channelIndex, cy_stc_capsense_context_t * context)
+{
+    uint32_t tmpRegVal;
+    uint32_t snsClkDivider;
+
+    /* SnsClk setup */
+    snsClkDivider = (uint32_t) context->ptrActiveScanSns->ptrWdContext->snsClk;
+
+    /* Check divider value */
+    if (0u == snsClkDivider)
+    {
+        snsClkDivider = 1u;
+    }
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        /* Change the divider based on the chId */
+        switch (channelIndex)
+        {
+            case CY_CAPSENSE_MFS_CH1_INDEX:
+                snsClkDivider += context->ptrCommonConfig->csxMfsDividerOffsetF1;
+                break;
+
+            case CY_CAPSENSE_MFS_CH2_INDEX:
+                snsClkDivider += context->ptrCommonConfig->csxMfsDividerOffsetF2;
+                break;
+
+            default:
+                /* No action for other indexes */
+                break;
+
+        }
+    #else
+        (void) channelIndex;
+    #endif
+
+    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);
+    /* Update reg value with divider and configuration */
+    context->ptrCommonConfig->ptrCsdBase->SENSE_PERIOD = tmpRegVal;
+
+}
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2)) */
+
+
+/* [] END OF FILE */

+ 207 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_csx_v2.h

@@ -0,0 +1,207 @@
+/***************************************************************************//**
+* \file cy_capsense_csx_v2.h
+* \version 3.0
+*
+* \brief
+* This file provides the function prototypes specific to the CSX sensing
+* implementation.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_CSX_V2_H)
+#define CY_CAPSENSE_CSX_V2_H
+
+#include "cy_syslib.h"
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_common.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN)
+    cy_capsense_status_t Cy_CapSense_CSXCalibrateWidget(uint32_t widgetId, uint32_t target, cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CALIBRATION_EN) */
+
+void Cy_CapSense_CSXSetupWidget(uint32_t widgetId, cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSXSetupWidgetExt(uint32_t widgetId, uint32_t sensorId, cy_stc_capsense_context_t * context);
+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, 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);
+
+void Cy_CapSense_CSXConnectRxExt(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSXConnectTxExt(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);
+void Cy_CapSense_CSXInitialize(cy_stc_capsense_context_t * context);
+void Cy_CapSense_CSXElectrodeCheck(cy_stc_capsense_context_t * context);
+
+void Cy_CapSense_CSXSetWidgetTxClkSrc(const cy_stc_capsense_widget_config_t * ptrWdConfig);
+
+void Cy_CapSense_CSXScanISR(void * capsenseContext);
+
+/** \} \endcond */
+
+/*******************************************************************************
+* Local definition
+*******************************************************************************/
+#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)
+
+
+/*******************************************************************************
+* 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 PSoC&trade; 4 devices in case if VDDA >= 2V */
+#define CY_CAPSENSE_DEFAULT_CSD_REFGEN_CFG                  (0x00001F41u)
+/* Intended to be used for PSoC&trade; 4 devices in case if VDDA < 2V */
+#define CY_CAPSENSE_LOW_VOLTAGE_CSD_REFGEN_CFG              (0x00800011u)
+/* Intended to be used for PSoC&trade; 6 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 PSoC&trade; 6 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_FOURTH_GEN)
+    #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_FOURTH_GEN)
+    #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_FOURTH_GEN)
+    #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_FOURTH_GEN)
+    #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_FOURTH_GEN)
+    #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_FOURTH_GEN)
+    #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_FOURTH_GEN)
+    #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_FOURTH_GEN)
+    #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_FOURTH_GEN)
+    #define CY_CAPSENSE_SCAN_CSD_SW_FW_TANK_SEL_CFG         (0x00000000u)
+#else
+    #define CY_CAPSENSE_SCAN_CSD_SW_FW_TANK_SEL_CFG         (0x00002210u)
+#endif
+
+#define CY_CAPSENSE_SCAN_CSD_SEQ_START_CFG                  (0x00000301u)
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2)) */
+
+#endif  /* CY_CAPSENSE_CSX_V2_H */
+
+
+/* [] END OF FILE */

+ 1006 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_filter.c

@@ -0,0 +1,1006 @@
+/***************************************************************************//**
+* \file cy_capsense_filter.c
+* \version 3.0
+*
+* \brief
+* This file contains the source code of all filters implementation.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include <stddef.h>
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_filter.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_lib.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+
+/*******************************************************************************
+* Local definition
+*******************************************************************************/
+#define CY_CAPSENSE_IIR_BL_SHIFT                                (8u)
+
+#define CY_CAPSENSE_IIR_SHIFT_STANDARD                          (0u)
+#define CY_CAPSENSE_IIR_SHIFT_PERFORMANCE                       (8u)
+
+#define CY_CAPSENSE_RC_MEDIAN_SIZE                              (2u)
+#define CY_CAPSENSE_RC_IIR_SIZE                                 (1u)
+#define CY_CAPSENSE_RC_AVG_SIZE                                 (3u)
+
+/* IIR filter constant */
+#define CY_CAPSENSE_IIR_COEFFICIENT_K                           (256u)
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+static cy_capsense_status_t Cy_CapSense_CheckBaselineInv(
+                cy_stc_capsense_widget_context_t * ptrWdContext,
+                const cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                const uint16_t * ptrSnsBslnInv,
+                const cy_stc_capsense_context_t * context);
+
+/** \} \endcond */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_UpdateAllBaselines
+****************************************************************************//**
+*
+* Updates the baseline for all the sensors in all the widgets.
+*
+* Baselines must be updated after sensor scan to ignore low frequency
+* changes in the sensor data caused by environment changes such as
+* temperature from sensor status decision.
+*
+* This function ignores the widget enable bit in the widget status register.
+* Calling this function multiple times without a new sensor scan leads to
+* unexpected behavior and should be avoided.
+*
+* This function is called by Cy_CapSense_ProcessAllWidgets() and
+* Cy_CapSense_ProcessWidget(), hence the application program need not use this
+* function if any of the above functions is already used. This function can be
+* used for custom application implementation.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the update baseline operation of all the widgets:
+* - CY_CAPSENSE_STATUS_SUCCESS  - The operation is successfully completed.
+* - CY_CAPSENSE_STATUS_BAD_DATA - The baseline processing failed.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_UpdateAllBaselines(
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t wdIndex;
+    cy_capsense_status_t bslnStatus = CY_CAPSENSE_STATUS_SUCCESS;
+
+    for(wdIndex = context->ptrCommonConfig->numWd; wdIndex-- > 0u;)
+    {
+        bslnStatus |= Cy_CapSense_UpdateWidgetBaseline(wdIndex, context);
+    }
+
+    return(bslnStatus);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_UpdateWidgetBaseline
+****************************************************************************//**
+*
+* Updates the baselines for all the sensors in a widget specified by
+* the input parameter.
+*
+* This function performs exactly the same tasks as
+* Cy_CapSense_UpdateAllBaselines() but only for a specified widget.
+*
+* Calling this function multiple times without a new sensor scan leads to
+* unexpected behavior and should be avoided. The application program need
+* not use this function if the Cy_CapSense_UpdateAllBaselines(),
+* Cy_CapSense_ProcessAllWidgets() or Cy_CapSense_ProcessWidget() functions
+* are already used.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the specified widget update baseline operation:
+* - CY_CAPSENSE_STATUS_SUCCESS - The operation is successfully completed.
+* - CY_CAPSENSE_STATUS_BAD_DATA - The baseline processing failed.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_UpdateWidgetBaseline(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+    cy_capsense_status_t bslnStatus = CY_CAPSENSE_STATUS_SUCCESS;
+
+    for(snsIndex = context->ptrWdConfig[widgetId].numSns; snsIndex-- > 0u;)
+    {
+        bslnStatus |= Cy_CapSense_UpdateSensorBaseline(widgetId, snsIndex, context);
+    }
+
+    return(bslnStatus);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_UpdateSensorBaseline
+****************************************************************************//**
+*
+* Updates the baseline for a sensor in a widget specified by the
+* input parameters.
+*
+* This function performs exactly the same tasks as
+* Cy_CapSense_UpdateAllBaselines() and Cy_CapSense_UpdateWidgetBaseline()
+* but only for a specified sensor.
+*
+* Calling this function multiple times without a new sensor scan leads to
+* unexpected behavior and should be avoided. The application need not use
+* this function if the Cy_CapSense_UpdateWidgetBaseline (),
+* Cy_CapSense_UpdateAllBaselines (), Cy_CapSense_ProcessAllWidgets(),
+* or Cy_CapSense_ProcessWidget() functions are already used.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* file defined as CY_CAPSENSE_<WIDGET_NAME>_SNS<SENSOR_NUMBER>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the specified sensor update baseline operation:
+* - CY_CAPSENSE_STATUS_SUCCESS - The operation is successfully completed.
+* - CY_CAPSENSE_STATUS_BAD_DATA - The baseline processing failed.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_UpdateSensorBaseline(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                const cy_stc_capsense_context_t * context)
+{
+    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, ptrSnsCxt, &ptrWdCfg->ptrBslnInv[sensorId], context);
+
+    return (result);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckBaselineInv
+****************************************************************************//**
+*
+* Check a matching of present baseline and its inverse duplication.
+*
+* \param ptrWdContext
+* The pointer to the widget context structure where all the widget parameters
+* are stored.
+*
+* \param ptrSnsContext
+* 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status indicating check result:
+* - CY_CAPSENSE_STATUS_SUCCESS -  if the BIST baseline integrity test is enabled and
+*                                 baseline and its inverse duplication match or BIST
+*                                 baseline integrity test is disabled.
+* - CY_CAPSENSE_STATUS_BAD_DATA - if the BIST baseline integrity test is enabled and
+*                                 the sensor's baseline and its inversion doesn't
+*                                 match. In this case the function as well clears
+*                                 the bit[2] (Widget Working) of the .status field
+*                                 in the widget context structure preventing corrupted
+*                                 data usage and set the CY_CAPSENSE_BIST_BSLN_INTEGRITY_MASK
+*                                 bit of the .testResultMask field
+*                                 in the /ref cy_stc_capsense_bist_context_t structure.
+*
+*******************************************************************************/
+static cy_capsense_status_t Cy_CapSense_CheckBaselineInv(
+                cy_stc_capsense_widget_context_t * ptrWdContext,
+                const cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                const uint16_t * ptrSnsBslnInv,
+                const cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t result = CY_CAPSENSE_STATUS_SUCCESS;
+
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) &&\
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN))
+        uint16_t bslnInv = (uint16_t)(~ptrSnsContext->bsln);
+
+        if (*ptrSnsBslnInv != bslnInv)
+        {
+            result = CY_CAPSENSE_STATUS_BAD_DATA;
+            ptrWdContext->status &= (uint8_t)~CY_CAPSENSE_WD_WORKING_MASK;
+            context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_BSLN_INTEGRITY_MASK;
+        }
+    #else
+        (void) ptrWdContext;
+        (void) ptrSnsContext;
+        (void) ptrSnsBslnInv;
+        (void) context;
+    #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) &&\
+               (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)) */
+
+    return result;
+}
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_FtUpdateBaseline
+****************************************************************************//**
+*
+* Updates the baseline for a sensor specified by an input parameter.
+*
+* Check a matching of present baseline and its inverse duplication. If they
+* match, then the function updates the baseline for a sensor specified by an input parameter.
+* If they don't match, the function returns CY_CAPSENSE_TST_BSLN_DUPLICATION
+* result and doesn't update the baseline.
+*
+* \param ptrWdContext
+* The pointer to the widget context structure where all the widget parameters
+* are stored.
+*
+* \param ptrSnsContext
+* 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status indicating whether the baseline has been updated:
+* - CY_CAPSENSE_STATUS_SUCCESS - if baseline updating was successful.
+* - CY_CAPSENSE_STATUS_BAD_DATA - if the BIST baseline integrity test is enabled and
+*                                 the sensor's baseline and its inversion doesn't
+*                                 match. In this case the function as well clears
+*                                 the bit[2] (Widget Working) of the .status field
+*                                 in the widget context structure preventing corrupted
+*                                 data usage and set the CY_CAPSENSE_BIST_BSLN_INTEGRITY_MASK
+*                                 bit of the .testResultMask field
+*                                 in the /ref cy_stc_capsense_bist_context_t structure.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_FtUpdateBaseline(
+                cy_stc_capsense_widget_context_t * ptrWdContext,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsBslnInv,
+                const cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t result;
+    uint32_t bslnHistory;
+
+    result = Cy_CapSense_CheckBaselineInv(ptrWdContext, ptrSnsContext, ptrSnsBslnInv, context);
+
+    if (CY_CAPSENSE_STATUS_SUCCESS == result)
+    {
+        /* Reset negative baseline counter */
+        if(ptrSnsContext->raw >= ptrSnsContext->bsln)
+        {
+            ptrSnsContext->negBslnRstCnt = 0u;
+        }
+
+        /* Reset baseline */
+        if ((uint32_t)ptrSnsContext->bsln > ((uint32_t)ptrWdContext->nNoiseTh + ptrSnsContext->raw))
+        {
+            if (ptrSnsContext->negBslnRstCnt >= ptrWdContext->lowBslnRst)
+            {
+                Cy_CapSense_FtInitializeBaseline(ptrSnsContext);
+            }
+            else
+            {
+                ptrSnsContext->negBslnRstCnt++;
+            }
+        }
+        else
+        {
+            /*
+            * Update baseline only if:
+            * - signal is in range between noiseThreshold and negativenoiseThreshold
+            * or
+            * - sensor Auto-reset is enabled
+            */
+            if ((0u != context->ptrCommonConfig->swSensorAutoResetEn) ||
+                ((uint32_t)ptrSnsContext->raw <= ((uint32_t)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 = (uint16_t)(bslnHistory >> CY_CAPSENSE_IIR_BL_SHIFT);
+                ptrSnsContext->bslnExt = (uint8_t)(bslnHistory);
+            }
+        }
+        /* If BIST enabled, update the baseline inverse duplication */
+        #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) &&\
+             (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN))
+            *ptrSnsBslnInv = ~ptrSnsContext->bsln;
+        #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) &&\
+                   (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)) */
+    }
+    return result;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeAllBaselines
+****************************************************************************//**
+*
+* Initializes the baselines of all the sensors of all the widgets.
+*
+* This function initializes baselines for all sensors and widgets in the project.
+* It can also be used to re-initialize baselines at any time, however, note
+* that all sensor data history information and sensor status shall be reset
+* along with re-initialization of baseline.
+*
+* Following functions to initialize sensor and widgets and filter history
+* should be called after initializing baseline for proper operation of
+* the CAPSENSE&trade; middleware:
+* * Cy_CapSense_InitializeAllStatuses()
+* * Cy_CapSense_InitializeAllFilters()
+*
+* These functions are called by the CapSense_Enable() function, hence it is
+* not required to use this function if above function is used.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeAllBaselines(cy_stc_capsense_context_t * context)
+{
+    uint32_t wdIndex;
+
+    for(wdIndex = context->ptrCommonConfig->numWd; wdIndex-- > 0u;)
+    {
+        Cy_CapSense_InitializeWidgetBaseline(wdIndex, context);
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeWidgetBaseline
+****************************************************************************//**
+*
+* Initializes the baselines of all the sensors in a specific widget.
+*
+* This function initializes baselines for all sensors in a specific widget
+* in the project. It can also be used to re-initialize baselines at any time,
+* however, note that all sensor data history information and sensor status
+* should be reset along with re-initialization of baseline.
+*
+* The following functions to initialize sensor and widgets and filter history
+* should be called after initializing baselines for proper operation of
+* middleware.
+* * Cy_CapSense_InitializeWidgetStatus()
+* * Cy_CapSense_InitializeWidgetFilter()
+*
+* These functions are called by CapSense_Enable() function, hence it is not
+* required to use this function is above function is used.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeWidgetBaseline(
+                uint32_t widgetId,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+
+    for(snsIndex = context->ptrWdConfig[widgetId].numSns; snsIndex-- > 0u;)
+    {
+        Cy_CapSense_InitializeSensorBaseline(widgetId, snsIndex, context);
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeSensorBaseline
+****************************************************************************//**
+*
+* Initializes the baseline of a sensor in a widget specified
+* by the input parameters.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param sensorId
+* Specifies the ID number of the sensor within the widget. A macro for the
+* sensor ID within a specified widget can be found in the cycfg_capsense.h
+* file defined as CY_CAPSENSE_<WIDGET_NAME>_SNS<SENSOR_NUMBER>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeSensorBaseline(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t cxtOffset;
+    uint32_t freqChIndex;
+    for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+    {
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+            cxtOffset = sensorId + (freqChIndex * context->ptrCommonConfig->numSns);
+        #else
+            cxtOffset = sensorId;
+        #endif
+        Cy_CapSense_FtInitializeBaseline(&context->ptrWdConfig[widgetId].ptrSnsContext[cxtOffset]);
+        /* If BIST enabled, create a baseline inverse duplication */
+        #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) &&\
+                (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN))
+            context->ptrWdConfig[widgetId].ptrBslnInv[cxtOffset] =
+                                            ~context->ptrWdConfig[widgetId].ptrSnsContext[cxtOffset].bsln;
+        #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) &&\
+                    (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)) */
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_FtInitializeBaseline
+****************************************************************************//**
+*
+* Initializes the baseline history for a sensor indicated by an input
+* parameter.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+*******************************************************************************/
+void Cy_CapSense_FtInitializeBaseline(cy_stc_capsense_sensor_context_t * ptrSnsContext)
+{
+    ptrSnsContext->bslnExt = 0u;
+    ptrSnsContext->bsln = ptrSnsContext->raw;
+    ptrSnsContext->negBslnRstCnt = 0u;
+}
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeAllFilters
+****************************************************************************//**
+*
+* Initializes (or re-initializes) all the firmware filter history, except
+* the baseline.
+*
+* Calling this function is accompanied by
+* * Cy_CapSense_InitializeAllStatuses()
+* * Cy_CapSense_InitializeAllBaselines()
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeAllFilters(const cy_stc_capsense_context_t * context)
+{
+    uint32_t widgetId;
+
+    for(widgetId = context->ptrCommonConfig->numWd; widgetId-- > 0u;)
+    {
+        Cy_CapSense_InitializeWidgetFilter(widgetId, context);
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeWidgetFilter
+****************************************************************************//**
+*
+* Initializes (or re-initializes) the raw count filter history of all
+* the sensors in a widget specified by the input parameter.
+*
+* Calling this function is accompanied by
+* - Cy_CapSense_InitializeWidgetStatus().
+* - Cy_CapSense_InitializeWidgetBaseline().
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeWidgetFilter(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+    uint32_t freqChIndex;
+    uint32_t snsHistorySize;
+    uint32_t historyOffset;
+
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+
+    uint32_t rawFilterCfg = ptrWdCfg->rawFilterConfig;
+    uint16_t * ptrHistory;
+    const cy_stc_capsense_sensor_context_t * ptrSnsCtx ;
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN)
+        cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNEHistory;
+    #endif
+    #if (CY_CAPSENSE_REGULAR_RC_IIR_FILTER_EN || CY_CAPSENSE_PROX_RC_IIR_FILTER_EN)
+        uint8_t * ptrHistoryLow = NULL;
+    #endif
+
+    snsHistorySize = (uint32_t)ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_MASK;
+    for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+    {
+        for(snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
+        {
+            ptrSnsCtx = &ptrWdCfg->ptrSnsContext[snsIndex + (freqChIndex * context->ptrCommonConfig->numSns)];
+            historyOffset = (freqChIndex * (CY_CAPSENSE_RAW_HISTORY_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)) + (snsHistorySize * snsIndex);
+            ptrHistory = &ptrWdCfg->ptrRawFilterHistory[historyOffset];
+
+            #if (CY_CAPSENSE_REGULAR_RC_MEDIAN_FILTER_EN || CY_CAPSENSE_PROX_RC_MEDIAN_FILTER_EN)
+                if(0u != (CY_CAPSENSE_RC_FILTER_MEDIAN_EN_MASK & rawFilterCfg))
+                {
+                    Cy_CapSense_InitializeMedianInternal(ptrWdCfg, ptrSnsCtx, ptrHistory);
+                    ptrHistory += CY_CAPSENSE_RC_MEDIAN_SIZE;
+                }
+            #endif
+
+            #if (CY_CAPSENSE_REGULAR_RC_IIR_FILTER_EN || CY_CAPSENSE_PROX_RC_IIR_FILTER_EN)
+            if(0u != (CY_CAPSENSE_RC_FILTER_IIR_EN_MASK & rawFilterCfg))
+            {
+                if(CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
+                {
+                    ptrHistoryLow = &ptrWdCfg->ptrRawFilterHistoryLow[snsIndex +
+                            (freqChIndex * (CY_CAPSENSE_IIR_HISTORY_LOW_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM))];
+                }
+                Cy_CapSense_InitializeIIRInternal(ptrWdCfg, ptrSnsCtx, ptrHistory, ptrHistoryLow);
+                ptrHistory += CY_CAPSENSE_RC_IIR_SIZE;
+            }
+            #endif
+
+            #if (CY_CAPSENSE_REGULAR_RC_AVERAGE_FILTER_EN || CY_CAPSENSE_PROX_RC_AVERAGE_FILTER_EN)
+            if(0u != (CY_CAPSENSE_RC_FILTER_AVERAGE_EN_MASK & rawFilterCfg))
+            {
+                Cy_CapSense_InitializeAverageInternal(ptrWdCfg, ptrSnsCtx, ptrHistory);
+            }
+            #endif
+        }
+    }
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN)
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+        /* Noise envelope is available for CSD widgets only */
+        if (CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod)
+        {
+            ptrSnsCtx = ptrWdCfg->ptrSnsContext;
+            ptrNEHistory = ptrWdCfg->ptrNoiseEnvelope;
+            for(snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
+            {
+                Cy_CapSense_InitializeNoiseEnvelope_Lib(ptrSnsCtx->raw,
+                        ptrWdCfg->ptrWdContext->sigPFC, ptrNEHistory);
+                ptrSnsCtx++;
+                ptrNEHistory++;
+            }
+        }
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+    #endif
+}
+#endif /*(CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)*/
+
+#if (CY_CAPSENSE_REGULAR_RC_IIR_FILTER_EN || CY_CAPSENSE_PROX_RC_IIR_FILTER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeIIRInternal
+****************************************************************************//**
+*
+* Initializes the IIR filter history.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+* \param ptrSnsRawHistory
+* The pointer to the filter history of the sensor.
+*
+* \param ptrSnsRawHistoryLow
+* The pointer to the extended filter history of the sensor.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeIIRInternal(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                const cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory,
+                uint8_t * ptrSnsRawHistoryLow)
+{
+    ptrSnsRawHistory[0u] = ptrSnsContext->raw;
+
+    if ((NULL != ptrSnsRawHistoryLow) &&
+       (CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdConfig->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK)))
+    {
+        ptrSnsRawHistoryLow[0u] = 0u;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunIIRInternal
+****************************************************************************//**
+*
+* Runs the IIR filter.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+* \param ptrSnsRawHistory
+* The pointer to the filter history of the sensor.
+*
+* \param ptrSnsRawHistoryLow
+* The pointer to the extended filter history of the sensor.
+*
+*******************************************************************************/
+void Cy_CapSense_RunIIRInternal(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory,
+                uint8_t * ptrSnsRawHistoryLow)
+{
+    uint32_t tempHistory;
+    uint32_t tempRaw;
+
+    if(CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdConfig->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
+    {
+        tempRaw = ((uint32_t)ptrSnsContext->raw) << CY_CAPSENSE_IIR_SHIFT_PERFORMANCE;
+        tempHistory  = ((uint32_t)(*ptrSnsRawHistory)) << CY_CAPSENSE_IIR_SHIFT_PERFORMANCE;
+        tempHistory |= (uint32_t)(*ptrSnsRawHistoryLow);
+        tempRaw = Cy_CapSense_FtIIR1stOrder(tempRaw, tempHistory, ptrWdConfig->iirCoeff);
+        *ptrSnsRawHistory = (uint16_t)(tempRaw >> CY_CAPSENSE_IIR_SHIFT_PERFORMANCE);
+        *ptrSnsRawHistoryLow = (uint8_t)(tempRaw);
+        ptrSnsContext->raw = (uint16_t)(tempRaw >> CY_CAPSENSE_IIR_SHIFT_PERFORMANCE);
+    }
+    else
+    {
+        tempRaw = Cy_CapSense_FtIIR1stOrder((uint32_t)ptrSnsContext->raw, (uint32_t)(*ptrSnsRawHistory), ptrWdConfig->iirCoeff);
+        *ptrSnsRawHistory = (uint16_t)(tempRaw);
+        ptrSnsContext->raw = *ptrSnsRawHistory;
+    }
+}
+#endif /* (CY_CAPSENSE_REGULAR_RC_IIR_FILTER_EN || CY_CAPSENSE_PROX_RC_IIR_FILTER_EN) */
+
+#if (CY_CAPSENSE_REGULAR_RC_MEDIAN_FILTER_EN || CY_CAPSENSE_PROX_RC_MEDIAN_FILTER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeMedianInternal
+****************************************************************************//**
+*
+* Initializes the median filter.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+* \param ptrSnsRawHistory
+* The pointer to the filter history of the sensor.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeMedianInternal(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                const cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory)
+{
+    (void)ptrWdConfig;
+
+    ptrSnsRawHistory[0u] = ptrSnsContext->raw;
+    ptrSnsRawHistory[1u] = ptrSnsContext->raw;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunMedianInternal
+****************************************************************************//**
+*
+* Runs the median filter.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+* \param ptrSnsRawHistory
+* The pointer to the filter history of the sensor.
+*
+*******************************************************************************/
+void Cy_CapSense_RunMedianInternal(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory)
+{
+    uint32_t temp = Cy_CapSense_FtMedian(
+                    (uint32_t)ptrSnsContext->raw,
+                    (uint32_t)ptrSnsRawHistory[0u],
+                    (uint32_t)ptrSnsRawHistory[1u]);
+
+    (void)ptrWdConfig;
+
+    ptrSnsRawHistory[1u] = ptrSnsRawHistory[0u];
+    ptrSnsRawHistory[0u] = ptrSnsContext->raw;
+    ptrSnsContext->raw = (uint16_t)(temp);
+}
+#endif /* (CY_CAPSENSE_REGULAR_RC_MEDIAN_FILTER_EN || CY_CAPSENSE_PROX_RC_MEDIAN_FILTER_EN) */
+
+#if (CY_CAPSENSE_REGULAR_RC_AVERAGE_FILTER_EN || CY_CAPSENSE_PROX_RC_AVERAGE_FILTER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeAverageInternal
+****************************************************************************//**
+*
+* Initializes the average filter.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+* \param ptrSnsRawHistory
+* The pointer to the filter history of the sensor.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeAverageInternal(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                const cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory)
+{
+    (void)ptrWdConfig;
+    ptrSnsRawHistory[0u] = ptrSnsContext->raw;
+    ptrSnsRawHistory[1u] = ptrSnsContext->raw;
+    ptrSnsRawHistory[2u] = ptrSnsContext->raw;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunAverageInternal
+****************************************************************************//**
+*
+* Runs the average filter.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+* \param ptrSnsRawHistory
+* The pointer to the filter history of the sensor.
+*
+*******************************************************************************/
+void Cy_CapSense_RunAverageInternal(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory)
+{
+    uint32_t temp;
+
+    if(CY_CAPSENSE_AVERAGE_FILTER_LEN_4 == (ptrWdConfig->rawFilterConfig & CY_CAPSENSE_RC_FILTER_AVERAGE_MODE_MASK))
+    {
+        temp = ((uint32_t)ptrSnsContext->raw + ptrSnsRawHistory[0u] + ptrSnsRawHistory[1u] + ptrSnsRawHistory[2u]) >> 2u;
+        ptrSnsRawHistory[2u] = ptrSnsRawHistory[1u];
+        ptrSnsRawHistory[1u] = ptrSnsRawHistory[0u];
+    }
+    else
+    {
+        temp = ((uint32_t)ptrSnsContext->raw + ptrSnsRawHistory[0u]) >> 1u;
+    }
+    ptrSnsRawHistory[0u] = ptrSnsContext->raw;
+    ptrSnsContext->raw = (uint16_t)(temp);
+}
+#endif /* (CY_CAPSENSE_REGULAR_RC_AVERAGE_FILTER_EN || CY_CAPSENSE_PROX_RC_AVERAGE_FILTER_EN) */
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_FtRunEnabledFiltersInternal
+****************************************************************************//**
+*
+* Runs all enabled filters.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+* \param ptrSnsRawHistory
+* The pointer to the filter history of the sensor.
+*
+* \param ptrSnsRawHistoryLow
+* The pointer to the extended filter history of the sensor.
+*
+*******************************************************************************/
+void Cy_CapSense_FtRunEnabledFiltersInternal(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory,
+                uint8_t * ptrSnsRawHistoryLow)
+{
+    uint16_t rawFilterCfg;
+    rawFilterCfg = ptrWdConfig->rawFilterConfig;
+    uint16_t * ptrSnsRawHistoryLocal = ptrSnsRawHistory;
+
+    #if (CY_CAPSENSE_REGULAR_RC_MEDIAN_FILTER_EN || CY_CAPSENSE_PROX_RC_MEDIAN_FILTER_EN)
+        if(0u != (CY_CAPSENSE_RC_FILTER_MEDIAN_EN_MASK & rawFilterCfg))
+        {
+            Cy_CapSense_RunMedianInternal(ptrWdConfig, ptrSnsContext, ptrSnsRawHistoryLocal);
+            ptrSnsRawHistoryLocal += CY_CAPSENSE_RC_MEDIAN_SIZE;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_REGULAR_RC_IIR_FILTER_EN || CY_CAPSENSE_PROX_RC_IIR_FILTER_EN)
+        if(0u != (CY_CAPSENSE_RC_FILTER_IIR_EN_MASK & rawFilterCfg))
+        {
+            Cy_CapSense_RunIIRInternal(ptrWdConfig, ptrSnsContext, ptrSnsRawHistoryLocal, ptrSnsRawHistoryLow);
+            ptrSnsRawHistoryLocal += CY_CAPSENSE_RC_IIR_SIZE;
+        }
+    #else
+        (void)ptrSnsRawHistoryLow;
+    #endif
+
+    #if (CY_CAPSENSE_REGULAR_RC_AVERAGE_FILTER_EN || CY_CAPSENSE_PROX_RC_AVERAGE_FILTER_EN)
+        if(0u != (CY_CAPSENSE_RC_FILTER_AVERAGE_EN_MASK & rawFilterCfg))
+        {
+            Cy_CapSense_RunAverageInternal(ptrWdConfig, ptrSnsContext, ptrSnsRawHistoryLocal);
+        }
+    #endif
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN) */
+
+#if (CY_CAPSENSE_POS_MEDIAN_FILTER_EN || CY_CAPSENSE_REGULAR_RC_MEDIAN_FILTER_EN \
+    || CY_CAPSENSE_PROX_RC_MEDIAN_FILTER_EN || CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN || CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_FtMedian
+****************************************************************************//**
+*
+* Returns the median value from the three passed arguments.
+*
+* \param x1
+* The first value to be compared.
+*
+* \param x2
+* The second value to be compared.
+*
+* \param x3
+* The third value to be compared.
+*
+* \return
+* Returns the median value of input arguments.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_FtMedian(uint32_t x1, uint32_t x2, uint32_t x3)
+{
+    uint32_t tmp;
+    uint32_t x1Local = x1;
+    uint32_t x2Local = x2;
+
+    if (x1Local > x2Local)
+    {
+        tmp = x2Local;
+        x2Local = x1Local;
+        x1Local = tmp;
+    }
+
+    if (x2Local > x3)
+    {
+        x2Local = x3;
+    }
+
+    return ((x1Local > x2Local) ? x1Local : x2Local);
+}
+#endif /*#if (CY_CAPSENSE_POS_MEDIAN_FILTER_EN || CY_CAPSENSE_REGULAR_RC_MEDIAN_FILTER_EN \
+    || CY_CAPSENSE_PROX_RC_MEDIAN_FILTER_EN || CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)*/
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_FtIIR1stOrder
+****************************************************************************//**
+*
+* Returns the filtered data by the IIR 1-st order algorithm
+*
+* \param input
+* The data to be filtered.
+*
+* \param prevOutput
+* The previous filtered data.
+*
+* \param n
+* The IIR filter coefficient (n/256).
+*
+* \return
+* Returns the filtered data.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_FtIIR1stOrder(uint32_t input, uint32_t prevOutput, uint32_t n)
+{
+    uint32_t filteredOutput;
+
+    filteredOutput = ((n * input) + ((CY_CAPSENSE_IIR_COEFFICIENT_K - n) * prevOutput)) >> 8u;
+
+    return filteredOutput;
+}
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_JITTER_FILTER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_FtJitter
+****************************************************************************//**
+*
+* Returns the filtered data by the jitter algorithm.
+*
+* \param input
+* The data to be filtered.
+*
+* \param prevOutput
+* The previous filtered data.
+*
+* \return
+* Returns the filtered data.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_FtJitter(uint32_t input, uint32_t prevOutput)
+{
+    uint32_t inputLocal = input;
+
+    if (prevOutput > inputLocal)
+    {
+        inputLocal++;
+    }
+    else if (prevOutput < inputLocal)
+    {
+        inputLocal--;
+    }
+    else
+    {
+        /* No action, input equal to prevOutput */
+    }
+    return inputLocal;
+}
+#endif /*(CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_JITTER_FILTER_EN)*/
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+
+/* [] END OF FILE */

+ 143 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_filter.h

@@ -0,0 +1,143 @@
+/***************************************************************************//**
+* \file cy_capsense_filter.h
+* \version 3.0
+*
+* \brief
+* This file contains the definitions for all the filters implementation.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_FILTER_H)
+#define CY_CAPSENSE_FILTER_H
+
+#include "cy_syslib.h"
+
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_common.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/***************************************
+* Function Prototypes
+***************************************/
+
+/*******************************************************************************
+* LOW LEVEL FUNCTIONS
+*******************************************************************************/
+
+/******************************************************************************/
+/** \addtogroup group_capsense_low_level *//** \{ */
+/******************************************************************************/
+
+void Cy_CapSense_InitializeAllBaselines(cy_stc_capsense_context_t * context);
+void Cy_CapSense_InitializeWidgetBaseline(uint32_t widgetId, cy_stc_capsense_context_t * context);
+void Cy_CapSense_InitializeSensorBaseline(uint32_t widgetId, uint32_t sensorId, cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
+    void Cy_CapSense_InitializeAllFilters(const cy_stc_capsense_context_t * context);
+    void Cy_CapSense_InitializeWidgetFilter(uint32_t widgetId, const cy_stc_capsense_context_t * context);
+#endif
+
+cy_capsense_status_t Cy_CapSense_UpdateAllBaselines(const cy_stc_capsense_context_t * context);
+cy_capsense_status_t Cy_CapSense_UpdateWidgetBaseline(uint32_t widgetId, const cy_stc_capsense_context_t * context);
+cy_capsense_status_t Cy_CapSense_UpdateSensorBaseline(uint32_t widgetId, uint32_t sensorId, const cy_stc_capsense_context_t * context);
+
+/** \} */
+
+
+/*******************************************************************************
+* Function Prototypes - Internal functions
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+void Cy_CapSense_FtInitializeBaseline(
+                cy_stc_capsense_sensor_context_t * ptrSnsContext);
+cy_capsense_status_t Cy_CapSense_FtUpdateBaseline(
+                cy_stc_capsense_widget_context_t * ptrWdContext,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsBslnInv,
+                const cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_POS_MEDIAN_FILTER_EN || CY_CAPSENSE_REGULAR_RC_MEDIAN_FILTER_EN \
+    || CY_CAPSENSE_PROX_RC_MEDIAN_FILTER_EN || CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN || CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
+    uint32_t Cy_CapSense_FtMedian(uint32_t x1, uint32_t x2, uint32_t x3);
+#endif
+
+uint32_t Cy_CapSense_FtIIR1stOrder(uint32_t input, uint32_t prevOutput, uint32_t n);
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POS_JITTER_FILTER_EN)
+    uint32_t Cy_CapSense_FtJitter(uint32_t input, uint32_t prevOutput);
+#endif
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
+    void Cy_CapSense_FtRunEnabledFiltersInternal(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                    uint16_t * ptrSnsRawHistory,
+                    uint8_t * ptrSnsRawHistoryLow);
+#endif
+
+#if (CY_CAPSENSE_REGULAR_RC_IIR_FILTER_EN || CY_CAPSENSE_PROX_RC_IIR_FILTER_EN)
+    void Cy_CapSense_InitializeIIRInternal(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    const cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                    uint16_t * ptrSnsRawHistory,
+                    uint8_t * ptrSnsRawHistoryLow);
+    void Cy_CapSense_RunIIRInternal(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                    uint16_t * ptrSnsRawHistory,
+                    uint8_t * ptrSnsRawHistoryLow);
+#endif
+
+#if (CY_CAPSENSE_REGULAR_RC_MEDIAN_FILTER_EN || CY_CAPSENSE_PROX_RC_MEDIAN_FILTER_EN)
+    void Cy_CapSense_InitializeMedianInternal(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    const cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                    uint16_t * ptrSnsRawHistory);
+    void Cy_CapSense_RunMedianInternal(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                    uint16_t * ptrSnsRawHistory);
+#endif
+
+#if (CY_CAPSENSE_REGULAR_RC_AVERAGE_FILTER_EN || CY_CAPSENSE_PROX_RC_AVERAGE_FILTER_EN)
+    void Cy_CapSense_InitializeAverageInternal(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    const cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                    uint16_t * ptrSnsRawHistory);
+    void Cy_CapSense_RunAverageInternal(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                    uint16_t * ptrSnsRawHistory);
+#endif
+
+/** \} \endcond */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+#endif /* CY_CAPSENSE_FILTER_H */
+
+
+/* [] END OF FILE */

+ 1247 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_generator_v3.c

@@ -0,0 +1,1247 @@
+/***************************************************************************//**
+* \file cy_capsense_generator_v3.c
+* \version 3.0
+*
+* \brief
+* This file contains the source of functions common for register map
+* generator module.
+*
+********************************************************************************
+* \copyright
+* Copyright 2020-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include <string.h>
+#include "cycfg_capsense_defines.h"
+#include "cycfg_peripherals.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_sensing_v3.h"
+#include "cy_capsense_generator_v3.h"
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+    #include "cy_msc.h"
+#endif
+
+#if (defined(CY_IP_M0S8MSCV3))
+
+/*******************************************************************************
+* Internal function prototypes
+*******************************************************************************/
+#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+static void Cy_CapSense_GenerateCtrlMuxSwControl(
+                uint32_t chIndex,
+                cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+static void Cy_CapSense_ApplyShieldConfig(
+                cy_stc_msc_mode_config_t * ptrBaseCfgMode,
+                const cy_stc_capsense_context_t * context);
+#endif
+
+static void Cy_CapSense_ConfigSensorClock(
+                uint32_t scanSlot,
+                uint32_t * ptrSensorCfg,
+                const cy_stc_capsense_context_t * context);
+
+cy_capsense_status_t Cy_CapSense_GenerateSensorConfigValid(
+                uint32_t scanSlot,
+                uint32_t * ptrSensorCfg,
+                cy_stc_capsense_context_t * context);
+
+uint32_t Cy_CapSense_AdjustSnsClkDivider(
+                uint8_t snsMethod,
+                uint8_t snsClkSource,
+                uint16_t snsClkDivider);
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GenerateBaseConfig
+****************************************************************************//**
+*
+* Generates the configuration for all registers that have to be configured
+* one-time to initialize the MSC block.
+*
+* \param chIndex
+* The desired channel index.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the operation:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is performed successfully.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_GenerateBaseConfig(
+                uint32_t chIndex,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t i;
+    uint32_t snsMethod;
+    uint32_t idCounter;
+    uint8_t * ptrMapping;
+    uint32_t cdacDitherEnabled;
+    uint32_t snsMethodInternal;
+    cy_stc_capsense_internal_context_t * ptrIntrCxt = context->ptrInternalContext;
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        cy_stc_msc_mode_config_t * ptrBaseCfgMode;
+    #endif
+
+    const cy_stc_msc_base_config_t cy_capsense_smTemplate = CY_CAPSENSE_SENSING_METHOD_BASE_TEMPLATE;
+
+    cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_SUCCESS;
+
+    cy_stc_msc_base_config_t * ptrBaseCfg;
+    const cy_stc_msc_base_config_t * ptrTemplateCfg;
+    const cy_stc_msc_channel_config_t * ptrMscChConfig = &context->ptrCommonConfig->ptrMscChConfig[chIndex];
+
+    /*
+     * BASE CONFIGURATION
+     */
+    ptrBaseCfg = &context->ptrBaseFrameContext[chIndex];
+    ptrTemplateCfg = &cy_capsense_smTemplate;
+
+    /* Copies template of a base config */
+    ptrBaseCfg->ctl = ptrTemplateCfg->ctl;
+    if(context->ptrCommonContext->modClk > 1u)
+    {
+        ptrBaseCfg->ctl &= (~MSC_CTL_CLK_MSC_RATIO_Msk);
+    }
+    else
+    {
+        ptrBaseCfg->ctl |= MSC_CTL_CLK_MSC_RATIO_Msk;
+    }
+
+    ptrBaseCfg->spare = ptrTemplateCfg->spare;
+    ptrBaseCfg->scanCtl1 = ptrTemplateCfg->scanCtl1;
+    ptrBaseCfg->scanCtl2 = ptrTemplateCfg->scanCtl2;
+    ptrBaseCfg->initCtl1 = ptrTemplateCfg->initCtl1;
+    ptrBaseCfg->initCtl2 = ptrTemplateCfg->initCtl2;
+    ptrBaseCfg->initCtl3 = ptrTemplateCfg->initCtl3;
+    ptrBaseCfg->initCtl4 = ptrTemplateCfg->initCtl4;
+    ptrBaseCfg->senseDutyCtl = ptrTemplateCfg->senseDutyCtl;
+    ptrBaseCfg->sensePeriodCtl = ptrTemplateCfg->sensePeriodCtl;
+    ptrBaseCfg->filterCtl = ptrTemplateCfg->filterCtl;
+    ptrBaseCfg->ccompCdacCtl = ptrTemplateCfg->ccompCdacCtl;
+    ptrBaseCfg->ditherCdacCtl = ptrTemplateCfg->ditherCdacCtl;
+    ptrBaseCfg->cswCtl = ptrTemplateCfg->cswCtl;
+    ptrBaseCfg->swSelGpio = ptrTemplateCfg->swSelGpio;
+    ptrBaseCfg->swSelCdacRe = ptrTemplateCfg->swSelCdacRe;
+    ptrBaseCfg->swSelCdacCo = ptrTemplateCfg->swSelCdacCo;
+    ptrBaseCfg->swSelCdacCf = ptrTemplateCfg->swSelCdacCf;
+    ptrBaseCfg->swSelCmod1 = ptrTemplateCfg->swSelCmod1;
+    ptrBaseCfg->swSelCmod2 = ptrTemplateCfg->swSelCmod2;
+    ptrBaseCfg->swSelCmod3 = ptrTemplateCfg->swSelCmod3;
+    ptrBaseCfg->swSelCmod4 = ptrTemplateCfg->swSelCmod4;
+
+    if((CY_CAPSENSE_MSC0_CMOD1PADD_PIN != ptrMscChConfig->pinCmod1) &&
+       (CY_CAPSENSE_MSC1_CMOD1PADD_PIN != ptrMscChConfig->pinCmod1))
+    {
+        ptrBaseCfg->swSelCmod1 = 0u;
+        ptrBaseCfg->swSelCmod2 = 0u;
+    }
+    else
+    {
+        ptrBaseCfg->swSelCmod3 = 0u;
+        ptrBaseCfg->swSelCmod4 = 0u;
+    }
+
+    ptrBaseCfg->obsCtl = ptrTemplateCfg->obsCtl;
+    ptrBaseCfg->intr = ptrTemplateCfg->intr;
+    ptrBaseCfg->intrSet = ptrTemplateCfg->intrSet;
+    ptrBaseCfg->intrMask = ptrTemplateCfg->intrMask;
+
+    /* Set the scanning mode */
+    #if (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE)
+        ptrBaseCfg->ctl |= CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN << MSC_CTL_OPERATING_MODE_Pos;
+    #endif /* (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE) */
+
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+        ptrBaseCfg->swSelGpio = 0u;
+    #endif
+
+    /* Frame is not started */
+    ptrBaseCfg->frameCmd = 0x00u;
+
+    /* Clear Structures */
+    (void)memset(&ptrBaseCfg->sensorConfig, 0, sizeof(cy_stc_msc_sensor_config_t));
+    (void)memset(&ptrBaseCfg->swSelCsw[0u], 0, CY_MSC_CSW_NUM * CY_CAPSENSE_BYTE_IN_32_BIT);
+    (void)memset(&ptrBaseCfg->mode, 0, sizeof(cy_stc_msc_mode_config_t) * CY_MSC_MODES_NUM);
+
+    /*
+     * MODE CONFIGURATION
+     */
+    idCounter = 0u;
+    ptrMapping = &ptrIntrCxt->mapSenseMethod[0u];
+    for (i = 0u; i < CY_CAPSENSE_REG_MODE_NUMBER; i++)
+    {
+        ptrMapping[i] = CY_CAPSENSE_REG_MODE_UNDEFINED;
+    }
+    if (0u == context->ptrCommonConfig->numWd)
+    {
+        capStatus |= CY_CAPSENSE_STATUS_BAD_CONFIG;
+    }
+    /* For each widget */
+    for (i = 0u; i < context->ptrCommonConfig->numWd; i++)
+    {
+        cdacDitherEnabled = context->ptrWdContext[i].cdacDitherEn;
+
+        /* Calculate REG_MODE value */
+        snsMethod = context->ptrWdConfig[i].senseMethod;
+        snsMethodInternal = snsMethod - 1u;
+
+        if (CY_CAPSENSE_ENABLE == cdacDitherEnabled)
+        {
+            /* Shift sense mode to cdac dither enabled modes */
+            snsMethodInternal += CY_CAPSENSE_REG_MODE_DITHERING;
+        }
+
+        /* If a method is a new method then register the method */
+        if (ptrMapping[snsMethodInternal] == CY_CAPSENSE_REG_MODE_UNDEFINED)
+        {
+            if (CY_MSC_SENSE_MODE_NUMBER < idCounter)
+            {
+                capStatus |= CY_CAPSENSE_STATUS_CONFIG_OVERFLOW;
+                break;
+            }
+            else
+            {
+                ptrMapping[snsMethodInternal] = (uint8_t)idCounter;
+                ptrBaseCfg->mode[idCounter] = ptrTemplateCfg->mode[snsMethodInternal];
+
+                #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+                        if(CY_CAPSENSE_CSX_GROUP == snsMethod)
+                        {
+                            ptrBaseCfg->mode[idCounter].senseDutyCtl = CY_CAPSENSE_FW_CSX_AMUX_MODE_SENSE_DUTY_CTL_VALUE;
+                        }
+                    #endif
+                    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+                        if(CY_CAPSENSE_CSD_GROUP == snsMethod)
+                        {
+                            ptrBaseCfg->mode[idCounter].senseDutyCtl = 0u;
+                        }
+                    #endif
+                #endif
+
+                if((CY_CAPSENSE_MSC0_CMOD1PADD_PIN != ptrMscChConfig->pinCmod1) &&
+                   (CY_CAPSENSE_MSC1_CMOD1PADD_PIN != ptrMscChConfig->pinCmod1))
+                {
+                    ptrBaseCfg->mode[idCounter].swSelComp &= (~MSC_MODE_SW_SEL_COMP_CPCS1_Msk);
+                    ptrBaseCfg->mode[idCounter].swSelComp &= (~MSC_MODE_SW_SEL_COMP_CMCS2_Msk);
+                    ptrBaseCfg->mode[idCounter].swSelComp |= MSC_MODE_SW_SEL_COMP_CPCS3_Msk;
+                    ptrBaseCfg->mode[idCounter].swSelComp |= MSC_MODE_SW_SEL_COMP_CMCS4_Msk;
+
+                    ptrBaseCfg->mode[idCounter].swSelSh &= (~MSC_MODE_SW_SEL_SH_C1SHG_Msk);
+                    ptrBaseCfg->mode[idCounter].swSelSh |= MSC_MODE_SW_SEL_SH_C3SHG_Msk;
+                }
+
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+                    if(CY_CAPSENSE_CSX_GROUP == snsMethod)
+                    {
+                        #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                            ptrBaseCfg->mode[idCounter].swSelTop = CY_CAPSENSE_CSX_FW_AMUX_MODE_SW_SEL_TOP_VALUE;
+                        #else
+                            ptrBaseCfg->mode[idCounter].swSelTop = CY_CAPSENSE_CSX_FW_CTLMUX_MODE_SW_SEL_TOP_VALUE;
+                        #endif
+
+                        if(CY_CAPSENSE_SNS_CONNECTION_VDDA_BY_2 == ptrIntrCxt->intrCsxInactSnsConn)
+                        {
+                            /* Close the reference to filter switch */
+                            ptrBaseCfg->mode[idCounter].swSelTop |= MSC_MODE_SW_SEL_TOP_RMF_Msk;
+                            #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                                ptrBaseCfg->mode[idCounter].swSelSh = CY_CAPSENSE_FW_CSX_VDDA2_AMUX_MODE_SW_SEL_SH_VALUE;
+                            #else
+                                ptrBaseCfg->mode[idCounter].swSelSh = CY_CAPSENSE_FW_CSX_VDDA2_CTLMUX_MODE_SW_SEL_SH_VALUE;
+                            #endif
+                        }
+                    }
+                #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+                idCounter++;
+            }
+        }
+    }
+    ptrIntrCxt->numSenseMethod = (uint8_t)idCounter;
+
+    /*
+     * PINS CONFIGURATION
+     */
+    for (i = 0u; i < CY_CAPSENSE_CTRLMUX_PIN_STATE_NUMBER; i++)
+    {
+        ptrBaseCfg->swSelCswFunc[i] = ptrTemplateCfg->swSelCswFunc[i];
+    }
+
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) &&\
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN))
+        if (CY_CAPSENSE_SHIELD_PASSIVE == context->ptrCommonConfig->csdShieldMode)
+        {
+            ptrBaseCfg->swSelCswFunc[CY_CAPSENSE_CTRLMUX_PIN_STATE_SHIELD] =
+                    CY_CAPSENSE_FW_SHIELD_PASSIVE_CTRLMUX_REG_SW_SEL_CSW_VALUE;
+        }
+    #endif
+
+    /*
+     * CONFIGURATION FROM CAPSENSE&trade; DATA STRUCTURE
+     */
+
+    /* Initialize interrupts for all enabled MSC channels */
+    #if (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE)
+        ptrBaseCfg->intrMask |= MSC_INTR_MASK_FRAME_Msk;
+    #else
+        ptrBaseCfg->intrMask |= MSC_INTR_MASK_SCAN_Msk;
+    #endif /* (CY_CAPSENSE_SCAN_MODE_DMA_DRIVEN == CY_CAPSENSE_SCAN_MODE) */
+
+    /* Shielding is available in CSD only */
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) &&\
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN))
+        if(CY_CAPSENSE_REG_MODE_UNDEFINED != ptrMapping[CY_CAPSENSE_REG_MODE_CSD])
+        {
+            ptrBaseCfgMode = &ptrBaseCfg->mode[ptrMapping[CY_CAPSENSE_REG_MODE_CSD]];
+            Cy_CapSense_ApplyShieldConfig(ptrBaseCfgMode, context);
+        }
+
+        if(CY_CAPSENSE_REG_MODE_UNDEFINED != ptrMapping[CY_CAPSENSE_REG_MODE_CSD_DITHERING])
+        {
+            ptrBaseCfgMode = &ptrBaseCfg->mode[ptrMapping[CY_CAPSENSE_REG_MODE_CSD_DITHERING]];
+            Cy_CapSense_ApplyShieldConfig(ptrBaseCfgMode, context);
+        }
+    #endif
+
+    /* Generating the common configuration for the Compensation CDAC */
+    #if((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_CDAC_COMP_USAGE) || \
+        (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_CDAC_COMP_USAGE))
+        ptrBaseCfg->ccompCdacCtl |= (uint32_t)ptrIntrCxt->proOffsetCdacComp << MSC_CCOMP_CDAC_CTL_SEL_CO_PRO_OFFSET_Pos;
+    #else
+        ptrBaseCfg->swSelCdacCo = 0u;
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN)
+        /* Generating the common configuration for the CIC2 Filter */
+        ptrBaseCfg->filterCtl = 0x01uL << MSC_FILTER_CTL_FILTER_MODE_Pos;
+    #endif
+
+    /* Generating the common configuration for the control mux switch control */
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+        Cy_CapSense_GenerateCtrlMuxSwControl(chIndex, context);
+    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+
+    /* Generating the common configuration for the dithering CapDAC */
+    ptrBaseCfg->ditherCdacCtl = (uint32_t)context->ptrCommonContext->cdacDitherSeed |
+                                ((uint32_t)context->ptrCommonContext->cdacDitherPoly << MSC_DITHER_CDAC_CTL_LFSR_POLY_FL_Pos);
+
+    /* Configures synchronization signals */
+
+    /* Sync_Clock */
+    ptrBaseCfg->ctl &= ~MSC_CTL_CLK_SYNC_EN_Msk;
+    /* If SYNC_CLK is enabled, generates CLK_SYNC_EN only for the Master channel */
+    if ((((uint32_t)context->ptrCommonConfig->masterChannelId) == (chIndex + context->ptrCommonConfig->channelOffset)) &&
+        (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->syncClockEn))
+    {
+        ptrBaseCfg->ctl |= (uint32_t)context->ptrCommonConfig->syncClockEn << MSC_CTL_CLK_SYNC_EN_Pos;
+    }
+    /* Frame Start */
+    ptrBaseCfg->ctl &= ~MSC_CTL_EXT_FRAME_START_EN_Msk;
+    /*
+     * If EXT_FRAME_START is enabled, generates EXT_FRAME_START_EN for all channels,
+     * except of the Master channel which is generating FRAME_START for all another channels
+     */
+    if ((((uint32_t)context->ptrCommonConfig->masterChannelId) == (chIndex + context->ptrCommonConfig->channelOffset)) &&
+        (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->syncFrameStartEn))
+    {
+        ptrBaseCfg->ctl |= (uint32_t)context->ptrCommonConfig->syncFrameStartEn << MSC_CTL_EXT_FRAME_START_EN_Pos;
+    }
+    /* Generating the multi-channel mode for each channel with updating the sensor control registers */
+    if (0u != context->ptrCommonConfig->syncMode)
+    {
+        context->ptrCommonConfig->ptrMscChConfig[chIndex].ptrMscBase->SNS_CTL =
+                        ((uint32_t)context->ptrCommonConfig->syncMode << MSC_SNS_CTL_MULTI_CH_MODE_Pos);
+    }
+
+    /* Generating the common configuration for the clock dithering */
+    ptrBaseCfg->sensePeriodCtl = ((uint32_t)context->ptrCommonContext->lfsrPoly << MSC_SENSE_PERIOD_CTL_LFSR_POLY_Pos) |
+                                 ((uint32_t)context->ptrCommonContext->lfsrScale << MSC_SENSE_PERIOD_CTL_LFSR_SCALE_Pos);
+
+    /* Generating the common configuration for the number of the auto-resampling cycles and the counter behaviour when the
+     * RAW_COUNT exceeds 0xFFFF
+     */
+    ptrBaseCfg->scanCtl1 &= ~MSC_SCAN_CTL1_NUM_AUTO_RESAMPLE_Msk;
+    ptrBaseCfg->scanCtl1 &= ~MSC_SCAN_CTL1_RAW_COUNT_MODE_Msk;
+    ptrBaseCfg->scanCtl1 |= (uint32_t)context->ptrCommonConfig->numBadScans << MSC_SCAN_CTL1_NUM_AUTO_RESAMPLE_Pos;
+    ptrBaseCfg->scanCtl1 |= (uint32_t)context->ptrCommonConfig->counterMode << MSC_SCAN_CTL1_RAW_COUNT_MODE_Pos;
+
+    /* Generating the common configuration for the number of epilogue cycles */
+    ptrBaseCfg->scanCtl2 &= ~MSC_SCAN_CTL2_NUM_EPI_CYCLES_Msk;
+    if (0u < ptrIntrCxt->numEpiCycles)
+    {
+        ptrBaseCfg->scanCtl2 |= (uint32_t)ptrIntrCxt->numEpiCycles << MSC_SCAN_CTL2_NUM_EPI_CYCLES_Pos;
+    }
+    else
+    {
+        ptrBaseCfg->scanCtl2 |= (uint32_t)(1uL << MSC_SCAN_CTL2_NUM_EPI_CYCLES_Pos);
+    }
+
+    /* Generating the common configuration for the system level chopping */
+    ptrBaseCfg->scanCtl2 &= ~MSC_SCAN_CTL2_CHOP_POL_Msk;
+    ptrBaseCfg->scanCtl2 |= (uint32_t)context->ptrCommonConfig->chopPolarity << MSC_SCAN_CTL2_CHOP_POL_Pos;
+
+    /* Generating the common configuration for the coarse initialization and coarse short phase */
+    ptrBaseCfg->initCtl1 &= ~MSC_INIT_CTL1_NUM_INIT_CMOD_12_RAIL_CYCLES_Msk;
+    ptrBaseCfg->initCtl1 &= ~MSC_INIT_CTL1_NUM_INIT_CMOD_12_SHORT_CYCLES_Msk;
+    ptrBaseCfg->initCtl2 &= ~MSC_INIT_CTL2_NUM_INIT_CMOD_34_RAIL_CYCLES_Msk;
+    ptrBaseCfg->initCtl2 &= ~MSC_INIT_CTL2_NUM_INIT_CMOD_34_SHORT_CYCLES_Msk;
+
+    if((CY_CAPSENSE_MSC0_CMOD1PADD_PIN == ptrMscChConfig->pinCmod1) ||
+       (CY_CAPSENSE_MSC1_CMOD1PADD_PIN == ptrMscChConfig->pinCmod1))
+    {
+        ptrBaseCfg->initCtl1 |= (uint32_t)ptrIntrCxt->numCoarseInitChargeCycles << MSC_INIT_CTL1_NUM_INIT_CMOD_12_RAIL_CYCLES_Pos;
+        ptrBaseCfg->initCtl1 |= (uint32_t)ptrIntrCxt->numCoarseInitSettleCycles << MSC_INIT_CTL1_NUM_INIT_CMOD_12_SHORT_CYCLES_Pos;
+        ptrBaseCfg->initCtl3 |= CY_CAPSENSE_CMOD12_PAIR_SELECTION << MSC_INIT_CTL3_CMOD_SEL_Pos;
+    }
+    else
+    {
+        ptrBaseCfg->initCtl2 |= (uint32_t)ptrIntrCxt->numCoarseInitChargeCycles << MSC_INIT_CTL2_NUM_INIT_CMOD_34_RAIL_CYCLES_Pos;
+        ptrBaseCfg->initCtl2 |= (uint32_t)ptrIntrCxt->numCoarseInitSettleCycles << MSC_INIT_CTL2_NUM_INIT_CMOD_34_SHORT_CYCLES_Pos;
+        ptrBaseCfg->initCtl3 |= (uint32_t)CY_CAPSENSE_CMOD34_PAIR_SELECTION << MSC_INIT_CTL3_CMOD_SEL_Pos;
+    }
+    ptrBaseCfg->initCtl3 &= ~MSC_INIT_CTL3_NUM_PRO_OFFSET_CYCLES_Msk;
+    ptrBaseCfg->initCtl3 |= (uint32_t)ptrIntrCxt->numProOffsetCycles << MSC_INIT_CTL3_NUM_PRO_OFFSET_CYCLES_Pos;
+
+    /* Generating the common configuration for the number of sub-conversions to be run during PRO_DUMMY and PRO_WAIT phases. */
+    ptrBaseCfg->initCtl4 &= ~MSC_INIT_CTL4_NUM_PRO_DUMMY_SUB_CONVS_Msk;
+    ptrBaseCfg->initCtl4 &= ~MSC_INIT_CTL4_NUM_PRO_WAIT_CYCLES_Msk;
+    ptrBaseCfg->initCtl4 |= (uint32_t)context->ptrCommonContext->numFineInitCycles << MSC_INIT_CTL4_NUM_PRO_DUMMY_SUB_CONVS_Pos;
+    ptrBaseCfg->initCtl4 |= (uint32_t)context->ptrInternalContext->numFineInitWaitCycles << MSC_INIT_CTL4_NUM_PRO_WAIT_CYCLES_Pos;
+
+    return (capStatus);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GenerateSensorConfigValid
+****************************************************************************//**
+*
+* Generates the configuration for registers that have to be configured to start
+* a scan for a single sensor.
+*
+* \param scanSlot
+* Slot to scan
+*
+* \param ptrSensorCfg
+* Specifies the pointer to the sensor configuration to be filled.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the operation:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is performed successfully.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_GenerateSensorConfigValid(
+                uint32_t scanSlot,
+                uint32_t * ptrSensorCfg,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t wdIndex;
+    uint32_t widgetSenseMethod;
+    uint32_t snsMethodInternal;
+    cy_capsense_status_t capStatus = (uint32_t)CY_CAPSENSE_BAD_PARAM_E;
+
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] = 0u;
+    ptrSensorCfg[CY_CAPSENSE_SNS_CDAC_CTL_INDEX] = 0u;
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] = 0u;
+
+    /* Sensor clock configuration */
+    Cy_CapSense_ConfigSensorClock(scanSlot, &ptrSensorCfg[0u], context);
+
+    /* CapDAC configuration */
+    capStatus = Cy_CapSense_GenerateCdacConfig(scanSlot, &ptrSensorCfg[0u], context);
+
+    /* CIC2 filter control */
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] &= ~MSC_SNS_CTL_DECIM_RATE_Msk;
+    wdIndex = context->ptrScanSlots[scanSlot].wdId;
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN)
+        ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] |= ((uint32_t)context->ptrWdContext[wdIndex].cicRate - 1u) << MSC_SNS_CTL_DECIM_RATE_Pos;
+    #endif
+
+    /* Update widget sense method */
+    snsMethodInternal = context->ptrWdConfig[wdIndex].senseMethod;
+    snsMethodInternal -= 1u;
+    if (CY_CAPSENSE_ENABLE == context->ptrWdContext[wdIndex].cdacDitherEn)
+    {
+        /* Shift sense mode to cdac dither enabled modes */
+        snsMethodInternal += CY_CAPSENSE_REG_MODE_DITHERING;
+    }
+    widgetSenseMethod = context->ptrInternalContext->mapSenseMethod[snsMethodInternal];
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] &= ~MSC_SNS_CTL_SENSE_MODE_SEL_Msk;
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] |= widgetSenseMethod << MSC_SNS_CTL_SENSE_MODE_SEL_Pos;
+
+    /* Multi-channel mode */
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] &= ~MSC_SNS_CTL_MULTI_CH_MODE_Msk;
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] |= (uint32_t)context->ptrCommonConfig->syncMode << MSC_SNS_CTL_MULTI_CH_MODE_Pos;
+
+    /* System level chopping */
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] &= ~MSC_SNS_SCAN_CTL_NUM_CONV_Msk;
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= ((uint32_t)context->ptrWdConfig[wdIndex].numChopCycles - 1u) << MSC_SNS_SCAN_CTL_NUM_CONV_Pos;
+
+    /* Number of sub-conversions */
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] &= ~MSC_SNS_SCAN_CTL_NUM_SUB_CONVS_Msk;
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= ((uint32_t)context->ptrWdContext[wdIndex].numSubConversions - 1u) << MSC_SNS_SCAN_CTL_NUM_SUB_CONVS_Pos;
+
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] &= ~(MSC_SNS_SCAN_CTL_INIT_BYPASS_Msk);
+    if((CY_CAPSENSE_ENABLE == context->ptrWdContext[wdIndex].coarseInitBypassEn) &&
+       ((scanSlot % CY_CAPSENSE_SLOT_COUNT) != context->ptrWdConfig[wdIndex].firstSlotId))
+    {
+        ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= (MSC_SNS_SCAN_CTL_INIT_BYPASS_Msk);
+    }
+
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] |= (MSC_SNS_CTL_VALID_Msk);
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] |= (MSC_SNS_CTL_START_SCAN_Msk);
+
+   return (capStatus);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GenerateSensorConfig
+****************************************************************************//**
+*
+* Generates configuration to configure registers to
+* the scan of the single sensor in the specified slot of the specified channel.
+*
+* \param chIndex
+* The specified channel index.
+*
+* \param scanSlot
+* The specified slot index.
+*
+* \param ptrSensorCfg
+* Specifies the pointer to the sensor configuration to be filled.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the operation:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is performed successfully.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_GenerateSensorConfig(
+                uint32_t chIndex,
+                uint32_t scanSlot,
+                uint32_t * ptrSensorCfg,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t wdIndex;
+    uint32_t slotIndex = scanSlot;
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+        uint32_t nextChIndex;
+    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+    cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_BAD_PARAM;
+
+    wdIndex = context->ptrScanSlots[scanSlot].wdId;
+
+    if((wdIndex == CY_CAPSENSE_SLOT_EMPTY) ||
+       (wdIndex == CY_CAPSENSE_SLOT_SHIELD_ONLY) ||
+       (wdIndex == CY_CAPSENSE_SLOT_TX_ONLY))
+    {
+        #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+            if (chIndex == 0u)
+            {
+                slotIndex = scanSlot + CY_CAPSENSE_SLOT_COUNT;
+            }
+            else
+            {
+                slotIndex = scanSlot - CY_CAPSENSE_SLOT_COUNT;
+            }
+        #else /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+            nextChIndex = ((chIndex == 0u) ? 1u : 0u);
+            slotIndex = context->ptrActiveScanSns[chIndex].currentChannelSlotIndex + (nextChIndex * CY_CAPSENSE_SLOT_COUNT);
+        #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)*/
+
+        /* Generate proper config for sensor */
+        capStatus = Cy_CapSense_GenerateSensorConfigValid(slotIndex, ptrSensorCfg, context);
+    }
+    else
+    {
+        /* Generate proper config for sensor */
+        capStatus = Cy_CapSense_GenerateSensorConfigValid(slotIndex, ptrSensorCfg, context);
+    }
+
+    return (capStatus);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GenerateAllSensorConfig
+****************************************************************************//**
+*
+* Generates configuration to configure registers to start
+* a scan for all sensors of the specified channel.
+*
+* \param chId
+* Channel ID
+*
+* \param ptrSensorCfg
+* Specifies the pointer to the sensor configuration to be filled.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_GenerateAllSensorConfig(
+                uint32_t chId,
+                uint32_t * ptrSensorCfg,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t i = 0u;
+    uint32_t scanSlotIndex;
+    uint32_t scanSlotIndexValid;
+    uint32_t sensorCfgTmp[CY_MSC_6_SNS_REGS] = {0u, 0u, 0u, 0u, 0u, 0u};
+    uint32_t * ptrSensorCfgLocal = ptrSensorCfg;
+
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+        uint32_t snsMask;
+        uint32_t snsMaskInactive = 0u;
+        uint32_t snsFuncState;
+        uint32_t snsFuncStateSelfCap;
+        uint32_t snsFuncStateMutualCap;
+        uint32_t snsIndex;
+        uint32_t wdIndex;
+        uint32_t slotValue;
+        uint32_t widgetSenseGroup;
+        const cy_stc_capsense_electrode_config_t * eltdPinCfg;
+
+        #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_PHASE_ENABLED)
+            uint32_t j = 0u;
+            uint32_t pattern;
+            uint32_t snsMaskNegative;
+            uint32_t snsFuncStateNegative;
+        #endif
+
+        /* Get mask for all pins in control mux switch registers */
+        snsMaskInactive = context->ptrBaseFrameContext[chId].cswCtl;
+
+        /* Define mutual cap pin state */
+        snsFuncStateMutualCap = CY_CAPSENSE_CTRLMUX_PIN_STATE_GND;
+        switch (context->ptrInternalContext->intrCsxInactSnsConn)
+        {
+            case CY_CAPSENSE_SNS_CONNECTION_HIGHZ:
+                snsFuncStateMutualCap = CY_CAPSENSE_CTRLMUX_PIN_STATE_HIGH_Z;
+                break;
+            case CY_CAPSENSE_SNS_CONNECTION_VDDA_BY_2:
+                snsFuncStateMutualCap = CY_CAPSENSE_CTRLMUX_PIN_STATE_VDDA2;
+                break;
+            default:
+                /* No action for other connections */
+                break;
+        }
+
+        /* Define self cap pin state */
+        snsFuncStateSelfCap = CY_CAPSENSE_CTRLMUX_PIN_STATE_GND;
+        switch (context->ptrInternalContext->intrCsdInactSnsConn)
+        {
+            case CY_CAPSENSE_SNS_CONNECTION_HIGHZ:
+                snsFuncStateSelfCap = CY_CAPSENSE_CTRLMUX_PIN_STATE_HIGH_Z;
+                break;
+            case CY_CAPSENSE_SNS_CONNECTION_SHIELD:
+                snsFuncStateSelfCap = CY_CAPSENSE_CTRLMUX_PIN_STATE_SHIELD;
+                break;
+            default:
+                /* No action for other connections */
+                break;
+        }
+    #endif
+
+    for (scanSlotIndex = 0u; scanSlotIndex < CY_CAPSENSE_SLOT_COUNT; scanSlotIndex++)
+    {
+        scanSlotIndexValid = scanSlotIndex + ((chId + context->ptrCommonConfig->channelOffset) * CY_CAPSENSE_SLOT_COUNT);
+        (void)Cy_CapSense_GenerateSensorConfig((chId + context->ptrCommonConfig->channelOffset), scanSlotIndexValid, &sensorCfgTmp[0u], context);
+
+        /* Does this for Control Mux connection only */
+        #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+            slotValue = context->ptrScanSlots[scanSlotIndexValid].wdId;
+            if (CY_CAPSENSE_SLOT_EMPTY == slotValue)
+            {
+                scanSlotIndexValid = (((chId + 1u) % CY_CAPSENSE_TOTAL_CH_NUMBER) * CY_CAPSENSE_SLOT_COUNT) +
+                                     scanSlotIndex;
+                wdIndex = context->ptrScanSlots[scanSlotIndexValid].wdId;
+                widgetSenseGroup = context->ptrWdConfig[wdIndex].senseMethod;
+                if (CY_CAPSENSE_CSD_GROUP == widgetSenseGroup)
+                {
+                    snsFuncState = snsFuncStateSelfCap;
+                }
+                else
+                {
+                    snsFuncState = snsFuncStateMutualCap;
+                }
+                /* INACTIVE SENSORS */
+                Cy_CapSense_CalculateMaskRegisters(snsMaskInactive, snsFuncState, &sensorCfgTmp[0u]);
+            }
+            else
+            {
+                if (CY_CAPSENSE_SLOT_SHIELD_ONLY <= slotValue)
+                {
+                    scanSlotIndexValid = ((uint32_t)context->ptrScanSlots[scanSlotIndexValid].snsId *
+                                          CY_CAPSENSE_SLOT_COUNT) + scanSlotIndex;
+                }
+
+                snsIndex = context->ptrScanSlots[scanSlotIndexValid].snsId;
+                wdIndex = context->ptrScanSlots[scanSlotIndexValid].wdId;
+                widgetSenseGroup = context->ptrWdConfig[wdIndex].senseMethod;
+                snsFuncState = snsFuncStateMutualCap;
+                if (CY_CAPSENSE_CSD_GROUP == widgetSenseGroup)
+                {
+                    snsFuncState = snsFuncStateSelfCap;
+                }
+                /* INACTIVE SENSORS */
+                Cy_CapSense_CalculateMaskRegisters(snsMaskInactive, snsFuncState, &sensorCfgTmp[0u]);
+
+                /* ACTIVE SELF-CAP SENSOR */
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+                    if (CY_CAPSENSE_SLOT_SHIELD_ONLY > slotValue)
+                    {
+                        /* Initializes an active sensor (including ganged sensors) by SNS, RX or TX sensor state */
+                        if (CY_CAPSENSE_CSD_GROUP == widgetSenseGroup)
+                        {
+                            snsMask = 0u;
+                            snsFuncState = CY_CAPSENSE_CTRLMUX_PIN_STATE_SNS;
+                            eltdPinCfg = &context->ptrWdConfig[wdIndex].ptrEltdConfig[snsIndex];
+                            /* Proceed only if electrode configuration belongs to selected channel */
+                            if ((chId + context->ptrCommonConfig->channelOffset) == eltdPinCfg->chId)
+                            {
+                                /* Loop through all pads for this electrode (ganged sensor) */
+                                for (i = 0u; i < eltdPinCfg->numPins; i++)
+                                {
+                                    snsMask |= 0x01uL << eltdPinCfg->ptrPin[i].padNumber;
+                                }
+                                Cy_CapSense_CalculateMaskRegisters(snsMask, snsFuncState, &sensorCfgTmp[0u]);
+                            }
+                        }
+                    }
+                #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+                /* ACTIVE MUTUAL-CAP SENSOR */
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+                    if (CY_CAPSENSE_CSX_GROUP == widgetSenseGroup)
+                    {
+                        if (CY_CAPSENSE_SLOT_SHIELD_ONLY > slotValue)
+                        {
+                            /* RX ELECTRODE */
+                            snsMask = 0u;
+                            snsFuncState = CY_CAPSENSE_CTRLMUX_PIN_STATE_RX;
+                            i = snsIndex / context->ptrWdConfig[wdIndex].numRows;
+                            eltdPinCfg = &context->ptrWdConfig[wdIndex].ptrEltdConfig[i];
+                            if ((chId + context->ptrCommonConfig->channelOffset) == eltdPinCfg->chId)
+                            {
+                                /* Loop through all pads for this electrode (ganged sensor) */
+                                for (i = 0u; i < eltdPinCfg->numPins; i++)
+                                {
+                                    snsMask |= 0x01uL << eltdPinCfg->ptrPin[i].padNumber;
+                                }
+                                Cy_CapSense_CalculateMaskRegisters(snsMask, snsFuncState, &sensorCfgTmp[0u]);
+                            }
+                        }
+
+                        /* Handles multi-phase TX feature */
+                        #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_PHASE_ENABLED)
+                            if (context->ptrWdConfig[wdIndex].mptxOrder >= CY_CAPSENSE_MPTX_MIN_ORDER)
+                            {
+                                /* Multiple TX ELECTRODES */
+                                snsMask = 0u;
+                                snsMaskNegative = 0u;
+                                snsFuncState = CY_CAPSENSE_CTRLMUX_PIN_STATE_TX;
+                                snsFuncStateNegative = CY_CAPSENSE_CTRLMUX_PIN_STATE_TX_NEGATIVE;
+                                /* Finds the first sensor number in mptx group */
+                                i = snsIndex - (snsIndex % context->ptrWdConfig[wdIndex].mptxOrder);
+                                /* Finds TX electrode of the first group sensor */
+                                i = context->ptrWdConfig[wdIndex].numCols + (i % context->ptrWdConfig[wdIndex].numRows);
+                                eltdPinCfg = &context->ptrWdConfig[wdIndex].ptrEltdConfig[i];
+                                /* Finding the right vector / pattern for mptx operation */
+                                pattern = context->ptrWdConfig[wdIndex].ptrMptxTable->vector;
+                                i = (snsIndex % context->ptrWdConfig[wdIndex].mptxOrder);
+                                if (0u != i)
+                                {
+                                    pattern = (pattern >> i) | (pattern << (context->ptrWdConfig[wdIndex].mptxOrder - i));
+                                }
+                                if (CY_CAPSENSE_MPTX_MAX_ORDER > context->ptrWdConfig[wdIndex].mptxOrder)
+                                {
+                                    pattern &= (0x01uL << context->ptrWdConfig[wdIndex].mptxOrder) - 1u;
+                                }
+                                /* Loop through all involved mptx TX electrodes, positive and negative */
+                                for (j = 0u; j < context->ptrWdConfig[wdIndex].mptxOrder; j++)
+                                {
+                                    if ((chId + context->ptrCommonConfig->channelOffset) == eltdPinCfg->chId)
+                                    {
+                                        if (0u != (pattern & 0x01u))
+                                        {
+                                            /* Loop through all pads for this electrode (ganged sensor) */
+                                            for (i = 0u; i < eltdPinCfg->numPins; i++)
+                                            {
+                                                snsMask |= 0x01uL << eltdPinCfg->ptrPin[i].padNumber;
+                                            }
+                                        }
+                                        else
+                                        {
+                                            /* Loop through all pads for this electrode (ganged sensor) */
+                                            for (i = 0u; i < eltdPinCfg->numPins; i++)
+                                            {
+                                                snsMaskNegative |= 0x01uL << eltdPinCfg->ptrPin[i].padNumber;
+                                            }
+                                        }
+                                    }
+                                    pattern >>= 0x01u;
+                                    eltdPinCfg++;
+                                }
+                                Cy_CapSense_CalculateMaskRegisters(snsMask, snsFuncState, &sensorCfgTmp[0u]);
+                                Cy_CapSense_CalculateMaskRegisters(snsMaskNegative, snsFuncStateNegative, &sensorCfgTmp[0u]);
+                            }
+                            else
+                            {
+                                /* TX ELECTRODE */
+                                snsMask = 0u;
+                                snsFuncState = CY_CAPSENSE_CTRLMUX_PIN_STATE_TX;
+                                i = context->ptrWdConfig[wdIndex].numCols +
+                                        (snsIndex % context->ptrWdConfig[wdIndex].numRows);
+                                eltdPinCfg = &context->ptrWdConfig[wdIndex].ptrEltdConfig[i];
+                                if ((chId + context->ptrCommonConfig->channelOffset) == eltdPinCfg->chId)
+                                {
+                                    /* Loop through all pads for this electrode (ganged sensor) */
+                                    for (i = 0u; i < eltdPinCfg->numPins; i++)
+                                    {
+                                        snsMask |= 0x01uL << eltdPinCfg->ptrPin[i].padNumber;
+                                    }
+                                    Cy_CapSense_CalculateMaskRegisters(snsMask, snsFuncState, &sensorCfgTmp[0u]);
+                                }
+                            }
+                        #else
+                            /* TX ELECTRODE */
+                            snsMask = 0u;
+                            snsFuncState = CY_CAPSENSE_CTRLMUX_PIN_STATE_TX;
+                            i = context->ptrWdConfig[wdIndex].numCols +
+                                    (snsIndex % context->ptrWdConfig[wdIndex].numRows);
+                            eltdPinCfg = &context->ptrWdConfig[wdIndex].ptrEltdConfig[i];
+                            if ((chId + context->ptrCommonConfig->channelOffset) == eltdPinCfg->chId)
+                            {
+                                /* Loop through all pads for this electrode (ganged sensor) */
+                                for (i = 0u; i < eltdPinCfg->numPins; i++)
+                                {
+                                    snsMask |= 0x01uL << eltdPinCfg->ptrPin[i].padNumber;
+                                }
+                                Cy_CapSense_CalculateMaskRegisters(snsMask, snsFuncState, &sensorCfgTmp[0u]);
+                            }
+                        #endif
+                    }
+                #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+                /* SHIELD ELECTRODE */
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                    if (0u < context->ptrCommonConfig->csdShieldNumPin)
+                    {
+                        snsMask = 0u;
+                        /* Connect shield to CSX_ISC in CSX mode */
+                        snsFuncState = (CY_CAPSENSE_CSD_GROUP == widgetSenseGroup) ?
+                                        CY_CAPSENSE_CTRLMUX_PIN_STATE_SHIELD :
+                                        snsFuncStateMutualCap;
+
+                        for (i = 0u; i < context->ptrCommonConfig->csdShieldNumPin; i++)
+                        {
+                            if ((chId + context->ptrCommonConfig->channelOffset) == context->ptrShieldPinConfig[i].chId)
+                            {
+                                snsMask |= 0x01uL << context->ptrShieldPinConfig[i].padNumber;
+                            }
+                        }
+                        Cy_CapSense_CalculateMaskRegisters(snsMask, snsFuncState, &sensorCfgTmp[0u]);
+                    }
+                #endif
+            }
+        #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+
+        /* Store results */
+        for (i = 0u; i < CY_MSC_6_SNS_REGS; i++)
+        {
+            ptrSensorCfgLocal[i] = sensorCfgTmp[i];
+        }
+        ptrSensorCfgLocal += CY_MSC_6_SNS_REGS;
+    }
+}
+
+
+#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CalculateMaskRegisters
+****************************************************************************//**
+*
+* Calculates the mask for pins that have to be updated for Control MUX
+* connection.
+*
+* \param mask
+* Specifies the mask of pins that should be updated.
+*
+* \param funcState
+* Specifies the pin state functionality.
+*
+* \param ptrCfg
+* Specifies the pointer to the mask registers.
+*
+*******************************************************************************/
+void Cy_CapSense_CalculateMaskRegisters(
+                uint32_t mask,
+                uint32_t funcState,
+                uint32_t * ptrCfg)
+{
+    uint32_t * ptrCfgMask = ptrCfg;
+
+    ptrCfgMask[0u] &= ~mask;
+    ptrCfgMask[1u] &= ~mask;
+    ptrCfgMask[2u] &= ~mask;
+    if (0u != (funcState & 0x04u))
+    {
+        ptrCfgMask[0u] |= mask;
+    }
+    if (0u != (funcState & 0x02u))
+    {
+        ptrCfgMask[1u] |= mask;
+    }
+    if (0u != (funcState & 0x01u))
+    {
+        ptrCfgMask[2u] |= mask;
+    }
+}
+#endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GenerateCdacConfig
+****************************************************************************//**
+*
+* Generates the Cap DAC configuration for a selected sensor.
+*
+* \param scanSlot
+* Slot to scan
+*
+* \param ptrSensorCfg
+* Specifies the pointer to the sensor configuration to be filled.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the operation:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is performed successfully.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_GenerateCdacConfig(
+                uint32_t scanSlot,
+                uint32_t * ptrSensorCfg,
+                const cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t capStatus = 0u;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+    const cy_stc_capsense_sensor_context_t * ptrSnsCxt;
+    uint32_t compDiv;
+    uint32_t wdIndex;
+    uint32_t snsIndex;
+    uint32_t cdacLfsrScale;
+    uint32_t snsCdacCtlReg = 0u;
+
+    wdIndex = context->ptrScanSlots[scanSlot].wdId;
+    snsIndex = context->ptrScanSlots[scanSlot].snsId;
+    ptrWdCfg  = &context->ptrWdConfig[wdIndex];
+    ptrSnsCxt = &ptrWdCfg->ptrSnsContext[snsIndex];
+
+    /* Compensation CDAC Divider */
+    compDiv = context->ptrWdContext[wdIndex].cdacCompDivider;
+    compDiv = (compDiv > 0u) ? (compDiv - 1u) : 0u;
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] &= ~MSC_SNS_SCAN_CTL_COMP_DIV_Msk;
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= compDiv << MSC_SNS_SCAN_CTL_COMP_DIV_Pos;
+
+    /* Cap DAC dithering control */
+    snsCdacCtlReg = 0u;
+
+    snsCdacCtlReg |= MSC_SNS_CDAC_CTL_CLOCK_REF_RATE_Msk;
+
+    if (CY_CAPSENSE_ENABLE == ptrWdCfg->ptrWdContext->cdacDitherEn)
+    {
+        cdacLfsrScale = context->ptrWdContext[wdIndex].cdacDitherValue;
+        snsCdacCtlReg |= cdacLfsrScale << MSC_SNS_CDAC_CTL_LFSR_SCALE_FL_Pos;
+        snsCdacCtlReg |= MSC_SNS_CDAC_CTL_FL_EN_Msk;
+    }
+
+    #if(CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+        if (0u != (CY_CAPSENSE_MW_STATE_CALIBRATION_SINGLE_MASK & context->ptrCommonContext->status))
+        {
+            /* If calibration, reuse compensation CDAC field as Ref CDAC in single CDAC mode */
+            snsCdacCtlReg |= ((uint32_t)ptrSnsCxt->cdacComp) << MSC_SNS_CDAC_CTL_SEL_RE_Pos;
+        }
+        else
+        {
+            /* Ref CDAC Code setup */
+            if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) &&
+                (ptrWdCfg->numCols <= snsIndex))
+            {
+                snsCdacCtlReg |= ((uint32_t)ptrWdCfg->ptrWdContext->rowCdacRef) <<
+                                                    MSC_SNS_CDAC_CTL_SEL_RE_Pos;
+            }
+            else
+            {
+                snsCdacCtlReg |= ((uint32_t)ptrWdCfg->ptrWdContext->cdacRef) <<
+                                                    MSC_SNS_CDAC_CTL_SEL_RE_Pos;
+            }
+
+            if(((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) &&
+                (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCdacCompEn)) ||
+               ((CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod) &&
+                (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csxCdacCompEn)))
+            {
+                snsCdacCtlReg |= ((uint32_t)ptrSnsCxt->cdacComp) << MSC_SNS_CDAC_CTL_SEL_CO_Pos;
+            }
+        }
+    #else
+        if (0u == (CY_CAPSENSE_MW_STATE_CALIBRATION_SINGLE_MASK & context->ptrCommonContext->status))
+        {
+            /* Ref CDAC Code setup */
+            if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) &&
+                (ptrWdCfg->numCols <= snsIndex))
+            {
+                snsCdacCtlReg |= ((uint32_t)ptrWdCfg->ptrWdContext->rowCdacRef) <<
+                                                    MSC_SNS_CDAC_CTL_SEL_RE_Pos;
+            }
+            else
+            {
+                snsCdacCtlReg |= ((uint32_t)ptrWdCfg->ptrWdContext->cdacRef) <<
+                                                    MSC_SNS_CDAC_CTL_SEL_RE_Pos;
+            }
+
+            if(((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) &&
+                (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csdCdacCompEn)) ||
+               ((CY_CAPSENSE_CSX_GROUP == ptrWdCfg->senseMethod) &&
+                (CY_CAPSENSE_ENABLE == context->ptrCommonConfig->csxCdacCompEn)))
+            {
+                snsCdacCtlReg |= ((uint32_t)ptrSnsCxt->cdacComp) << MSC_SNS_CDAC_CTL_SEL_CO_Pos;
+            }
+        }
+    #endif
+
+    ptrSensorCfg[CY_CAPSENSE_SNS_CDAC_CTL_INDEX] = snsCdacCtlReg;
+
+    return (capStatus);
+}
+
+
+#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+/*******************************************************************************
+* Function Name: Cy_CapSense_GenerateCtrlMuxSwControl
+****************************************************************************//**
+*
+* Generates the Control MUX Switch Control register configuration.
+*
+* \param chIndex
+* The desired channel index.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_GenerateCtrlMuxSwControl(
+                uint32_t chIndex,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t cswFuncMode = 0uL;
+    uint32_t i;
+    const cy_stc_capsense_pin_config_t * ptrPinCfg = context->ptrPinConfig;
+
+    for (i = 0u; i < context->ptrCommonConfig->numPin; i++)
+    {
+        if ((chIndex + context->ptrCommonConfig->channelOffset) == ptrPinCfg->chId)
+        {
+            cswFuncMode |= (0x01uL << ptrPinCfg->padNumber);
+        }
+        ptrPinCfg++;
+    }
+
+    ptrPinCfg = context->ptrShieldPinConfig;
+    for (i = 0u; i < context->ptrCommonConfig->csdShieldNumPin; i++)
+    {
+        if ((chIndex + context->ptrCommonConfig->channelOffset) == ptrPinCfg->chId)
+        {
+            cswFuncMode |= (0x01uL << ptrPinCfg->padNumber);
+        }
+        ptrPinCfg++;
+    }
+    context->ptrBaseFrameContext[chIndex].cswCtl = cswFuncMode;
+}
+#endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_ApplyShieldConfig
+****************************************************************************//**
+*
+* Applies shield configuration to the base configuration.
+*
+* \param ptrBaseCfgMode
+* Specifies the pointer to the sense mode registers structure
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_ApplyShieldConfig(
+                cy_stc_msc_mode_config_t * ptrBaseCfgMode,
+                const cy_stc_capsense_context_t * context)
+{
+    ptrBaseCfgMode->senseDutyCtl &= ~(MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Msk |
+                                      MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Msk);
+    /* Active Shield mode */
+    if (CY_CAPSENSE_SHIELD_ACTIVE == context->ptrCommonConfig->csdShieldMode)
+    {
+        #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+            ptrBaseCfgMode->swSelTop &= ~CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_TOP_MASK;
+            ptrBaseCfgMode->swSelTop |= CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_TOP_VALUE;
+            ptrBaseCfgMode->swSelSh  |= CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_SH_VALUE;
+
+        #else /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+            /* Amux sensor_connection_method */
+            ptrBaseCfgMode->swSelTop &= ~CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_TOP_MASK;
+            ptrBaseCfgMode->swSelTop |= CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_TOP_VALUE;
+            ptrBaseCfgMode->swSelSh  |= CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_SH_VALUE;
+        #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+    }
+    /* Passive Shield mode */
+    else
+    {
+        #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+            ptrBaseCfgMode->swSelTop &= ~CY_CAPSENSE_FW_SHIELD_PASSIVE_CTRLMUX_REG_SW_SEL_TOP_MASK;
+            ptrBaseCfgMode->swSelTop |= CY_CAPSENSE_FW_SHIELD_PASSIVE_CTRLMUX_REG_SW_SEL_TOP_VALUE;
+            ptrBaseCfgMode->senseDutyCtl |= ((1u << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) |
+                                             (1u << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos));
+        #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+    }
+}
+#endif
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_ConfigSensorClock
+****************************************************************************//**
+*
+* This function configures the sense clock for different modes.
+*
+* \param scanSlot
+* Slot to scan
+*
+* \param ptrSensorCfg
+* Specifies the pointer to the sensor configuration to be filled.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_ConfigSensorClock(
+                uint32_t scanSlot,
+                uint32_t * ptrSensorCfg,
+                const cy_stc_capsense_context_t * context)
+{
+    uint8_t lfsrBitsVal;
+    uint8_t lfsrModeVal;
+    uint16_t snsClkDividerVal;
+
+    uint32_t wdIndex = context->ptrScanSlots[scanSlot].wdId;
+    const cy_stc_capsense_widget_context_t * ptrWdCxt = &context->ptrWdContext[wdIndex];
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[wdIndex];
+
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] &= ~(MSC_SNS_CTL_SENSE_DIV_Msk |
+                                                 MSC_SNS_CTL_LFSR_MODE_Msk |
+                                                 MSC_SNS_CTL_LFSR_BITS_Msk);
+
+    /* Getting column sense clock divider */
+    snsClkDividerVal = ptrWdCxt->snsClk;
+    if((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) &&
+       (ptrWdCfg->numCols <= context->ptrScanSlots[scanSlot].snsId))
+    {
+        snsClkDividerVal = ptrWdCxt->rowSnsClk;
+    }
+
+    snsClkDividerVal = (uint16_t)Cy_CapSense_AdjustSnsClkDivider(ptrWdCfg->senseMethod,
+                                                ptrWdCxt->snsClkSource, snsClkDividerVal);
+
+    snsClkDividerVal -= 1u;
+    lfsrBitsVal = (ptrWdCxt->lfsrBits & CY_CAPSENSE_LFSR_BITS_RANGE_MASK);
+    lfsrModeVal = (ptrWdCxt->snsClkSource & CY_CAPSENSE_CLK_SOURCE_MASK);
+
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] |= (((uint32_t)snsClkDividerVal) << MSC_SNS_CTL_SENSE_DIV_Pos) |
+                                                ((uint32_t)lfsrModeVal << MSC_SNS_CTL_LFSR_MODE_Pos) |
+                                                ((uint32_t)lfsrBitsVal << MSC_SNS_CTL_LFSR_BITS_Pos);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_AdjustSnsClkDivider
+****************************************************************************//**
+*
+* If the PRS is selected as the Sense Clock source, adjusts the Sense Clock
+* divider to obtain the max frequency of the PRS sequence equal to
+* ModClkFreq / SenseClkDivider. Updates the sense Clock divider with the minimal
+* supported value in case if it is out of range for the specified parameters.
+*
+* \param snsMethod
+*  Specifies the widget group:
+*   - CSD (CY_CAPSENSE_CSD_GROUP)
+*   - CSX (CY_CAPSENSE_CSX_GROUP)
+*
+* \param snsClkSource
+*  Specifies the sense Clock source, supported by MSCv3 HW:
+*   - CY_CAPSENSE_CLK_SOURCE_DIRECT
+*   - CY_CAPSENSE_CLK_SOURCE_SSC
+*   - CY_CAPSENSE_CLK_SOURCE_PRS
+*
+* \param snsClkDivider
+* The divider value for the sense clock.
+*
+* \return
+*  Adjusted value of the Sense Clock divider.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_AdjustSnsClkDivider(
+                        uint8_t snsMethod,
+                        uint8_t snsClkSource,
+                        uint16_t snsClkDivider)
+{
+    uint16_t snsClkDividerTmp;
+    uint32_t snsClkDividerShift;
+    uint32_t snsClkSourceTmp;
+
+    snsClkDividerTmp = snsClkDivider;
+    snsClkSourceTmp = ((uint32_t)snsClkSource & CY_CAPSENSE_CLK_SOURCE_MASK);
+
+    if(CY_CAPSENSE_CSD_GROUP == snsMethod)
+    {
+        snsClkDividerShift = CY_CAPSENSE_4PH_PRS_SNS_CLOCK_DIVIDER_SHIFT;
+    }
+    else
+    {
+        snsClkDividerShift = CY_CAPSENSE_2PH_PRS_SNS_CLOCK_DIVIDER_SHIFT;
+    }
+
+    if(CY_CAPSENSE_CLK_SOURCE_PRS == snsClkSourceTmp)
+    {
+        snsClkDividerTmp >>= snsClkDividerShift;
+    }
+
+    return (snsClkDividerTmp);
+}
+
+
+#endif /* CY_IP_M0S8MSCV3 */
+
+
+/* [] END OF FILE */

+ 702 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_generator_v3.h

@@ -0,0 +1,702 @@
+/***************************************************************************//**
+* \file cy_capsense_generator_v3.h
+* \version 3.0
+*
+* \brief
+* This file provides the function prototypes specific to the register
+* map generation module.
+*
+********************************************************************************
+* \copyright
+* Copyright 2020-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_GENERATOR_V3_H)
+#define CY_CAPSENSE_GENERATOR_V3_H
+
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_sm_base_full_wave_v3.h"
+
+#if (defined(CY_IP_M0S8MSCV3))
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+cy_capsense_status_t Cy_CapSense_GenerateBaseConfig(
+                uint32_t chIndex,
+                cy_stc_capsense_context_t * context);
+cy_capsense_status_t Cy_CapSense_GenerateSensorConfig(
+                uint32_t chIndex,
+                uint32_t scanSlot,
+                uint32_t * ptrSensorCfg,
+                cy_stc_capsense_context_t * context);
+void Cy_CapSense_GenerateAllSensorConfig(
+                uint32_t chId,
+                uint32_t * ptrSensorCfg,
+                cy_stc_capsense_context_t * context);
+cy_capsense_status_t Cy_CapSense_GenerateCdacConfig(
+                uint32_t scanSlot,
+                uint32_t * ptrSensorCfg,
+                const cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+void Cy_CapSense_CalculateMaskRegisters(
+                uint32_t mask,
+                uint32_t funcState,
+                uint32_t * ptrCfg);
+#endif
+
+/** \} \endcond */
+
+
+/*******************************************************************************
+* Sensor Config Register indexes in the frame
+*******************************************************************************/
+#define CY_CAPSENSE_SNS_SW_SEL_CSW_MASK2_INDEX                                  (0u)
+#define CY_CAPSENSE_SNS_SW_SEL_CSW_MASK1_INDEX                                  (1u)
+#define CY_CAPSENSE_SNS_SW_SEL_CSW_MASK0_INDEX                                  (2u)
+#define CY_CAPSENSE_SNS_SCAN_CTL_INDEX                                          (3u)
+#define CY_CAPSENSE_SNS_CDAC_CTL_INDEX                                          (4u)
+#define CY_CAPSENSE_SNS_CTL_INDEX                                               (5u)
+
+
+/*******************************************************************************
+* Macros for Cmod selection
+*******************************************************************************/
+#define CY_CAPSENSE_MSC0_CMOD1PADD_PIN                                          (2u)
+#define CY_CAPSENSE_MSC1_CMOD1PADD_PIN                                          (1u)
+
+#define CY_CAPSENSE_CMOD12_PAIR_SELECTION                                       (0u)
+#define CY_CAPSENSE_CMOD34_PAIR_SELECTION                                       (1u)
+
+
+/*******************************************************************************
+* Register definition for FW CSD CTRLMUX with Active Shielding
+*******************************************************************************/
+#define CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_TOP_MASK                (0x4FFC0000uL)
+#define CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_SH_MASK                 (0x80050000uL)
+#define CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_TOP_VALUE               (0x44280000uL)
+#define CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_SH_VALUE                (0x80050000uL)
+#define CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_CSW_VALUE               (0x84022000uL)
+
+
+/*******************************************************************************
+* Register definition for FW CSD CTRLMUX with Passive Shielding
+*******************************************************************************/
+#define CY_CAPSENSE_FW_SHIELD_PASSIVE_CTRLMUX_REG_SW_SEL_TOP_MASK               (0x0FFC0000uL)
+#define CY_CAPSENSE_FW_SHIELD_PASSIVE_CTRLMUX_REG_SW_SEL_TOP_VALUE              (0x09800000uL)
+#define CY_CAPSENSE_FW_SHIELD_PASSIVE_CTRLMUX_REG_SW_SEL_CSW_VALUE              (0x09080000uL)
+
+
+/*******************************************************************************
+* Register definition for FW CSD AMUX with Active Shielding
+*******************************************************************************/
+#define CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_TOP_MASK                   (0x40000000uL)
+#define CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_SH_MASK                    (0x80010100uL)
+#define CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_TOP_VALUE                  (0x40000000uL)
+#define CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_SH_VALUE                   (0x80010100uL)
+
+
+/*******************************************************************************
+* Register definition for FW CSX VDDA/2
+*******************************************************************************/
+#define CY_CAPSENSE_FW_CSX_VDDA2_CTLMUX_MODE_SW_SEL_SH_VALUE                    (0x87050000uL)
+#define CY_CAPSENSE_FW_CSX_VDDA2_AMUX_MODE_SW_SEL_SH_VALUE                      (0x87010100uL)
+
+
+/*******************************************************************************
+* The MODE_SENSE_DUTY_CTL register configuration for the FW CSX AMUX
+*******************************************************************************/
+#define CY_CAPSENSE_FW_CSX_AMUX_MODE_SENSE_DUTY_CTL_VALUE                       (0x11000000uL)
+
+
+/*******************************************************************************
+* The MODE_SW_SEL_TOP register configuration for the FW CSX
+*******************************************************************************/
+#define CY_CAPSENSE_CSX_FW_CTLMUX_MODE_SW_SEL_TOP_VALUE            (1uL << MSC_MODE_SW_SEL_TOP_SHG_Pos)
+#define CY_CAPSENSE_CSX_FW_AMUX_MODE_SW_SEL_TOP_VALUE              ((2uL << MSC_MODE_SW_SEL_TOP_AYA_CTL_Pos) |\
+                                                                    (1uL << MSC_MODE_SW_SEL_TOP_AYA_EN_Pos)  |\
+                                                                    (2uL << MSC_MODE_SW_SEL_TOP_AYB_CTL_Pos) |\
+                                                                    (1uL << MSC_MODE_SW_SEL_TOP_AYB_EN_Pos)  |\
+                                                                    (1uL << MSC_MODE_SW_SEL_TOP_SHG_Pos))
+
+/* CSW0 = RX MUX */
+#define CY_CAPSENSE_SM_REG_SW_SEL_CSW0_RX_VALUE \
+((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW0_FLD_SW_SNCA  << MSC_SW_SEL_CSW_SW_SNCA_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW0_FLD_SW_SNCB  << MSC_SW_SEL_CSW_SW_SNCB_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW0_FLD_SW_SNCC  << MSC_SW_SEL_CSW_SW_SNCC_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW0_FLD_SW_SNCV  << MSC_SW_SEL_CSW_SW_SNCV_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW0_FLD_SW_SNCG  << MSC_SW_SEL_CSW_SW_SNCG_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW0_FLD_REF_MODE << MSC_SW_SEL_CSW_REF_MODE_Pos) | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW0_FLD_ENABLED  << MSC_SW_SEL_CSW_ENABLED_Pos))
+
+/* CSW1 = Positive TX MUX */
+#define CY_CAPSENSE_SM_REG_SW_SEL_CSW1_TX_VALUE \
+((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW1_FLD_SW_SNCA  << MSC_SW_SEL_CSW_SW_SNCA_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW1_FLD_SW_SNCB  << MSC_SW_SEL_CSW_SW_SNCB_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW1_FLD_SW_SNCC  << MSC_SW_SEL_CSW_SW_SNCC_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW1_FLD_SW_SNCV  << MSC_SW_SEL_CSW_SW_SNCV_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW1_FLD_SW_SNCG  << MSC_SW_SEL_CSW_SW_SNCG_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW1_FLD_REF_MODE << MSC_SW_SEL_CSW_REF_MODE_Pos) | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW1_FLD_ENABLED  << MSC_SW_SEL_CSW_ENABLED_Pos))
+
+/* CSW2 = Negative TX MUX */
+#define CY_CAPSENSE_SM_REG_SW_SEL_CSW2_NEG_TX_VALUE \
+((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW2_FLD_SW_SNCA  << MSC_SW_SEL_CSW_SW_SNCA_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW2_FLD_SW_SNCB  << MSC_SW_SEL_CSW_SW_SNCB_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW2_FLD_SW_SNCC  << MSC_SW_SEL_CSW_SW_SNCC_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW2_FLD_SW_SNCV  << MSC_SW_SEL_CSW_SW_SNCV_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW2_FLD_SW_SNCG  << MSC_SW_SEL_CSW_SW_SNCG_Pos)  | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW2_FLD_REF_MODE << MSC_SW_SEL_CSW_REF_MODE_Pos) | \
+ (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW2_FLD_ENABLED  << MSC_SW_SEL_CSW_ENABLED_Pos))
+
+/* CSW3 = Cs Sensor MUX */
+#define CY_CAPSENSE_SM_REG_SW_SEL_CSW3_SNS_VALUE \
+((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW3_FLD_SW_SNCA  << MSC_SW_SEL_CSW_SW_SNCA_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW3_FLD_SW_SNCB  << MSC_SW_SEL_CSW_SW_SNCB_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW3_FLD_SW_SNCC  << MSC_SW_SEL_CSW_SW_SNCC_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW3_FLD_SW_SNCV  << MSC_SW_SEL_CSW_SW_SNCV_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW3_FLD_SW_SNCG  << MSC_SW_SEL_CSW_SW_SNCG_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW3_FLD_REF_MODE << MSC_SW_SEL_CSW_REF_MODE_Pos) | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW3_FLD_ENABLED  << MSC_SW_SEL_CSW_ENABLED_Pos))
+
+/* CSW4 = Shield MUX for grounded shield */
+#define CY_CAPSENSE_SM_REG_SW_SEL_CSW4_GND_VALUE \
+((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW4_FLD_SW_SNCA  << MSC_SW_SEL_CSW_SW_SNCA_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW4_FLD_SW_SNCB  << MSC_SW_SEL_CSW_SW_SNCB_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW4_FLD_SW_SNCC  << MSC_SW_SEL_CSW_SW_SNCC_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW4_FLD_SW_SNCV  << MSC_SW_SEL_CSW_SW_SNCV_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW4_FLD_SW_SNCG  << MSC_SW_SEL_CSW_SW_SNCG_Pos)  | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW4_FLD_REF_MODE << MSC_SW_SEL_CSW_REF_MODE_Pos) | \
+ (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW4_FLD_ENABLED  << MSC_SW_SEL_CSW_ENABLED_Pos)) \
+
+/* CSW5 = High Z */
+#define CY_CAPSENSE_SM_REG_SW_SEL_CSW5_HIGH_Z_VALUE \
+((CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW5_FLD_SW_SNCA  << MSC_SW_SEL_CSW_SW_SNCA_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW5_FLD_SW_SNCB  << MSC_SW_SEL_CSW_SW_SNCB_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW5_FLD_SW_SNCC  << MSC_SW_SEL_CSW_SW_SNCC_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW5_FLD_SW_SNCV  << MSC_SW_SEL_CSW_SW_SNCV_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW5_FLD_SW_SNCG  << MSC_SW_SEL_CSW_SW_SNCG_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW5_FLD_REF_MODE << MSC_SW_SEL_CSW_REF_MODE_Pos) | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW5_FLD_ENABLED  << MSC_SW_SEL_CSW_ENABLED_Pos)) \
+
+/* CSW6 = CSDBUSC connection */
+#define CY_CAPSENSE_SM_REG_SW_SEL_CSW6_VDDA2_VALUE \
+((CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW6_FLD_SW_SNCA  << MSC_SW_SEL_CSW_SW_SNCA_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW6_FLD_SW_SNCB  << MSC_SW_SEL_CSW_SW_SNCB_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW6_FLD_SW_SNCC  << MSC_SW_SEL_CSW_SW_SNCC_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW6_FLD_SW_SNCV  << MSC_SW_SEL_CSW_SW_SNCV_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW6_FLD_SW_SNCG  << MSC_SW_SEL_CSW_SW_SNCG_Pos)  | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW6_FLD_REF_MODE << MSC_SW_SEL_CSW_REF_MODE_Pos) | \
+ (CY_CAPSENSE_SM_FULL_WAVE_CTRL_MUX_REG_SW_SEL_CSW6_FLD_ENABLED  << MSC_SW_SEL_CSW_ENABLED_Pos)) \
+
+
+#define CY_CAPSENSE_CSD_RM_SENSING_METHOD_INDEX         (0u)
+#define CY_CAPSENSE_CSX_RM_SENSING_METHOD_INDEX         (1u)
+#define CY_CAPSENSE_CSD_DITHERING_SENSING_METHOD_INDEX  (2u)
+#define CY_CAPSENSE_CSX_DITHERING_SENSING_METHOD_INDEX  (3u)
+
+
+/** Initialization of sensing method template variable */
+#define CY_CAPSENSE_SENSING_METHOD_BASE_TEMPLATE            \
+    {                                                   \
+        .ctl = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_SENSE_EN << MSC_CTL_SENSE_EN_Pos)                    | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_MSCCMP_EN << MSC_CTL_MSCCMP_EN_Pos)                   | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_CLK_SYNC_EN << MSC_CTL_CLK_SYNC_EN_Pos)               | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_EXT_FRAME_START_EN << MSC_CTL_EXT_FRAME_START_EN_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_OPERATING_MODE << MSC_CTL_OPERATING_MODE_Pos)         | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_BUF_MODE << MSC_CTL_BUF_MODE_Pos)                     | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_CLK_MSC_RATIO << MSC_CTL_CLK_MSC_RATIO_Pos)           | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_ENABLED << MSC_CTL_ENABLED_Pos)),                      \
+        .spare = \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SPARE_FLD_SPARE), \
+        .scanCtl1 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SCAN_CTL1_FLD_NUM_AUTO_RESAMPLE << MSC_SCAN_CTL1_NUM_AUTO_RESAMPLE_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SCAN_CTL1_FLD_RESCAN_DEBUG_MODE << MSC_SCAN_CTL1_RESCAN_DEBUG_MODE_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SCAN_CTL1_FLD_NUM_SAMPLES << MSC_SCAN_CTL1_NUM_SAMPLES_Pos)              | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SCAN_CTL1_FLD_RAW_COUNT_MODE << MSC_SCAN_CTL1_RAW_COUNT_MODE_Pos)        | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SCAN_CTL1_FLD_DEBUG_CONV_PH_SEL << MSC_SCAN_CTL1_DEBUG_CONV_PH_SEL_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SCAN_CTL1_FLD_FRAME_START_PTR << MSC_SCAN_CTL1_FRAME_START_PTR_Pos)),     \
+        .scanCtl2 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SCAN_CTL2_FLD_NUM_EPI_CYCLES << MSC_SCAN_CTL2_NUM_EPI_CYCLES_Pos)       | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SCAN_CTL2_FLD_CHOP_POL << MSC_SCAN_CTL2_CHOP_POL_Pos)                    | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SCAN_CTL2_FLD_CHOP_EVEN_HOLD_EN << MSC_SCAN_CTL2_CHOP_EVEN_HOLD_EN_Pos)), \
+        .initCtl1 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL1_FLD_NUM_INIT_CMOD_12_RAIL_CYCLES << MSC_INIT_CTL1_NUM_INIT_CMOD_12_RAIL_CYCLES_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL1_FLD_NUM_INIT_CMOD_12_SHORT_CYCLES << MSC_INIT_CTL1_NUM_INIT_CMOD_12_SHORT_CYCLES_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL1_FLD_PER_SAMPLE << MSC_INIT_CTL1_PER_SAMPLE_Pos)),                                      \
+        .initCtl2 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL2_FLD_NUM_INIT_CMOD_34_RAIL_CYCLES << MSC_INIT_CTL2_NUM_INIT_CMOD_34_RAIL_CYCLES_Pos)   | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL2_FLD_NUM_INIT_CMOD_34_SHORT_CYCLES << MSC_INIT_CTL2_NUM_INIT_CMOD_34_SHORT_CYCLES_Pos)), \
+        .initCtl3 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL3_FLD_NUM_PRO_OFFSET_CYCLES << MSC_INIT_CTL3_NUM_PRO_OFFSET_CYCLES_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL3_FLD_NUM_PRO_OFFSET_TRIPS << MSC_INIT_CTL3_NUM_PRO_OFFSET_TRIPS_Pos)    | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL3_FLD_CMOD_SEL << MSC_INIT_CTL3_CMOD_SEL_Pos)                            | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL3_FLD_INIT_MODE << MSC_INIT_CTL3_INIT_MODE_Pos)),                         \
+        .initCtl4 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL4_FLD_NUM_PRO_DUMMY_SUB_CONVS << MSC_INIT_CTL4_NUM_PRO_DUMMY_SUB_CONVS_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INIT_CTL4_FLD_NUM_PRO_WAIT_CYCLES << MSC_INIT_CTL4_NUM_PRO_WAIT_CYCLES_Pos)), \
+        .senseDutyCtl = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SENSE_DUTY_CTL_FLD_PHASE_WIDTH << MSC_SENSE_DUTY_CTL_PHASE_WIDTH_Pos)              | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_CYCLES << MSC_SENSE_DUTY_CTL_PHASE_SHIFT_CYCLES_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SENSE_DUTY_CTL_FLD_PHASE_WIDTH_SEL << MSC_SENSE_DUTY_CTL_PHASE_WIDTH_SEL_Pos)),      \
+        .sensePeriodCtl = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SENSE_PERIOD_CTL_FLD_LFSR_POLY << MSC_SENSE_PERIOD_CTL_LFSR_POLY_Pos)   | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SENSE_PERIOD_CTL_FLD_LFSR_SCALE << MSC_SENSE_PERIOD_CTL_LFSR_SCALE_Pos)), \
+        .filterCtl = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_FILTER_CTL_FLD_BIT_FORMAT << MSC_FILTER_CTL_BIT_FORMAT_Pos)   | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_FILTER_CTL_FLD_FILTER_MODE << MSC_FILTER_CTL_FILTER_MODE_Pos)), \
+        .ccompCdacCtl = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CCOMP_CDAC_CTL_FLD_SEL_CO_PRO_OFFSET << MSC_CCOMP_CDAC_CTL_SEL_CO_PRO_OFFSET_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CCOMP_CDAC_CTL_FLD_EPILOGUE_EN << MSC_CCOMP_CDAC_CTL_EPILOGUE_EN_Pos)),             \
+        .ditherCdacCtl = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_DITHER_CDAC_CTL_FLD_SEL_FL << MSC_DITHER_CDAC_CTL_SEL_FL_Pos)             | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_DITHER_CDAC_CTL_FLD_LFSR_POLY_FL << MSC_DITHER_CDAC_CTL_LFSR_POLY_FL_Pos)), \
+        .cswCtl = \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CSW_CTL_FLD_CSW_FUNC_MODE), \
+        .swSelGpio = \
+                    ((CY_CAPSENSE_SM_CSX_FULL_WAVE_GPIO_REG_SW_SEL_GPIO_FLD_SW_CSD_SENSE   << MSC_SW_SEL_GPIO_SW_CSD_SENSE_Pos)     | \
+                    (CY_CAPSENSE_SM_CSX_FULL_WAVE_GPIO_REG_SW_SEL_GPIO_FLD_SW_CSD_SHIELD   << MSC_SW_SEL_GPIO_SW_CSD_SHIELD_Pos)    | \
+                    (CY_CAPSENSE_SM_CSX_FULL_WAVE_GPIO_REG_SW_SEL_GPIO_FLD_SW_CSD_MUTUAL   << MSC_SW_SEL_GPIO_SW_CSD_MUTUAL_Pos)    | \
+                    (CY_CAPSENSE_SM_CSX_FULL_WAVE_GPIO_REG_SW_SEL_GPIO_FLD_SW_CSD_POLARITY << MSC_SW_SEL_GPIO_SW_CSD_POLARITY_Pos)  | \
+                    (CY_CAPSENSE_SM_CSX_FULL_WAVE_GPIO_REG_SW_SEL_GPIO_FLD_SW_CSD_CHARGE   << MSC_SW_SEL_GPIO_SW_CSD_CHARGE_Pos)    | \
+                    (CY_CAPSENSE_SM_CSX_FULL_WAVE_GPIO_REG_SW_SEL_GPIO_FLD_SW_DSI_CMOD     << MSC_SW_SEL_GPIO_SW_DSI_CMOD_Pos)      | \
+                    (CY_CAPSENSE_SM_CSX_FULL_WAVE_GPIO_REG_SW_SEL_GPIO_FLD_SW_DSI_CSH_TANK << MSC_SW_SEL_GPIO_SW_DSI_CSH_TANK_Pos)), \
+        .swSelCdacRe = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_RETCA << MSC_SW_SEL_CDAC_RE_SW_RETCA_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_RECB   << MSC_SW_SEL_CDAC_RE_SW_RECB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_RETV   << MSC_SW_SEL_CDAC_RE_SW_RETV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_RETG   << MSC_SW_SEL_CDAC_RE_SW_RETG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_REBV   << MSC_SW_SEL_CDAC_RE_SW_REBV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_REBG   << MSC_SW_SEL_CDAC_RE_SW_REBG_Pos)), \
+        .swSelCdacCo = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CO_FLD_SW_COTCA << MSC_SW_SEL_CDAC_CO_SW_COTCA_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CO_FLD_SW_COCB   << MSC_SW_SEL_CDAC_CO_SW_COCB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CO_FLD_SW_COTV   << MSC_SW_SEL_CDAC_CO_SW_COTV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CO_FLD_SW_COTG   << MSC_SW_SEL_CDAC_CO_SW_COTG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CO_FLD_SW_COBV   << MSC_SW_SEL_CDAC_CO_SW_COBV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CO_FLD_SW_COBG   << MSC_SW_SEL_CDAC_CO_SW_COBG_Pos)), \
+        .swSelCdacCf = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CF_FLD_SW_CFTCA << MSC_SW_SEL_CDAC_CF_SW_CFTCA_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CF_FLD_SW_CFTCB  << MSC_SW_SEL_CDAC_CF_SW_CFTCB_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CF_FLD_SW_CFTV   << MSC_SW_SEL_CDAC_CF_SW_CFTV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CF_FLD_SW_CFTG   << MSC_SW_SEL_CDAC_CF_SW_CFTG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CF_FLD_SW_CFBV   << MSC_SW_SEL_CDAC_CF_SW_CFBV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_CF_FLD_SW_CFBG   << MSC_SW_SEL_CDAC_CF_SW_CFBG_Pos)), \
+        .swSelCmod1 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CA << MSC_SW_SEL_CMOD1_SW_C1CA_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CB  << MSC_SW_SEL_CMOD1_SW_C1CB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CC  << MSC_SW_SEL_CMOD1_SW_C1CC_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CV  << MSC_SW_SEL_CMOD1_SW_C1CV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CG  << MSC_SW_SEL_CMOD1_SW_C1CG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_REF_MODE << MSC_SW_SEL_CMOD1_REF_MODE_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_ENABLED  << MSC_SW_SEL_CMOD1_ENABLED_Pos)), \
+        .swSelCmod2 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CA << MSC_SW_SEL_CMOD2_SW_C2CA_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CB  << MSC_SW_SEL_CMOD2_SW_C2CB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CC  << MSC_SW_SEL_CMOD2_SW_C2CC_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CV  << MSC_SW_SEL_CMOD2_SW_C2CV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CG  << MSC_SW_SEL_CMOD2_SW_C2CG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_REF_MODE << MSC_SW_SEL_CMOD2_REF_MODE_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_ENABLED  << MSC_SW_SEL_CMOD2_ENABLED_Pos)), \
+        .swSelCmod3 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CA << MSC_SW_SEL_CMOD3_SW_C3CA_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CB  << MSC_SW_SEL_CMOD3_SW_C3CB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CC  << MSC_SW_SEL_CMOD3_SW_C3CC_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CV  << MSC_SW_SEL_CMOD3_SW_C3CV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CG  << MSC_SW_SEL_CMOD3_SW_C3CG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_REF_MODE << MSC_SW_SEL_CMOD3_REF_MODE_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_ENABLED  << MSC_SW_SEL_CMOD3_ENABLED_Pos)), \
+        .swSelCmod4 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CA << MSC_SW_SEL_CMOD4_SW_C4CA_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CB  << MSC_SW_SEL_CMOD4_SW_C4CB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CC  << MSC_SW_SEL_CMOD4_SW_C4CC_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CV  << MSC_SW_SEL_CMOD4_SW_C4CV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CG  << MSC_SW_SEL_CMOD4_SW_C4CG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_REF_MODE << MSC_SW_SEL_CMOD4_REF_MODE_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_ENABLED  << MSC_SW_SEL_CMOD4_ENABLED_Pos)), \
+        .obsCtl = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_OBS_CTL_FLD_OBSERVE0 << MSC_OBS_CTL_OBSERVE0_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_OBS_CTL_FLD_OBSERVE1  << MSC_OBS_CTL_OBSERVE1_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_OBS_CTL_FLD_OBSERVE2  << MSC_OBS_CTL_OBSERVE2_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_OBS_CTL_FLD_OBSERVE3  << MSC_OBS_CTL_OBSERVE3_Pos)), \
+        .status1            = 0x00uL, \
+        .status2            = 0x00uL, \
+        .status3            = 0x00uL, \
+        .resultFifoStatus   = 0x00uL, \
+        .resultFifoRd       = 0x00uL, \
+        .intr = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_SUB_SAMPLE    << MSC_INTR_SUB_SAMPLE_Pos)     | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_SAMPLE         << MSC_INTR_SAMPLE_Pos)         | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_SCAN           << MSC_INTR_SCAN_Pos)           | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_INIT           << MSC_INTR_INIT_Pos)           | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_FRAME          << MSC_INTR_FRAME_Pos)          | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_FIFO_UNDERFLOW << MSC_INTR_FIFO_UNDERFLOW_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_FIFO_OVERFLOW  << MSC_INTR_FIFO_OVERFLOW_Pos)), \
+        .intrSet = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_SET_FLD_SUB_SAMPLE    << MSC_INTR_SET_SUB_SAMPLE_Pos)     | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_SET_FLD_SAMPLE         << MSC_INTR_SET_SAMPLE_Pos)         | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_SET_FLD_SCAN           << MSC_INTR_SET_SCAN_Pos)           | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_SET_FLD_INIT           << MSC_INTR_SET_INIT_Pos)           | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_SET_FLD_FRAME          << MSC_INTR_SET_FRAME_Pos)          | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_SET_FLD_FIFO_UNDERFLOW << MSC_INTR_SET_FIFO_UNDERFLOW_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_SET_FLD_FIFO_OVERFLOW  << MSC_INTR_SET_FIFO_OVERFLOW_Pos)), \
+        .intrMask = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_MASK_FLD_SUB_SAMPLE        << MSC_INTR_MASK_SUB_SAMPLE_Pos)     | \
+                        (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_MASK_FLD_SAMPLE         << MSC_INTR_MASK_SAMPLE_Pos)         | \
+                        (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_MASK_FLD_SCAN           << MSC_INTR_MASK_SCAN_Pos)           | \
+                        (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_MASK_FLD_INIT           << MSC_INTR_MASK_INIT_Pos)           | \
+                        (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_MASK_FLD_FRAME          << MSC_INTR_MASK_FRAME_Pos)          | \
+                        (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_MASK_FLD_FIFO_UNDERFLOW << MSC_INTR_MASK_FIFO_UNDERFLOW_Pos) | \
+                        (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_MASK_FLD_FIFO_OVERFLOW  << MSC_INTR_MASK_FIFO_OVERFLOW_Pos)), \
+        .intrMasked         = 0x00uL, \
+        .frameCmd = \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_FRAME_CMD_FLD_START_FRAME), \
+        .sensorConfig = \
+        { \
+            .snsSwSelCswMask2   = 0x00uL, \
+            .snsSwSelCswMask1   = 0x00uL, \
+            .snsSwSelCswMask0   = 0x00uL, \
+            .snsScanCtl         = 0x00uL, \
+            .snsCdacCtl         = 0x00uL, \
+            .snsCtl             = 0x00uL, \
+        }, \
+        .swSelCsw = \
+        { \
+            [0u]       = 0x00uL, \
+            [1u]       = 0x00uL, \
+            [2u]       = 0x00uL, \
+            [3u]       = 0x00uL, \
+            [4u]       = 0x00uL, \
+            [5u]       = 0x00uL, \
+            [6u]       = 0x00uL, \
+            [7u]       = 0x00uL, \
+            [8u]       = 0x00uL, \
+            [9u]       = 0x00uL, \
+            [10u]      = 0x00uL, \
+            [11u]      = 0x00uL, \
+            [12u]      = 0x00uL, \
+            [13u]      = 0x00uL, \
+            [14u]      = 0x00uL, \
+            [15u]      = 0x00uL, \
+            [16u]      = 0x00uL, \
+            [17u]      = 0x00uL, \
+            [18u]      = 0x00uL, \
+            [19u]      = 0x00uL, \
+            [20u]      = 0x00uL, \
+            [21u]      = 0x00uL, \
+            [22u]      = 0x00uL, \
+            [23u]      = 0x00uL, \
+            [24u]      = 0x00uL, \
+            [25u]      = 0x00uL, \
+            [26u]      = 0x00uL, \
+            [27u]      = 0x00uL, \
+            [28u]      = 0x00uL, \
+            [29u]      = 0x00uL, \
+            [30u]      = 0x00uL, \
+            [31u]      = 0x00uL, \
+        }, \
+        .swSelCswFunc = \
+        { \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_RX] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW0_RX_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_TX] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW1_TX_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_TX_NEGATIVE] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW2_NEG_TX_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_SNS] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW3_SNS_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_GND] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW4_GND_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_HIGH_Z] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW5_HIGH_Z_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_VDDA2] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW6_VDDA2_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_SHIELD] = (CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_CSW_VALUE), \
+        }, \
+        .mode = \
+        { \
+            [CY_CAPSENSE_CSD_RM_SENSING_METHOD_INDEX] = \
+            { \
+                .senseDutyCtl = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH2_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH3_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN     << MSC_MODE_SENSE_DUTY_CTL_PH_GAP_2CYCLE_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN    << MSC_MODE_SENSE_DUTY_CTL_PHX_GAP_2CYCLE_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN       << MSC_MODE_SENSE_DUTY_CTL_PHASE_SHIFT_EN_Pos)       | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL       << MSC_MODE_SENSE_DUTY_CTL_PHASE_MODE_SEL_Pos)),      \
+                .swSelCdacFl = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTCA        << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTCA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLCB         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLCB_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTV         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTG         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLBV         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLBV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLBG         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLBG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_ACTIVATION_MODE << MSC_MODE_SW_SEL_CDAC_FL_ACTIVATION_MODE_Pos)), \
+                .swSelTop = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACB     << MSC_MODE_SW_SEL_TOP_CACB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACC     << MSC_MODE_SW_SEL_TOP_CACC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CBCC     << MSC_MODE_SW_SEL_TOP_CBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBCC     << MSC_MODE_SW_SEL_TOP_MBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYA_CTL  << MSC_MODE_SW_SEL_TOP_AYA_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYB_CTL  << MSC_MODE_SW_SEL_TOP_AYB_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BYB      << MSC_MODE_SW_SEL_TOP_BYB_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SOSH     << MSC_MODE_SW_SEL_TOP_SOSH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHV      << MSC_MODE_SW_SEL_TOP_SHV_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHG      << MSC_MODE_SW_SEL_TOP_SHG_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BGRF     << MSC_MODE_SW_SEL_TOP_BGRF_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_RMF      << MSC_MODE_SW_SEL_TOP_RMF_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBF      << MSC_MODE_SW_SEL_TOP_MBF_Pos)),    \
+                .swSelComp = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCS1        << MSC_MODE_SW_SEL_COMP_CPCS1_Pos)        | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCS3        << MSC_MODE_SW_SEL_COMP_CPCS3_Pos)        | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPMA         << MSC_MODE_SW_SEL_COMP_CPMA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCA         << MSC_MODE_SW_SEL_COMP_CPCA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCB         << MSC_MODE_SW_SEL_COMP_CPCB_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCB         << MSC_MODE_SW_SEL_COMP_CMCB_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPF          << MSC_MODE_SW_SEL_COMP_CPF_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCS2        << MSC_MODE_SW_SEL_COMP_CMCS2_Pos)        | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCS4        << MSC_MODE_SW_SEL_COMP_CMCS4_Pos)        | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMV          << MSC_MODE_SW_SEL_COMP_CMV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMG          << MSC_MODE_SW_SEL_COMP_CMG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMF          << MSC_MODE_SW_SEL_COMP_CMF_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_HALF_WAVE_EN << MSC_MODE_SW_SEL_COMP_HALF_WAVE_EN_Pos)), \
+                .swSelSh = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SHG   << MSC_MODE_SW_SEL_SH_C1SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SH    << MSC_MODE_SW_SEL_SH_C1SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SHG   << MSC_MODE_SW_SEL_SH_C3SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SH    << MSC_MODE_SW_SEL_SH_C3SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SOMB    << MSC_MODE_SW_SEL_SH_SOMB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CBSO    << MSC_MODE_SW_SEL_SH_CBSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS1   << MSC_MODE_SW_SEL_SH_SPCS1_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS3   << MSC_MODE_SW_SEL_SH_SPCS3_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_FSP     << MSC_MODE_SW_SEL_SH_FSP_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CCSO    << MSC_MODE_SW_SEL_SH_CCSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_SEL << MSC_MODE_SW_SEL_SH_BUF_SEL_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_EN  << MSC_MODE_SW_SEL_SH_BUF_EN_Pos)), \
+            }, \
+            [CY_CAPSENSE_CSX_RM_SENSING_METHOD_INDEX] = \
+            { \
+                .senseDutyCtl = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH2_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH3_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN     << MSC_MODE_SENSE_DUTY_CTL_PH_GAP_2CYCLE_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN    << MSC_MODE_SENSE_DUTY_CTL_PHX_GAP_2CYCLE_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN       << MSC_MODE_SENSE_DUTY_CTL_PHASE_SHIFT_EN_Pos)       | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL       << MSC_MODE_SENSE_DUTY_CTL_PHASE_MODE_SEL_Pos)),      \
+                .swSelCdacFl = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTCA        << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTCA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLCB         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLCB_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTV         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTG         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLBV         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLBV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLBG         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLBG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_ACTIVATION_MODE << MSC_MODE_SW_SEL_CDAC_FL_ACTIVATION_MODE_Pos)), \
+                .swSelTop = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACB     << MSC_MODE_SW_SEL_TOP_CACB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACC     << MSC_MODE_SW_SEL_TOP_CACC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CBCC     << MSC_MODE_SW_SEL_TOP_CBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBCC     << MSC_MODE_SW_SEL_TOP_MBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYA_CTL  << MSC_MODE_SW_SEL_TOP_AYA_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYB_CTL  << MSC_MODE_SW_SEL_TOP_AYB_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BYB      << MSC_MODE_SW_SEL_TOP_BYB_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SOSH     << MSC_MODE_SW_SEL_TOP_SOSH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHV      << MSC_MODE_SW_SEL_TOP_SHV_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHG      << MSC_MODE_SW_SEL_TOP_SHG_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BGRF     << MSC_MODE_SW_SEL_TOP_BGRF_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_RMF      << MSC_MODE_SW_SEL_TOP_RMF_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBF      << MSC_MODE_SW_SEL_TOP_MBF_Pos)),    \
+                .swSelComp = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCS1        << MSC_MODE_SW_SEL_COMP_CPCS1_Pos)        | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCS3        << MSC_MODE_SW_SEL_COMP_CPCS3_Pos)        | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPMA         << MSC_MODE_SW_SEL_COMP_CPMA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCA         << MSC_MODE_SW_SEL_COMP_CPCA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCB         << MSC_MODE_SW_SEL_COMP_CPCB_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCB         << MSC_MODE_SW_SEL_COMP_CMCB_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPF          << MSC_MODE_SW_SEL_COMP_CPF_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCS2        << MSC_MODE_SW_SEL_COMP_CMCS2_Pos)        | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCS4        << MSC_MODE_SW_SEL_COMP_CMCS4_Pos)        | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMV          << MSC_MODE_SW_SEL_COMP_CMV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMG          << MSC_MODE_SW_SEL_COMP_CMG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMF          << MSC_MODE_SW_SEL_COMP_CMF_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_HALF_WAVE_EN << MSC_MODE_SW_SEL_COMP_HALF_WAVE_EN_Pos)), \
+                .swSelSh = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SHG   << MSC_MODE_SW_SEL_SH_C1SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SH    << MSC_MODE_SW_SEL_SH_C1SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SHG   << MSC_MODE_SW_SEL_SH_C3SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SH    << MSC_MODE_SW_SEL_SH_C3SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SOMB    << MSC_MODE_SW_SEL_SH_SOMB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CBSO    << MSC_MODE_SW_SEL_SH_CBSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS1   << MSC_MODE_SW_SEL_SH_SPCS1_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS3   << MSC_MODE_SW_SEL_SH_SPCS3_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_FSP     << MSC_MODE_SW_SEL_SH_FSP_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CCSO    << MSC_MODE_SW_SEL_SH_CCSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_SEL << MSC_MODE_SW_SEL_SH_BUF_SEL_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_EN  << MSC_MODE_SW_SEL_SH_BUF_EN_Pos)), \
+            }, \
+            [CY_CAPSENSE_CSD_DITHERING_SENSING_METHOD_INDEX] = \
+            { \
+                .senseDutyCtl = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH2_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH3_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN     << MSC_MODE_SENSE_DUTY_CTL_PH_GAP_2CYCLE_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN    << MSC_MODE_SENSE_DUTY_CTL_PHX_GAP_2CYCLE_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN       << MSC_MODE_SENSE_DUTY_CTL_PHASE_SHIFT_EN_Pos)       | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL       << MSC_MODE_SENSE_DUTY_CTL_PHASE_MODE_SEL_Pos)),      \
+                .swSelCdacFl = \
+                        ((CY_CAPSENSE_SM_CSD_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTCA        << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTCA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLCB         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLCB_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTV         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTG         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLBV         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLBV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLBG         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLBG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_ACTIVATION_MODE << MSC_MODE_SW_SEL_CDAC_FL_ACTIVATION_MODE_Pos)), \
+                .swSelTop = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACB     << MSC_MODE_SW_SEL_TOP_CACB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACC     << MSC_MODE_SW_SEL_TOP_CACC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CBCC     << MSC_MODE_SW_SEL_TOP_CBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBCC     << MSC_MODE_SW_SEL_TOP_MBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYA_CTL  << MSC_MODE_SW_SEL_TOP_AYA_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYB_CTL  << MSC_MODE_SW_SEL_TOP_AYB_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BYB      << MSC_MODE_SW_SEL_TOP_BYB_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SOSH     << MSC_MODE_SW_SEL_TOP_SOSH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHV      << MSC_MODE_SW_SEL_TOP_SHV_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHG      << MSC_MODE_SW_SEL_TOP_SHG_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BGRF     << MSC_MODE_SW_SEL_TOP_BGRF_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_RMF      << MSC_MODE_SW_SEL_TOP_RMF_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBF      << MSC_MODE_SW_SEL_TOP_MBF_Pos)),    \
+                .swSelComp = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCS1        << MSC_MODE_SW_SEL_COMP_CPCS1_Pos)        | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCS3        << MSC_MODE_SW_SEL_COMP_CPCS3_Pos)        | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPMA         << MSC_MODE_SW_SEL_COMP_CPMA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCA         << MSC_MODE_SW_SEL_COMP_CPCA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCB         << MSC_MODE_SW_SEL_COMP_CPCB_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCB         << MSC_MODE_SW_SEL_COMP_CMCB_Pos)         | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPF          << MSC_MODE_SW_SEL_COMP_CPF_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCS2        << MSC_MODE_SW_SEL_COMP_CMCS2_Pos)        | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCS4        << MSC_MODE_SW_SEL_COMP_CMCS4_Pos)        | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMV          << MSC_MODE_SW_SEL_COMP_CMV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMG          << MSC_MODE_SW_SEL_COMP_CMG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMF          << MSC_MODE_SW_SEL_COMP_CMF_Pos)          | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_HALF_WAVE_EN << MSC_MODE_SW_SEL_COMP_HALF_WAVE_EN_Pos)), \
+                .swSelSh = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SHG   << MSC_MODE_SW_SEL_SH_C1SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SH    << MSC_MODE_SW_SEL_SH_C1SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SHG   << MSC_MODE_SW_SEL_SH_C3SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SH    << MSC_MODE_SW_SEL_SH_C3SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SOMB    << MSC_MODE_SW_SEL_SH_SOMB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CBSO    << MSC_MODE_SW_SEL_SH_CBSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS1   << MSC_MODE_SW_SEL_SH_SPCS1_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS3   << MSC_MODE_SW_SEL_SH_SPCS3_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_FSP     << MSC_MODE_SW_SEL_SH_FSP_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CCSO    << MSC_MODE_SW_SEL_SH_CCSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_SEL << MSC_MODE_SW_SEL_SH_BUF_SEL_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_EN  << MSC_MODE_SW_SEL_SH_BUF_EN_Pos)), \
+            }, \
+            [CY_CAPSENSE_CSX_DITHERING_SENSING_METHOD_INDEX] = \
+            { \
+                .senseDutyCtl = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH2_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH3_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN     << MSC_MODE_SENSE_DUTY_CTL_PH_GAP_2CYCLE_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN    << MSC_MODE_SENSE_DUTY_CTL_PHX_GAP_2CYCLE_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN       << MSC_MODE_SENSE_DUTY_CTL_PHASE_SHIFT_EN_Pos)       | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL       << MSC_MODE_SENSE_DUTY_CTL_PHASE_MODE_SEL_Pos)),      \
+                .swSelCdacFl = \
+                        ((CY_CAPSENSE_SM_CSX_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTCA        << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTCA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLCB         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLCB_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTV         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLTG         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLTG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLBV         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLBV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_SW_FLBG         << MSC_MODE_SW_SEL_CDAC_FL_SW_FLBG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_DITH_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_CDAC_FL_FLD_ACTIVATION_MODE << MSC_MODE_SW_SEL_CDAC_FL_ACTIVATION_MODE_Pos)), \
+                .swSelTop = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACB     << MSC_MODE_SW_SEL_TOP_CACB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACC     << MSC_MODE_SW_SEL_TOP_CACC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CBCC     << MSC_MODE_SW_SEL_TOP_CBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBCC     << MSC_MODE_SW_SEL_TOP_MBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYA_CTL  << MSC_MODE_SW_SEL_TOP_AYA_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYB_CTL  << MSC_MODE_SW_SEL_TOP_AYB_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BYB      << MSC_MODE_SW_SEL_TOP_BYB_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SOSH     << MSC_MODE_SW_SEL_TOP_SOSH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHV      << MSC_MODE_SW_SEL_TOP_SHV_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHG      << MSC_MODE_SW_SEL_TOP_SHG_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BGRF     << MSC_MODE_SW_SEL_TOP_BGRF_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_RMF      << MSC_MODE_SW_SEL_TOP_RMF_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBF      << MSC_MODE_SW_SEL_TOP_MBF_Pos)),    \
+                .swSelComp = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCS1        << MSC_MODE_SW_SEL_COMP_CPCS1_Pos)        | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCS3        << MSC_MODE_SW_SEL_COMP_CPCS3_Pos)        | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPMA         << MSC_MODE_SW_SEL_COMP_CPMA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCA         << MSC_MODE_SW_SEL_COMP_CPCA_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPCB         << MSC_MODE_SW_SEL_COMP_CPCB_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCB         << MSC_MODE_SW_SEL_COMP_CMCB_Pos)         | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CPF          << MSC_MODE_SW_SEL_COMP_CPF_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCS2        << MSC_MODE_SW_SEL_COMP_CMCS2_Pos)        | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMCS4        << MSC_MODE_SW_SEL_COMP_CMCS4_Pos)        | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMV          << MSC_MODE_SW_SEL_COMP_CMV_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMG          << MSC_MODE_SW_SEL_COMP_CMG_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_CMF          << MSC_MODE_SW_SEL_COMP_CMF_Pos)          | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_COMP_FLD_HALF_WAVE_EN << MSC_MODE_SW_SEL_COMP_HALF_WAVE_EN_Pos)), \
+                .swSelSh = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SHG   << MSC_MODE_SW_SEL_SH_C1SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SH    << MSC_MODE_SW_SEL_SH_C1SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SHG   << MSC_MODE_SW_SEL_SH_C3SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SH    << MSC_MODE_SW_SEL_SH_C3SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SOMB    << MSC_MODE_SW_SEL_SH_SOMB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CBSO    << MSC_MODE_SW_SEL_SH_CBSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS1   << MSC_MODE_SW_SEL_SH_SPCS1_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS3   << MSC_MODE_SW_SEL_SH_SPCS3_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_FSP     << MSC_MODE_SW_SEL_SH_FSP_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CCSO    << MSC_MODE_SW_SEL_SH_CCSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_SEL << MSC_MODE_SW_SEL_SH_BUF_SEL_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_EN  << MSC_MODE_SW_SEL_SH_BUF_EN_Pos)), \
+            }, \
+        }, \
+    }
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* CY_IP_M0S8MSCV3 */
+
+#endif /* CY_CAPSENSE_GENERATOR_V3_H */
+
+
+/* [] END OF FILE */

+ 364 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_gesture_lib.h

@@ -0,0 +1,364 @@
+/***************************************************************************//**
+* \file cy_capsense_gesture_lib.h
+* \version 3.0
+*
+* \brief
+* Provides the gesture interface.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#ifndef CY_CAPSENSE_GESTURE_LIB_H
+#define CY_CAPSENSE_GESTURE_LIB_H
+
+#include <stdint.h>
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/******************************************************************************/
+/** \addtogroup group_capsense_gesture_structures *//** \{ */
+/******************************************************************************/
+
+/** Gesture configuration structure */
+typedef struct
+{
+    /* Common parameters */
+    uint16_t resolutionX;                                       /**< Widget maximum position X-axis */
+    uint16_t resolutionY;                                       /**< Widget maximum position Y-axis */
+
+    /* Enabled gesture */
+    uint16_t gestureEnableMask;                                 /**< Enabled gesture mask */
+
+    /* Timeout */
+    uint16_t flickTimeoutMax;                                   /**< Flick maximum timeout */
+    uint16_t edgeTimeoutMax;                                    /**< Edge Swipe maximum timeout */
+    uint16_t clickTimeoutMax;                                   /**< Click maximum timeout */
+    uint16_t clickTimeoutMin;                                   /**< Click minimum timeout */
+    uint16_t secondClickIntervalMax;                            /**< Second Click maximum interval */
+    uint16_t secondClickIntervalMin;                            /**< Second Click minimum interval */
+
+    /* Distance */
+    uint16_t zoomDistanceMin;                                   /**< Zoom minimum distance */
+    uint16_t flickDistanceMin;                                  /**< Flick minimum distance */
+    uint16_t scrollDistanceMin;                                 /**< Scroll minimum distance */
+    uint16_t rotateDistanceMin;                                 /**< Rotate minimum distance */
+    uint16_t edgeDistanceMin;                                   /**< Edge Swipe minimum distance */
+    uint8_t secondClickDistanceMax;                             /**< Second Click maximum distance */
+    uint8_t clickDistanceMax;                                   /**< Click maximum distance */
+
+    /* Debounce */
+    uint8_t zoomDebounce;                                       /**< Zoom debounce */
+    uint8_t scrollDebounce;                                     /**< Scroll debounce */
+    uint8_t rotateDebounce;                                     /**< Rotate debounce */
+
+    /* Edge Swipe Specific */
+    uint8_t edgeAngleMax;                                       /**< Edge Swipe maximum angle */
+    uint8_t edgeEdgeSize;                                       /**< Edge Swipe border size */
+} cy_stc_capsense_gesture_config_t;
+
+/** Gesture position structure */
+typedef struct
+{
+    uint16_t x;                                                 /**< X axis position */
+    uint16_t y;                                                 /**< Y axis position */
+} cy_stc_capsense_gesture_position_t;
+
+/** Gesture One Finger Single Click context structure */
+typedef struct
+{
+    uint32_t touchStartTime1;                                   /**< Touchdown time */
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position */
+    uint8_t state;                                              /**< Gesture state */
+} cy_stc_capsense_ofsc_context_t;
+
+/** Gesture One Finger Double Click context structure */
+typedef struct
+{
+    uint32_t touchStartTime1;                                   /**< Touchdown time */
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position */
+    uint8_t state;                                              /**< Gesture state */
+} cy_stc_capsense_ofdc_context_t;
+
+/** Gesture One Finger Click and Drag context structure */
+typedef struct
+{
+    uint32_t touchStartTime1;                                   /**< Touchdown time */
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position */
+    uint8_t state;                                              /**< Gesture state */
+} cy_stc_capsense_ofcd_context_t;
+
+/** Gesture Two Finger Single Click context structure */
+typedef struct
+{
+    uint32_t touchStartTime1;                                   /**< Touchdown time of the first touch */
+    uint32_t touchStartTime2;                                   /**< Touchdown time of the second touch */
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position of the first touch */
+    cy_stc_capsense_gesture_position_t touchStartPosition2;     /**< Touchdown position of the second touch */
+    uint8_t state;                                              /**< Gesture state */
+} cy_stc_capsense_tfsc_context_t;
+
+/** Gesture One Finger Scroll context structure */
+typedef struct
+{
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position */
+    uint8_t state;                                              /**< Gesture state */
+    uint8_t debounce;                                           /**< Gesture debounce counter */
+    uint8_t direction;                                          /**< Last reported direction */
+} cy_stc_capsense_ofsl_context_t;
+
+/** Gesture Two Finger Scroll context structure */
+typedef struct
+{
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position of the first touch */
+    cy_stc_capsense_gesture_position_t touchStartPosition2;     /**< Touchdown position of the second touch */
+    uint8_t state;                                              /**< Gesture state */
+    uint8_t debounce;                                           /**< Gesture debounce counter */
+    uint8_t direction;                                          /**< Last reported direction */
+} cy_stc_capsense_tfsl_context_t;
+
+/** Gesture One Finger Flick context structure */
+typedef struct
+{
+    uint32_t touchStartTime1;                                   /**< Touchdown time */
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position */
+    uint8_t state;                                              /**< Gesture state */
+} cy_stc_capsense_offl_context_t;
+
+/** Gesture One Finger Edge Swipe context structure */
+typedef struct
+{
+    uint32_t touchStartTime1;                                   /**< Touchdown time */
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position */
+    uint8_t state;                                              /**< Gesture state */
+    uint8_t edge;                                               /**< Detected edge */
+} cy_stc_capsense_ofes_context_t;
+
+/** Gesture Two Finger Zoom context structure */
+typedef struct
+{
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position of the first touch */
+    cy_stc_capsense_gesture_position_t touchStartPosition2;     /**< Touchdown position of the second touch */
+    uint16_t distanceX;                                         /**< History of X-axis displacement */
+    uint16_t distanceY;                                         /**< History of Y-axis displacement */
+    uint8_t state;                                              /**< Gesture state */
+    uint8_t debounce;                                           /**< Gesture debounce counter */
+} cy_stc_capsense_tfzm_context_t;
+
+/** Gesture One Finger Rotate context structure */
+typedef struct
+{
+    cy_stc_capsense_gesture_position_t touchStartPosition1;     /**< Touchdown position */
+    uint8_t state;                                              /**< Gesture state */
+    uint8_t history;                                            /**< History of detected movements */
+    uint8_t debounce;                                           /**< Gesture debounce counter */
+} cy_stc_capsense_ofrt_context_t;
+
+/** Gesture global context structure */
+typedef struct
+{
+    cy_stc_capsense_gesture_position_t position1;               /**< Current position of the first touch */
+    cy_stc_capsense_gesture_position_t positionLast1;           /**< Previous position of the first touch */
+    cy_stc_capsense_gesture_position_t position2;               /**< Current position of the second touch */
+    cy_stc_capsense_gesture_position_t positionLast2;           /**< Previous position of the second touch */
+
+    uint32_t timestamp;                                         /**< Current timestamp */
+    uint16_t detected;                                          /**< Detected gesture mask */
+    uint16_t direction;                                         /**< Mask of direction of detected gesture */
+
+    cy_stc_capsense_ofrt_context_t ofrtContext;                 /**< One-finger rotate gesture context */
+    cy_stc_capsense_ofsl_context_t ofslContext;                 /**< One-finger scroll gesture context */
+    cy_stc_capsense_tfzm_context_t tfzmContext;                 /**< Two-finger zoom gesture context */
+    cy_stc_capsense_tfsc_context_t tfscContext;                 /**< Two-finger single click gesture context */
+    cy_stc_capsense_ofes_context_t ofesContext;                 /**< One-finger edge swipe gesture context */
+    cy_stc_capsense_offl_context_t offlContext;                 /**< One-finger flick gesture context */
+    cy_stc_capsense_ofsc_context_t ofscContext;                 /**< One-finger single click gesture context */
+    cy_stc_capsense_ofdc_context_t ofdcContext;                 /**< One-finger double click gesture context */
+    cy_stc_capsense_ofcd_context_t ofcdContext;                 /**< One-finger click and drag gesture context */
+    cy_stc_capsense_tfsl_context_t tfslContext;                 /**< Two-finger scroll gesture context */
+
+    uint8_t numPosition;                                        /**< Current number of touches */
+    uint8_t numPositionLast;                                    /**< Previous number of touches */
+} cy_stc_capsense_gesture_context_t;
+
+/** \} */
+
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_Gesture_ResetState
+****************************************************************************//**
+*
+* Initializes internal variables and states.
+*
+* \param context
+* The pointer to the gesture context structure
+* \ref cy_stc_capsense_gesture_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_Gesture_ResetState(
+                cy_stc_capsense_gesture_context_t * context);
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_Gesture_Decode
+****************************************************************************//**
+*
+* Decodes all enabled gestures. This function is called each scanning cycle.
+*
+* \param timestamp
+* Current timestamp.
+*
+* \param touchNumber
+* The number of touches. Also this parameter defines the size of position array.
+*
+* \param position
+* The pointer to the array of positions \ref cy_stc_capsense_gesture_position_t.
+*
+* \param config
+* The pointer to the gesture configuration structure
+* \ref cy_stc_capsense_gesture_config_t.
+*
+* \param context
+* The pointer to the gesture context structure
+* \ref cy_stc_capsense_gesture_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_Gesture_Decode(
+                uint32_t timestamp,
+                uint32_t touchNumber,
+                const cy_stc_capsense_gesture_position_t * position,
+                const cy_stc_capsense_gesture_config_t * config,
+                cy_stc_capsense_gesture_context_t * context);
+/** \} \endcond */
+
+/*******************************************************************************
+* Macros
+*******************************************************************************/
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_gesture *//** \{ */
+/******************************************************************************/
+/* Enable and Detection */
+/** No gesture detected */
+#define CY_CAPSENSE_GESTURE_NO_GESTURE                      (0x00u)
+/** All gestures enable / detection mask */
+#define CY_CAPSENSE_GESTURE_ALL_GESTURES_MASK               (0x03FFu)
+/** Gesture enable filtering mask */
+#define CY_CAPSENSE_GESTURE_FILTERING_MASK                  (0x8000u)
+/** Detection mask of Touchdown */
+#define CY_CAPSENSE_GESTURE_TOUCHDOWN_MASK                  (0x2000u)
+/** Detection mask of Lift Off */
+#define CY_CAPSENSE_GESTURE_LIFTOFF_MASK                    (0x4000u)
+
+/** Enable / detection mask of one-finger single click gesture */
+#define CY_CAPSENSE_GESTURE_ONE_FNGR_SINGLE_CLICK_MASK      (0x0001u)
+/** Enable / detection mask of one-finger double click gesture */
+#define CY_CAPSENSE_GESTURE_ONE_FNGR_DOUBLE_CLICK_MASK      (0x0002u)
+/** Enable / detection mask of one-finger click and drag gesture */
+#define CY_CAPSENSE_GESTURE_ONE_FNGR_CLICK_DRAG_MASK        (0x0004u)
+/** Enable / detection mask of two-finger single click gesture */
+#define CY_CAPSENSE_GESTURE_TWO_FNGR_SINGLE_CLICK_MASK      (0x0008u)
+/** Enable / detection mask of one-finger scroll gesture */
+#define CY_CAPSENSE_GESTURE_ONE_FNGR_SCROLL_MASK            (0x0010u)
+/** Enable / detection mask of two-finger scroll gesture */
+#define CY_CAPSENSE_GESTURE_TWO_FNGR_SCROLL_MASK            (0x0020u)
+/** Enable / detection mask of one-finger edge swipe gesture */
+#define CY_CAPSENSE_GESTURE_ONE_FNGR_EDGE_SWIPE_MASK        (0x0040u)
+/** Enable / detection mask of one-finger flick gesture */
+#define CY_CAPSENSE_GESTURE_ONE_FNGR_FLICK_MASK             (0x0080u)
+/** Enable / detection mask of one-finger rotate gesture */
+#define CY_CAPSENSE_GESTURE_ONE_FNGR_ROTATE_MASK            (0x0100u)
+/** Enable / detection mask of two-finger zoom gesture */
+#define CY_CAPSENSE_GESTURE_TWO_FNGR_ZOOM_MASK              (0x0200u)
+
+/* Direction Offsets */
+/** Offset of direction of one-finger scroll gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_OFFSET_ONE_SCROLL     (0x00u)
+/** Offset of direction of two-finger scroll gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_OFFSET_TWO_SCROLL     (0x02u)
+/** Offset of direction of one-finger edge swipe gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_OFFSET_ONE_EDGE       (0x04u)
+/** Offset of direction of one-finger rotate gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_OFFSET_ONE_ROTATE     (0x06u)
+/** Offset of direction of two-finger zoom gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_OFFSET_TWO_ZOOM       (0x07u)
+/** Offset of direction of one-finger flick gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_OFFSET_ONE_FLICK      (0x08u)
+
+/* Direction Masks */
+/** Mask of direction of one-finger scroll gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_MASK_ONE_SCROLL       (0x0003u)
+/** Mask of direction of two-finger scroll gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_MASK_TWO_SCROLL       (0x000Cu)
+/** Mask of direction of one-finger edge swipe gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_MASK_ONE_EDGE         (0x0030u)
+/** Mask of direction of one-finger rotate gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_MASK_ONE_ROTATE       (0x0040u)
+/** Mask of direction of two-finger zoom gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_MASK_TWO_ZOOM         (0x0080u)
+/** Mask of direction of one-finger flick gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_MASK_ONE_FLICK        (0x0700u)
+
+/** An extra direction offset returned by Cy_CapSense_DecodeWidgetGestures() */
+#define CY_CAPSENSE_GESTURE_DIRECTION_OFFSET                (16u)
+
+/* Direction */
+/** CLOCKWISE direction of Rotate gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_CW                    (0x00u)
+/** COUNTER CLOCKWISE direction of Rotate gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_CCW                   (0x01u)
+
+/** ZOOM-IN direction of Zoom gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_IN                    (0x00u)
+/** ZOOM-OUT direction of Zoom gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_OUT                   (0x01u)
+
+/** UP direction of Scroll, Flick and Edge Swipe gestures */
+#define CY_CAPSENSE_GESTURE_DIRECTION_UP                    (0x00u)
+/** DOWN direction of Scroll, Flick and Edge Swipe gestures */
+#define CY_CAPSENSE_GESTURE_DIRECTION_DOWN                  (0x01u)
+/** RIGHT direction of Scroll, Flick and Edge Swipe gestures */
+#define CY_CAPSENSE_GESTURE_DIRECTION_RIGHT                 (0x02u)
+/** LEFT direction of Scroll, Flick and Edge Swipe gestures */
+#define CY_CAPSENSE_GESTURE_DIRECTION_LEFT                  (0x03u)
+/** UP-RIGHT direction of Flick gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_UP_RIGHT              (0x04u)
+/** DOWN-LEFT direction of Flick gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_DOWN_LEFT             (0x05u)
+/** DOWN-RIGHT direction of Flick gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_DOWN_RIGHT            (0x06u)
+/** UP-LEFT direction of Flick gesture */
+#define CY_CAPSENSE_GESTURE_DIRECTION_UP_LEFT               (0x07u)
+
+/** \} */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+#endif /* CY_CAPSENSE_GESTURE_LIB_H */
+
+
+/* [] END OF FILE */

+ 629 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_lib.h

@@ -0,0 +1,629 @@
+/***************************************************************************//**
+* \file cy_capsense_lib.h
+* \version 3.0
+*
+* \brief
+* The file contains application programming interface to the CAPSENSE&trade; library.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_LIB_H)
+#define CY_CAPSENSE_LIB_H
+
+#include "cy_syslib.h"
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/*******************************************************************************
+* Public definitions
+*******************************************************************************/
+
+/******************************************************************************/
+/** \addtogroup group_capsense_macros_touch *//** \{ */
+/******************************************************************************/
+/** No touch detected */
+#define CY_CAPSENSE_ADVANCED_CENTROID_NO_TOUCHES                        (0x00u)
+/** An error in touch calculation or number of detected touches is above supported touches */
+#define CY_CAPSENSE_ADVANCED_CENTROID_POSITION_ERROR                    (0xFFu)
+/** \} */
+
+
+/*******************************************************************************
+* Structures
+*******************************************************************************/
+
+/******************************************************************************/
+/** \addtogroup group_capsense_structures *//** \{ */
+/******************************************************************************/
+
+/** Declares Adaptive Filter configuration parameters */
+typedef struct
+{
+    uint8_t maxK;                                   /**< Maximum filter coefficient */
+    uint8_t minK;                                   /**< Minimum filter coefficient */
+    uint8_t noMovTh;                                /**< No-movement threshold */
+    uint8_t littleMovTh;                            /**< Little movement threshold */
+    uint8_t largeMovTh;                             /**< Large movement threshold */
+    uint8_t divVal;                                 /**< Divisor value */
+    uint8_t reserved0;                              /**< Reserved field */
+    uint8_t reserved1;                              /**< Reserved field */
+} cy_stc_capsense_adaptive_filter_config_t;
+
+/** Declares Advanced Centroid configuration parameters */
+typedef struct
+{
+    uint16_t fingerTh;                              /**< Finger threshold of widget */
+    uint16_t penultimateTh;                         /**< Penultimate threshold */
+    uint16_t virtualSnsTh;                          /**< Virtual sensor threshold */
+    uint16_t resolutionX;                           /**< X axis maximum position */
+    uint16_t resolutionY;                           /**< Y axis maximum position */
+    uint8_t crossCouplingTh;                        /**< Cross-coupling threshold */
+    uint8_t snsCountX;                              /**< Number of segments on X axis */
+    uint8_t snsCountY;                              /**< Number of segments on Y axis */
+    uint8_t edgeCorrectionEn;                       /**< Edge correction enabled */
+    uint8_t twoFingersEn;                           /**< Two-finger detection enabled */
+} cy_stc_capsense_advanced_centroid_config_t;
+
+/** Declares position structure that keep information of a single touch.
+* Depending on a widget type each structure field keeps the following
+* information:
+*
+* <table class="doxtable">
+*   <tr>
+*     <th>Structure Field</th>
+*     <th>Slider</th>
+*     <th>Matrix Buttons</th>
+*     <th>CSD Touchpad</th>
+*     <th>CSX Touchpad</th>
+*   </tr>
+*   <tr>
+*     <td>x</td>
+*     <td>X-axis position</td>
+*     <td>Active Column</td>
+*     <td>X-axis position</td>
+*     <td>X-axis position</td>
+*   </tr>
+*   <tr>
+*     <td>y</td>
+*     <td>Reserved</td>
+*     <td>Active Row</td>
+*     <td>Y-axis position</td>
+*     <td>Y-axis position</td>
+*   </tr>
+*   <tr>
+*     <td>z</td>
+*     <td>Reserved</td>
+*     <td>Reserved</td>
+*     <td>Reserved</td>
+*     <td>MSB = Age of touch; LSB = Z-value</td>
+*   </tr>
+*   <tr>
+*     <td>id</td>
+*     <td>Reserved</td>
+*     <td>Logical number of button</td>
+*     <td>Reserved</td>
+*     <td>MSB = Debounce; LSB = touch ID</td>
+*   </tr>
+* </table>
+*/
+typedef struct
+{
+    uint16_t x;                                     /**< X position */
+    uint16_t y;                                     /**< Y position */
+    uint16_t z;                                     /**< Z value */
+    uint16_t id;                                    /**< ID of touch */
+} cy_stc_capsense_position_t;
+
+/** Declares touch structure used to store positions of Touchpad, Matrix buttons and Slider widgets */
+typedef struct
+{
+    cy_stc_capsense_position_t * ptrPosition;       /**< Pointer to the array containing the position information.
+                                                         A number of elements is defined by numPosition. */
+    uint8_t numPosition;                            /**< Total number of detected touches on a widget:
+                                                    *    * 0 - no touch is detected
+                                                    *    * 1 - a single touch is detected
+                                                    *    * 2 - two touches are detected
+                                                    *    * 3 - three touches are detected
+                                                    *    * CY_CAPSENSE_POSITION_MULTIPLE - multiple touches are detected
+                                                    *        and information in position structure should be ignored.
+                                                    */
+} cy_stc_capsense_touch_t;
+
+/** Declares HW smart sensing algorithm data structure for CSD widgets for fourth-generation CAPSENSE&trade; */
+typedef struct
+{
+    uint32_t sensorCap;                             /**< Sensor parasitic capacitance in fF 10^-15 */
+    uint32_t iDacGain;                              /**< IDAC gain in pA */
+    uint16_t * ptrSenseClk;                         /**< Pointer to SnsClk divider */
+    uint16_t * sigPFC;                              /**< Pointer to sigPFC value (Signal Per Finger Capacitance) */
+    uint16_t snsClkConstantR;                       /**< Resistance in series to a sensor */
+    uint16_t vRef;                                  /**< Vref in mVolts  */
+    uint16_t fingerCap;                             /**< Finger capacitance in fF 10^-15 (Set in Basic tab in pF 10^-12) */
+    uint16_t snsClkInputClock;                      /**< Frequency for sense clock divider in kHz */
+    uint16_t calTarget;                             /**< Calibration target in percentage */
+    uint8_t iDacMod;                                /**< Modulation idac code */
+    uint8_t iDacComp;                               /**< Compensation idac code */
+} cy_stc_capsense_auto_tune_config_t;
+
+/** Declares HW smart sensing algorithm data structure for CSD widgets for fifth-generation CAPSENSE&trade; */
+typedef struct
+{
+    uint32_t snsCapacitance;                        /**< Sensor parasitic capacitance in fF 10^-15 */
+    uint32_t modClock;                              /**< Modulation clock frequency in Hz */
+    uint16_t nSub0;                                 /**< Base number of sub-conversions */
+    uint16_t nSub1;                                 /**< Final number of sub-conversions */
+    uint16_t raw;                                   /**< Sensor raw counts */
+    uint16_t snsResistance;                         /**< Resistance in series to a sensor */
+    uint16_t kRef0;                                 /**< Base sense frequency */
+    uint16_t kRef1;                                 /**< Final sense frequency */
+    uint16_t fingerCap;                             /**< Finger capacitance in fF 10^-15 (Set in Basic tab in pF 10^-12) */
+    uint16_t sigPFC;                                /**< sigPFC value (Signal Per Finger Capacitance) */
+    uint8_t refCdac;                                /**< Reference CAP DAC code */
+    uint8_t correctionCoeff;                        /**< Correction coefficient for CTRL_MUX mode */
+} cy_stc_capsense_hw_smartsense_config_t;
+
+/** Declares Noise envelope data structure for CSD widgets when smart sensing algorithm is enabled */
+typedef struct
+{
+    uint16_t param0;                                /**< Parameter 0 configuration */
+    uint16_t param1;                                /**< Parameter 1 configuration */
+    uint16_t param2;                                /**< Parameter 2 configuration */
+    uint16_t param3;                                /**< Parameter 3 configuration */
+    uint16_t param4;                                /**< Parameter 4 configuration */
+    uint8_t  param5;                                /**< Parameter 5 configuration */
+    uint8_t  param6;                                /**< Parameter 6 configuration */
+} cy_stc_capsense_smartsense_csd_noise_envelope_t;
+
+/** Declares Update Thresholds structure */
+typedef struct
+{
+    uint16_t fingerTh;                              /**< Widget finger threshold */
+    uint8_t  noiseTh;                               /**< Widget noise threshold */
+    uint8_t  nNoiseTh;                              /**< Widget negative noise threshold */
+    uint8_t  hysteresis;                            /**< Widget hysteresis for the signal crossing finger threshold */
+} cy_stc_capsense_smartsense_update_thresholds_t;
+
+/** Declares Ballistics Multiplier Configuration data structure */
+typedef struct
+{
+    uint8_t  accelCoeff;                            /**< Acceleration Coefficient */
+    uint8_t  speedCoeff;                            /**< Speed Coefficient */
+    uint8_t  divisorValue;                          /**< Divisor Value */
+    uint8_t  speedThresholdX;                       /**< Speed Threshold X */
+    uint8_t  speedThresholdY;                       /**< Speed Threshold Y */
+    uint8_t  reserved0;                             /**< Reserved field */
+    uint8_t  reserved1;                             /**< Reserved field */
+    uint8_t  reserved2;                             /**< Reserved field */
+} cy_stc_capsense_ballistic_config_t;
+
+/** Declares Ballistics Multiplier Configuration data structure */
+typedef struct
+{
+    uint32_t currentTimestamp;                      /**< Current timestamp */
+    uint32_t oldTimestamp;                          /**< Previous timestamp */
+    int32_t deltaXfrac;                             /**< Fraction of X-axis displacement */
+    int32_t deltaYfrac;                             /**< Fraction of Y-axis displacement */
+    uint16_t x;                                     /**< X-axis position */
+    uint16_t y;                                     /**< Y-axis position */
+    uint8_t touchNumber;                            /**< Current number of touches */
+    uint8_t oldTouchNumber;                         /**< Previous number of touches */
+    uint8_t reserved0;                              /**< Reserved field */
+    uint8_t reserved1;                              /**< Reserved field */
+} cy_stc_capsense_ballistic_context_t;
+
+/** Declares Ballistic Displacement structure */
+typedef struct
+{
+    int16_t deltaX;                                 /**< X-axis displacement */
+    int16_t deltaY;                                 /**< Y-axis displacement */
+} cy_stc_capsense_ballistic_delta_t;
+
+/** \} */
+
+/** Declares ALP filter data structure */
+typedef struct
+{
+    uint32_t dataParam0;                            /**< Parameter 0 context */
+    uint16_t dataParam1;                            /**< Parameter 1 context */
+    uint16_t dataParam2;                            /**< Parameter 2 context */
+    uint16_t dataParam3;                            /**< Parameter 3 context */
+    uint16_t dataParam4;                            /**< Parameter 4 context */
+    uint16_t dataParam5;                            /**< Parameter 5 context */
+    uint16_t dataParam6;                            /**< Parameter 6 context */
+    uint8_t dataParam7;                             /**< Parameter 7 context */
+} cy_stc_capsense_alp_fltr_channel_t;
+
+/** Declares ALP filter configuration structure */
+typedef struct
+{
+    uint16_t configParam0;                          /**< Parameter 0 configuration */
+    uint16_t configParam1;                          /**< Parameter 1 configuration */
+    uint16_t configParam2;                          /**< Parameter 2 configuration */
+    uint8_t configParam3;                           /**< Parameter 3 configuration */
+    uint8_t configParam4;                           /**< Parameter 4 configuration */
+    uint8_t configParam5;                           /**< Parameter 5 configuration */
+} cy_stc_capsense_alp_fltr_config_t;
+
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_AdaptiveFilterInitialize_Lib
+****************************************************************************//**
+*
+* Initializes the Adaptive Filter context structure by writing default
+* adaptive coefficient for the AIIR filter.
+*
+* \param config
+* The pointer to the configuration structure of the Adaptive Filter.
+*
+* \param context
+* The pointer to the context structure of the Adaptive Filter.
+*
+*******************************************************************************/
+void Cy_CapSense_AdaptiveFilterInitialize_Lib(
+                const cy_stc_capsense_adaptive_filter_config_t * config,
+                cy_stc_capsense_position_t * context);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_AdaptiveFilterRun_Lib
+****************************************************************************//**
+*
+* This function runs the Adaptive Filter algorithm for the centroid position.
+*
+* Equation: result = ((k * curPos) + ((divisor-k) * prevPos)) / divisor
+* where k is adaptive coefficient.
+*
+* The function supposes that the filter history is updated at first touch
+* outside of the library. I.e. at the first touchdown the filter history has
+* be initialized by touch positions before calling this function.
+*
+* \param config
+* The pointer to the configuration structure of the Adaptive Filter.
+*
+* \param context
+* The pointer to the context structure of the Adaptive Filter.
+*
+* \param currentX
+* The pointer to X position.
+*
+* \param currentY
+* The pointer to Y position.
+*
+*******************************************************************************/
+void Cy_CapSense_AdaptiveFilterRun_Lib(
+                const cy_stc_capsense_adaptive_filter_config_t * config,
+                cy_stc_capsense_position_t * context,
+                uint32_t * currentX,
+                uint32_t * currentY);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_AdvancedCentroidGetTouchCoordinates_Lib
+****************************************************************************//**
+*
+* This API calculates the centroids for up to two fingers.
+*
+* \param config
+* The pointer to the configuration structure of the Advanced Centroid.
+*
+* \param ptrSns
+* The pointer to the array with sensor raw counts.
+*
+* \param touch
+* The pointer to touch structure.
+*
+*******************************************************************************/
+void Cy_CapSense_AdvancedCentroidGetTouchCoordinates_Lib(
+                const cy_stc_capsense_advanced_centroid_config_t * config,
+                const uint16_t * ptrSns,
+                cy_stc_capsense_touch_t * touch);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BallisticMultiplier_Lib
+****************************************************************************//**
+*
+* This function runs the ballistic multiplier.
+*
+* \param config
+* The pointer to the configuration structure of the Advanced Centroid.
+*
+* \param touch
+* The pointer to touch structure.
+*
+* \param displacement
+* The pointer to position displacement
+*
+* \param timestamp
+* The current timestamp
+*
+* \param context
+* The pointer to the context structure of the Ballistic Multiplier.
+*
+*******************************************************************************/
+void Cy_CapSense_BallisticMultiplier_Lib(
+                const cy_stc_capsense_ballistic_config_t * config,
+                const cy_stc_capsense_touch_t * touch,
+                cy_stc_capsense_ballistic_delta_t * displacement,
+                uint32_t timestamp,
+                cy_stc_capsense_ballistic_context_t * context);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_AlpRun_Lib
+****************************************************************************//**
+*
+* Applies advanced low pass filter algorithm on raw counts.
+*
+* \param ptrFilterObj
+* The pointer to sensor filter data structure
+*
+* \param ptrFilterConfig
+* The pointer to sensor filter configuration structure
+*
+* \param rawCount
+* The pointer to sensor raw count
+*
+* \param baseline
+* The pointer to sensor baseline
+*
+*******************************************************************************/
+void Cy_CapSense_AlpRun_Lib(
+                cy_stc_capsense_alp_fltr_channel_t * ptrFilterObj,
+                const cy_stc_capsense_alp_fltr_config_t * ptrFilterConfig,
+                uint16_t * rawCount,
+                const uint16_t * baseline);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_AlpInitialize_Lib
+****************************************************************************//**
+*
+* Initializes filter data structure.
+*
+* \param ptrFilterObj
+* Pointer to filter data structure
+*
+* \param rawCount
+* Pointer to sensor raw count
+*
+*******************************************************************************/
+void Cy_CapSense_AlpInitialize_Lib(
+                cy_stc_capsense_alp_fltr_channel_t * ptrFilterObj,
+                const uint16_t * rawCount);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_AlpResetState_Lib
+****************************************************************************//**
+*
+* Resets state machine of the filter.
+*
+* \param ptrFilterObj
+* Pointer to the filter data structure
+*
+*******************************************************************************/
+void Cy_CapSense_AlpResetState_Lib(
+                cy_stc_capsense_alp_fltr_channel_t * ptrFilterObj);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_AlpGetAverage_Lib
+****************************************************************************//**
+*
+* Returns the output of internal average filter
+*
+* \param ptrFilterObj
+* Pointer to the filter data structure
+*
+* \return
+* Returns the output of internal average filter
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_AlpGetAverage_Lib(
+                const cy_stc_capsense_alp_fltr_channel_t * ptrFilterObj);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_TunePrescalers_Lib
+****************************************************************************//**
+*
+* This internal function tunes the Sense Clock divider.
+*
+* Found IDAC code in Single IDAC mode is used to calculate the optimal SnsClk.
+* The SnsClk divider is set to meet the requirement that the widget
+* clock period should be greater than or equal to:
+* Period > 2*5*R*Cp,
+* where:
+* * Cp is the maximum sensor parasitic capacitance within the widget.
+* * R is the user input value in the expression view of the customizer for a
+*   series resistor.
+*
+* \param config
+* The configuration structure.
+*
+* \return
+* Cp in fF (10^-15)
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_TunePrescalers_Lib(
+                cy_stc_capsense_auto_tune_config_t * config);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_TuneSensitivity_Lib
+****************************************************************************//**
+*
+* Configure scanning resolution to achieve the sufficient sensitivity.
+*
+* The function searches the lowest possible resolution that produces signal
+* greater than 50 counts (Difference Counts) for user defined finger capacitance.
+* In addition, function calculates 75%-value of the achieved signal, that becomes
+* candidate to finger threshold.
+*
+* Used equation to calculate signal at resolution 16-bit:
+* sigPFCmax = (2^16-1) * vRef * snsClk * fingerCap / idacCurrent
+*
+* sigPFCmax contains absolute number of difference counts that user receives as
+* result of sensor scanning at corresponding resolution.
+*
+* This function requires non-zero Modulator IDAC code (if IDAC is equal to zero it
+* is considered as non-valid use case).
+*
+* \param config
+* The configuration structure.
+*
+* \return
+* Scan resolution
+*
+*******************************************************************************/
+uint8_t Cy_CapSense_TuneSensitivity_Lib(
+                cy_stc_capsense_auto_tune_config_t * config);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GetSmartSenseCapacitance
+****************************************************************************//**
+*
+* Returns capacitance that corresponds to the provided parameters.
+*
+* Calculates sensor capacitance as follows:
+*     Cp = Raw * RefCDAC / Nsub0
+*
+* \param autoTuneConfig
+* The configuration structure.
+*
+* \return
+* Returns capacitance in femto-farads.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_GetSmartSenseCapacitance(
+                cy_stc_capsense_hw_smartsense_config_t * autoTuneConfig);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GetSmartSenseFrequencyDivider
+****************************************************************************//**
+*
+* Returns minimum sense clock divider.
+*
+* Calculates minimal sense clock divider as follows:
+*     Kref = 4 * 5tau * Fmod * R * Cp
+*
+* \param autoTuneConfig
+* The configuration structure.
+*
+* \return
+* Returns sense clock divider.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_GetSmartSenseFrequencyDivider(
+                cy_stc_capsense_hw_smartsense_config_t * autoTuneConfig);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GetSmartSenseNumSubconversions
+****************************************************************************//**
+*
+* Returns optimum number of sub-conversions.
+*
+* Calculates number of sub-conversions as follows:
+*     Nsub = RoundUp(minRaw * RefCDAC * kRef0 /(sigPFC * kRef1)
+*
+* \param autoTuneConfig
+* The configuration structure.
+*
+* \return
+* Returns number of sub-conversions.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_GetSmartSenseNumSubconversions(
+                cy_stc_capsense_hw_smartsense_config_t * autoTuneConfig);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_UpdateThresholds_Lib
+****************************************************************************//**
+*
+* Updates noise and finger thresholds for a specified widget.
+*
+* This function comprises an algorithm of thresholds auto-tune. The thresholds
+* object contains updated thresholds after this API is called.
+*
+* \param ptrNoiseEnvelope
+* The pointer to the noise-envelope object in RAM.
+*
+* \param ptrThresholds
+* The pointer to the thresholds object.
+*
+* \param sigPFC
+* Signal per finger capacitance.
+*
+* \param startFlag
+* The flag indicates a first sensor in a widget.
+*
+*******************************************************************************/
+void Cy_CapSense_UpdateThresholds_Lib(
+                const cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNoiseEnvelope,
+                cy_stc_capsense_smartsense_update_thresholds_t * ptrThresholds,
+                uint16_t sigPFC,
+                uint32_t startFlag);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeNoiseEnvelope_Lib
+****************************************************************************//**
+*
+* Initializes the noise-envelope filter.
+*
+* \param rawCount
+* The RawCount value for a given sensor.
+*
+* \param sigPFC
+* Signal per finger capacitance.
+*
+* \param ptrNoiseEnvelope
+* The pointer to the noise-envelope RAM object of the sensor.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeNoiseEnvelope_Lib(
+                uint16_t rawCount,
+                uint16_t sigPFC,
+                cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNoiseEnvelope);
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunNoiseEnvelope_Lib
+****************************************************************************//**
+*
+* Runs the noise-envelope filter.
+*
+* \param rawCount
+* The RawCount value for a given sensor.
+*
+* \param sigPFC
+* Signal per finger capacitance.
+*
+* \param ptrNoiseEnvelope
+* The pointer to the noise-envelope RAM object of the sensor.
+*
+*******************************************************************************/
+void Cy_CapSense_RunNoiseEnvelope_Lib(
+                uint16_t rawCount,
+                uint16_t sigPFC,
+                cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNoiseEnvelope);
+/** \} \endcond */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* CY_CAPSENSE_LIB_H */
+
+
+/* [] END OF FILE */

+ 2226 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_processing.c

@@ -0,0 +1,2226 @@
+/***************************************************************************//**
+* \file cy_capsense_processing.c
+* \version 3.0
+*
+* \brief
+* This file provides the source code for the Data Processing module functions.
+* The Data Processing module is responsible for the low-level raw count
+* processing provided by the sensing module, maintaining baseline and
+* difference values and performing high-level widget processing like
+* updating button status or calculating slider position.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include "cy_syslib.h"
+#include <stddef.h>
+#include <string.h>
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_processing.h"
+#include "cy_capsense_filter.h"
+#include "cy_capsense_lib.h"
+#include "cy_capsense_centroid.h"
+#include "cy_capsense_sensing_v3.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+/*******************************************************************************
+* Local definition
+*******************************************************************************/
+/* Raw data normalization and scaling */
+#define CY_CAPSENSE_SCALING_SHIFT              (15)
+#define CY_CAPSENSE_MAX_TX_PATTERN_NUM         (32)
+
+/* CIC2 Filter Divider */
+#define CY_CAPSENSE_CIC2_DIVIDER_1             (1u)
+#define CY_CAPSENSE_CIC2_DIVIDER_2             (2u)
+#define CY_CAPSENSE_CIC2_DIVIDER_4             (4u)
+#define CY_CAPSENSE_CIC2_DIVIDER_8             (8u)
+#define CY_CAPSENSE_CIC2_DIVIDER_16            (16u)
+
+/** \} \endcond */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeAllStatuses
+****************************************************************************//**
+*
+* Performs initialization of all statuses and related modules including
+* debounce counters and touch positions of all the widgets.
+*
+* The initialization includes the following tasks:
+* * Reset the debounce counters of all the widgets.
+* * Reset the number of touches.
+* * Reset the position filter history for slider and touchpad widgets.
+* * Clear all status of widgets and sensors.
+* * Enable all the widgets.
+*
+* Calling this function is accompanied by
+* * Cy_CapSense_InitializeAllBaselines().
+* * Cy_CapSense_InitializeAllFilters().
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeAllStatuses(const cy_stc_capsense_context_t * context)
+{
+    uint32_t widgetId;
+
+    for(widgetId = context->ptrCommonConfig->numWd; widgetId-- > 0u;)
+    {
+        Cy_CapSense_InitializeWidgetStatus(widgetId, context);
+        #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_GESTURE_EN)
+            Cy_CapSense_InitializeWidgetGestures(widgetId, context);
+        #endif
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeWidgetStatus
+****************************************************************************//**
+*
+* Performs initialization of all statuses, debounce counters, and touch positions
+* of the specified widget.
+*
+* The initialization includes:
+* * Resets the debounce counter of the widget.
+* * Resets the number of touches.
+* * Resets the position filter history for slider and touchpad widgets.
+* * Clears widget and sensor statuses.
+* * Enables the widget.
+*
+* The Button and Matrix Button widgets have individual debounce counters per
+* sensor for the CSD widgets and per node for the CSX widgets.
+*
+* The Slider and Touchpad widgets have a single debounce counter per widget.
+*
+* The Proximity widget has two debounce counters per sensor. One is for the
+* proximity event and the second is for the touch event.
+*
+* All debounce counters during initialization are set to the value of the
+* onDebounce widget parameter.
+*
+* Calling this function is accompanied by
+* * Cy_CapSense_InitializeWidgetBaseline().
+* * Cy_CapSense_InitializeWidgetFilter().
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeWidgetStatus(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+    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 * ptrSnsCxt = ptrWdCfg->ptrSnsContext;
+    uint32_t snsNumber = ptrWdCfg->numSns;
+
+    #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_TOUCHPAD_EN)
+        uint32_t filterSize;
+        cy_stc_capsense_position_t * ptrHistory;
+    #endif
+
+    /* Clear widget statuses (Non active, Not disabled, Working) */
+    ptrWdCxt->status &= (uint8_t)~(CY_CAPSENSE_WD_ACTIVE_MASK |
+                                   CY_CAPSENSE_WD_DISABLE_MASK |
+                                   CY_CAPSENSE_WD_WORKING_MASK);
+    /* Clear sensor status */
+    for (snsIndex = snsNumber; snsIndex-- >0u;)
+    {
+        ptrSnsCxt->status &= (uint8_t)~(CY_CAPSENSE_SNS_TOUCH_STATUS_MASK | CY_CAPSENSE_SNS_PROX_STATUS_MASK);
+        ptrSnsCxt++;
+    }
+
+    /* Reset debounce counters */
+    switch (ptrWdCfg->wdType)
+    {
+        #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_BUTTON_EN) ||\
+            (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MATRIX_EN))
+            case (uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E:
+            case (uint8_t)CY_CAPSENSE_WD_BUTTON_E:
+                /* Each button requires one debounce counter */
+                (void)memset(ptrWdCfg->ptrDebounceArr, (int32_t)ptrWdCxt->onDebounce, (size_t)snsNumber);
+                break;
+        #endif
+        #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_SLIDER_EN) ||\
+            (CY_CAPSENSE_DISABLE != CY_CAPSENSE_TOUCHPAD_EN))
+            case (uint8_t)CY_CAPSENSE_WD_LINEAR_SLIDER_E:
+            case (uint8_t)CY_CAPSENSE_WD_RADIAL_SLIDER_E:
+            case (uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E:
+                /* Each widget requires one debounce counter */
+                if (ptrWdCfg->senseMethod == CY_CAPSENSE_CSD_GROUP)
+                {
+                    *(ptrWdCfg->ptrDebounceArr) = ptrWdCxt->onDebounce;
+                }
+                else
+                {
+                    /*
+                    * CSX Touchpad has debounce located in another place. Moreover,
+                    * debounce counter is initialized at ID assignment, so no need
+                    * to do it here.
+                    */
+                }
+                break;
+        #endif
+        #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_PROXIMITY_EN)
+            case (uint8_t)CY_CAPSENSE_WD_PROXIMITY_E:
+                /* Proximity widgets have 2 debounce counters per sensor (for touch and prox detection) */
+                (void)memset(ptrWdCfg->ptrDebounceArr, (int32_t)ptrWdCxt->onDebounce, (size_t)(snsNumber << 1u));
+                break;
+        #endif
+        default:
+            /* No other widget types */
+            break;
+    }
+
+    /* Reset touch numbers */
+    #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_TOUCHPAD_EN) ||\
+        (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MATRIX_EN) ||\
+        (CY_CAPSENSE_DISABLE != CY_CAPSENSE_SLIDER_EN))
+        switch (ptrWdCfg->wdType)
+        {
+            case (uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E:
+            case (uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E:
+            case (uint8_t)CY_CAPSENSE_WD_LINEAR_SLIDER_E:
+            case (uint8_t)CY_CAPSENSE_WD_RADIAL_SLIDER_E:
+                /* Clean number of touches */
+                ptrWdCxt->wdTouch.numPosition = CY_CAPSENSE_POSITION_NONE;
+                if (0u != (ptrWdCfg->posFilterConfig & CY_CAPSENSE_POSITION_FILTERS_MASK))
+                {
+                    ptrWdCfg->ptrPosFilterHistory->numPosition = CY_CAPSENSE_POSITION_NONE;
+                }
+                break;
+            default:
+                /* No action on other widget types */
+                break;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_BALLISTIC_MULTIPLIER_EN)
+        /* Reset ballistic displacement */
+        if (0u != (ptrWdCfg->centroidConfig & CY_CAPSENSE_CENTROID_BALLISTIC_MASK))
+        {
+            ptrWdCxt->xDelta = 0;
+            ptrWdCxt->yDelta = 0;
+            ptrWdCfg->ptrBallisticContext->oldTouchNumber = 0u;
+        }
+    #endif
+
+    /* Reset touch history */
+    if (0u != (ptrWdCfg->posFilterConfig & CY_CAPSENSE_POSITION_FILTERS_MASK))
+    {
+        #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_TOUCHPAD_EN)
+            switch (ptrWdCfg->wdType)
+            {
+                case (uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E:
+                    /* Clean position filter history */
+                    if (ptrWdCfg->senseMethod == CY_CAPSENSE_CSX_GROUP)
+                    {
+                        /* Reset all history IDs to undefined state */
+                        ptrHistory = ptrWdCfg->ptrPosFilterHistory->ptrPosition;
+                        filterSize = (ptrWdCfg->posFilterConfig & CY_CAPSENSE_POSITION_FILTERS_SIZE_MASK) >> CY_CAPSENSE_POSITION_FILTERS_SIZE_OFFSET;
+                        for (snsIndex = 0u; snsIndex < CY_CAPSENSE_MAX_CENTROIDS; snsIndex++)
+                        {
+                            ptrHistory->id = CY_CAPSENSE_CSX_TOUCHPAD_ID_UNDEFINED;
+                            ptrHistory += filterSize;
+                        }
+                    }
+                    break;
+                default:
+                    /* No action on other widget types */
+                    break;
+            }
+        #endif
+
+        #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_ADAPTIVE_FILTER_EN)
+            /* Init Adaptive IIR filter */
+            if (0u != (ptrWdCfg->posFilterConfig & CY_CAPSENSE_POSITION_AIIR_MASK))
+            {
+                Cy_CapSense_AdaptiveFilterInitialize_Lib(&ptrWdCfg->aiirConfig,
+                                                         ptrWdCfg->ptrPosFilterHistory->ptrPosition);
+            }
+        #endif
+    }
+}
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_GESTURE_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_InitializeWidgetGestures
+****************************************************************************//**
+*
+* Performs initialization of all gestures for the specified widget.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_InitializeWidgetGestures(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdCfg->ptrWdContext;
+
+    if (((uint8_t)CY_CAPSENSE_WD_LINEAR_SLIDER_E == ptrWdCfg->wdType) ||
+        ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType))
+    {
+        if (NULL != ptrWdCfg->ptrGestureConfig)
+        {
+            if (0u != (ptrWdCfg->ptrGestureConfig->gestureEnableMask & CY_CAPSENSE_GESTURE_ALL_GESTURES_MASK))
+            {
+                ptrWdCxt->gestureDetected = 0u;
+                ptrWdCxt->gestureDirection = 0u;
+                Cy_CapSense_Gesture_ResetState(ptrWdCfg->ptrGestureContext);
+            }
+        }
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_DecodeWidgetGestures
+****************************************************************************//**
+*
+* 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
+* Cy_CapSense_ProcessAllWidgets() or Cy_CapSense_ProcessWidget() functions
+* for the widget. Calling this function multiple times without a new sensor
+* scan and process causes unexpected behavior.
+*
+* \note 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.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the detected Gesture mask and direction of detected gestures.
+* The same information is stored in ptrWdContext->gestureDetected and
+* ptrWdContext->gestureDirection registers. Corresponding macros could be found
+* \ref group_capsense_macros_gesture.
+* * bit[0..15] - detected gesture masks gesture
+*   * bit[0] - one-finger single click gesture
+*   * bit[1] - one-finger double click gesture
+*   * bit[2] - one-finger click and drag gesture
+*   * bit[3] - two-finger single click gesture
+*   * bit[4] - one-finger scroll gesture
+*   * bit[5] - two-finger scroll gesture
+*   * bit[6] - one-finger edge swipe
+*   * bit[7] - one-finger flick
+*   * bit[8] - one-finger rotate
+*   * bit[9] - two-finger zoom
+*   * bit[13] - touchdown event
+*   * bit[14] - liftoff event
+* * bit[16..31] - gesture direction if detected
+*    * bit[0..1] - direction of one-finger scroll gesture
+*    * bit[2..3] - direction of two-finger scroll gesture
+*    * bit[4..5] - direction of one-finger edge swipe gesture
+*    * bit[6] - direction of one-finger rotate gesture
+*    * bit[7] - direction of two-finger zoom gesture
+*    * bit[8..10] - direction of one-finger flick gesture
+*
+* \funcusage
+*
+* An example of gesture decoding:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Gesture
+*
+* An example of gesture status parsing:
+* \snippet capsense/snippet/main.c snippet_Cy_CapSense_Gesture_Macro
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_DecodeWidgetGestures(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t gestureStatus = 0u;
+    uint32_t posIndex;
+    uint32_t positionNum;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdCfg->ptrWdContext;
+    cy_stc_capsense_gesture_position_t position[CY_CAPSENSE_MAX_CENTROIDS];
+
+    if (((uint8_t)CY_CAPSENSE_WD_LINEAR_SLIDER_E == ptrWdCfg->wdType) ||
+        ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType))
+    {
+        if (NULL != ptrWdCfg->ptrGestureConfig)
+        {
+            if (0u != (ptrWdCfg->ptrGestureConfig->gestureEnableMask & CY_CAPSENSE_GESTURE_ALL_GESTURES_MASK))
+            {
+                positionNum = ptrWdCxt->wdTouch.numPosition;
+                if (positionNum > CY_CAPSENSE_MAX_CENTROIDS)
+                {
+                    positionNum = 0u;
+                }
+                for (posIndex = 0u; posIndex < positionNum; posIndex++)
+                {
+                    position[posIndex].x = ptrWdCxt->wdTouch.ptrPosition[posIndex].x;
+                    position[posIndex].y = ptrWdCxt->wdTouch.ptrPosition[posIndex].y;
+                }
+                Cy_CapSense_Gesture_Decode(context->ptrCommonContext->timestamp, (uint32_t)ptrWdCxt->wdTouch.numPosition,
+                        &position[0u], ptrWdCfg->ptrGestureConfig, ptrWdCfg->ptrGestureContext);
+                ptrWdCxt->gestureDetected = ptrWdCfg->ptrGestureContext->detected;
+                ptrWdCxt->gestureDirection = ptrWdCfg->ptrGestureContext->direction;
+                gestureStatus = (uint32_t)ptrWdCxt->gestureDetected | ((uint32_t)ptrWdCxt->gestureDirection << CY_CAPSENSE_GESTURE_DIRECTION_OFFSET);
+            }
+        }
+    }
+    return gestureStatus;
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_GESTURE_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessCsxWidgetRawCounts
+****************************************************************************//**
+*
+* Performs default processing of the raw counts of the specified CSX widget.
+*
+* The processing includes the following tasks:
+* - Run Filters.
+* - Update Baselines.
+* - Update Differences.
+* The same process is applied to all the sensors of the specified widget.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the specified widget processing operation:
+* - Zero - if operation was successfully completed;
+* - Non-zero - if baseline processing of any sensor of the specified widget
+* failed. The result is concatenated with the index of failed sensor.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_DpProcessCsxWidgetRawCounts(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t result = CY_CAPSENSE_STATUS_SUCCESS;
+    uint32_t snsIndex;
+    uint32_t snsHistorySize;
+    uint32_t freqChIndex;
+    uint16_t * ptrHistorySns;
+    uint16_t * ptrBslnInvSns;
+    uint8_t * ptrHistoryLowSns = NULL;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxtSns;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+
+    ptrWdCfg = &context->ptrWdConfig[widgetId];
+    snsHistorySize = (uint32_t)ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_MASK;
+
+    for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+    {
+        ptrSnsCxtSns = &ptrWdCfg->ptrSnsContext[freqChIndex * context->ptrCommonConfig->numSns];
+        ptrBslnInvSns = &ptrWdCfg->ptrBslnInv[freqChIndex * context->ptrCommonConfig->numSns];
+        ptrHistorySns = &ptrWdCfg->ptrRawFilterHistory[freqChIndex * (CY_CAPSENSE_RAW_HISTORY_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)];
+        if(CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
+        {
+            ptrHistoryLowSns = &ptrWdCfg->ptrRawFilterHistoryLow[freqChIndex *
+                    (CY_CAPSENSE_IIR_HISTORY_LOW_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)];
+        }
+
+        for (snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
+        {
+            #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
+                Cy_CapSense_FtRunEnabledFiltersInternal(ptrWdCfg, ptrSnsCxtSns, ptrHistorySns, ptrHistoryLowSns);
+            #endif
+            result |= Cy_CapSense_FtUpdateBaseline(ptrWdCfg->ptrWdContext, ptrSnsCxtSns, ptrBslnInvSns, context);
+            Cy_CapSense_DpUpdateDifferences(ptrWdCfg->ptrWdContext, ptrSnsCxtSns);
+            ptrSnsCxtSns++;
+            ptrBslnInvSns++;
+            ptrHistorySns += snsHistorySize;
+            if(NULL != ptrHistoryLowSns)
+            {
+                ptrHistoryLowSns++;
+            }
+        }
+    }
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        ptrSnsCxtSns = ptrWdCfg->ptrSnsContext;
+        for (snsIndex = ptrWdCfg->numSns; snsIndex-- > 0u;)
+        {
+            Cy_CapSense_RunMfsFiltering(ptrSnsCxtSns, context);
+            ptrSnsCxtSns++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
+        (void) Cy_CapSense_RunMfsMedian(widgetId, context);
+    #endif
+
+    return result;
+}
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessCsxWidgetStatus
+****************************************************************************//**
+*
+* Updates the status of the CSX widget in the Data Structure.
+*
+* This function determines the type of widget and runs the appropriate function
+* that implements the status update algorithm for this type of widget.
+*
+* When the widget-specific processing completes this function updates the
+* sensor and widget status registers in the data structure.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpProcessCsxWidgetStatus(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    switch (ptrWdConfig->wdType)
+    {
+        #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_BUTTON_EN) ||\
+            (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_MATRIX_EN))
+            case (uint8_t)CY_CAPSENSE_WD_BUTTON_E:
+            case (uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E:
+                Cy_CapSense_DpProcessButton(ptrWdConfig);
+                break;
+        #endif
+
+        #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_LINEAR_SLIDER_EN)
+            case (uint8_t)CY_CAPSENSE_WD_LINEAR_SLIDER_E:
+                Cy_CapSense_DpProcessSlider(ptrWdConfig);
+                break;
+        #endif
+
+        #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+            case (uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E:
+                Cy_CapSense_DpProcessCsxTouchpad(ptrWdConfig);
+                break;
+        #endif
+
+    default:
+        /* Nothing to process since widget type is not valid */
+        break;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessCsxSensorRawCountsExt
+****************************************************************************//**
+*
+* Performs customized processing of the CSX sensor raw counts.
+*
+* If all bits are set at once, the default processing order will take place.
+* For a custom order, this function can be called multiple times and execute
+* one task at a time.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+* \param ptrSnsRawHistory
+* The pointer to the filter history.
+*
+* \param ptrSnsRawHistoryLow
+* The pointer to the extended filter history.
+*
+* \param mode
+* The bit-mask with the data processing tasks to be executed.
+* The mode parameters can take the following values:
+* - CY_CAPSENSE_PROCESS_FILTER     (0x01) Run Firmware Filter
+* - CY_CAPSENSE_PROCESS_BASELINE   (0x02) Update Baselines
+* - 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the specified sensor processing operation:
+* - CY_CAPSENSE_STATUS_SUCCESS if operation was successfully completed;
+* - Non-zero - if baseline processing of any
+* sensor of the specified widget failed. The result is concatenated with the index
+* of failed sensor.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_DpProcessCsxSensorRawCountsExt(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory,
+                uint8_t * ptrSnsRawHistoryLow,
+                uint32_t mode,
+                uint16_t * ptrSnsBslnInv,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t  result = CY_CAPSENSE_STATUS_SUCCESS;
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
+        if (0u != (mode & CY_CAPSENSE_PROCESS_FILTER))
+        {
+            Cy_CapSense_FtRunEnabledFiltersInternal(ptrWdConfig,
+                                                    ptrSnsContext,
+                                                    ptrSnsRawHistory,
+                                                    ptrSnsRawHistoryLow);
+        }
+    #else
+        (void)ptrSnsRawHistory;
+        (void)ptrSnsRawHistoryLow;
+    #endif
+
+    if (0u != (mode & CY_CAPSENSE_PROCESS_BASELINE))
+    {
+        result = Cy_CapSense_FtUpdateBaseline(ptrWdCxt, ptrSnsContext, ptrSnsBslnInv, context);
+    }
+    if (0u != (mode & CY_CAPSENSE_PROCESS_DIFFCOUNTS))
+    {
+        Cy_CapSense_DpUpdateDifferences(ptrWdCxt, ptrSnsContext);
+    }
+
+    return result;
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessCsdWidgetRawCounts
+****************************************************************************//**
+*
+* Performs default processing of the raw counts of the specified CSD widget.
+*
+* The processing includes the following tasks:
+* - Run Filters.
+* - Update Baselines.
+* - Update Differences.
+* The same process is applied to all the sensors of the specified widget.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the specified widget processing operation:
+* - Zero - if operation was successfully completed.
+* - Non-zero - if baseline processing of any sensor of the specified widget
+* failed. The result is concatenated with the index of failed sensor.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_DpProcessCsdWidgetRawCounts(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t result = CY_CAPSENSE_STATUS_SUCCESS;
+    uint32_t snsIndex;
+    uint32_t snsHistorySize;
+    uint32_t freqChIndex;
+    uint16_t * ptrHistorySns;
+    uint16_t * ptrBslnInvSns;
+    uint8_t * ptrHistoryLowSns = NULL;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxtSns;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+
+    ptrWdCfg = &context->ptrWdConfig[widgetId];
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN)
+        cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNEHistory = ptrWdCfg->ptrNoiseEnvelope;
+    #endif
+
+    snsHistorySize = (uint32_t)ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_SNS_HISTORY_SIZE_MASK;
+
+    for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+    {
+        ptrSnsCxtSns = &ptrWdCfg->ptrSnsContext[freqChIndex * context->ptrCommonConfig->numSns];
+        ptrBslnInvSns = &ptrWdCfg->ptrBslnInv[freqChIndex * context->ptrCommonConfig->numSns];
+        ptrHistorySns = &ptrWdCfg->ptrRawFilterHistory[freqChIndex * (CY_CAPSENSE_RAW_HISTORY_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)];
+        if(CY_CAPSENSE_IIR_FILTER_PERFORMANCE == (ptrWdCfg->rawFilterConfig & CY_CAPSENSE_RC_FILTER_IIR_MODE_MASK))
+        {
+            ptrHistoryLowSns = &ptrWdCfg->ptrRawFilterHistoryLow[freqChIndex *
+                    (CY_CAPSENSE_IIR_HISTORY_LOW_SIZE / CY_CAPSENSE_CONFIGURED_FREQ_NUM)];
+        }
+
+        for (snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
+        {
+            #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
+                Cy_CapSense_FtRunEnabledFiltersInternal(ptrWdCfg, ptrSnsCxtSns, ptrHistorySns, ptrHistoryLowSns);
+            #endif
+            /* Run auto-tuning activities */
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_SMARTSENSE_FULL_EN)
+                Cy_CapSense_RunNoiseEnvelope_Lib(ptrSnsCxtSns->raw, ptrWdCfg->ptrWdContext->sigPFC, ptrNEHistory);
+                Cy_CapSense_DpUpdateThresholds(ptrWdCfg->ptrWdContext, ptrNEHistory, snsIndex);
+                #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_PROXIMITY_EN)
+                    if ((uint8_t)CY_CAPSENSE_WD_PROXIMITY_E == ptrWdCfg->wdType)
+                    {
+                        ptrWdCfg->ptrWdContext->proxTh = (uint16_t)(((uint32_t)ptrWdCfg->ptrWdContext->fingerTh *
+                            context->ptrCommonConfig->proxTouchCoeff) / CY_CAPSENSE_PERCENTAGE_100);
+                    }
+                #endif
+                ptrNEHistory++;
+            #endif
+
+            result |= Cy_CapSense_FtUpdateBaseline(ptrWdCfg->ptrWdContext, ptrSnsCxtSns, ptrBslnInvSns, context);
+            Cy_CapSense_DpUpdateDifferences(ptrWdCfg->ptrWdContext, ptrSnsCxtSns);
+
+            ptrSnsCxtSns++;
+            ptrBslnInvSns++;
+            ptrHistorySns += snsHistorySize;
+            if(NULL != ptrHistoryLowSns)
+            {
+                ptrHistoryLowSns++;
+            }
+        }
+    }
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+        ptrSnsCxtSns = ptrWdCfg->ptrSnsContext;
+        for (snsIndex = ptrWdCfg->numSns; snsIndex-- > 0u;)
+        {
+            Cy_CapSense_RunMfsFiltering(ptrSnsCxtSns, context);
+            ptrSnsCxtSns++;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
+        (void) Cy_CapSense_RunMfsMedian(widgetId, context);
+    #endif
+
+    return result;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessCsdSensorRawCountsExt
+****************************************************************************//**
+*
+* Performs customized processing of the CSX sensor raw counts.
+*
+* If all bits are set at once, the default processing order will take place.
+* For a custom order, this function can be called multiple times and execute
+* one task at a time.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+* \param ptrSnsRawHistory
+* The pointer to the filter history.
+*
+* \param ptrSnsRawHistoryLow
+* The pointer to the extended filter history.
+*
+* \param mode
+* The bit-mask with the data processing tasks to be executed.
+* The mode parameters can take the following values:
+* - CY_CAPSENSE_PROCESS_FILTER     (0x01) Run Firmware Filter
+* - CY_CAPSENSE_PROCESS_BASELINE   (0x02) Update Baselines
+* - CY_CAPSENSE_PROCESS_DIFFCOUNTS (0x04) Update Difference Counts
+* - CY_CAPSENSE_PROCESS_CALC_NOISE (0x08) Calculate Noise (only if FW Tuning is enabled)
+* - 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the specified sensor processing operation:
+* - CY_CAPSENSE_STATUS_SUCCESS if operation was successfully completed.
+* - CY_CAPSENSE_STATUS_BAD_DATA if baseline processing of any sensor of the specified widget
+*   failed.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_DpProcessCsdSensorRawCountsExt(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                    uint16_t * ptrSnsRawHistory,
+                    uint8_t * ptrSnsRawHistoryLow,
+                    uint32_t mode,
+                    uint16_t * ptrBslnInvSns,
+                    const cy_stc_capsense_context_t * context)
+{
+    uint32_t  result = CY_CAPSENSE_STATUS_SUCCESS;
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_RAWCOUNT_FILTER_EN)
+        if (0u != (mode & CY_CAPSENSE_PROCESS_FILTER))
+        {
+            Cy_CapSense_FtRunEnabledFiltersInternal(ptrWdConfig, ptrSnsContext,
+                                                    ptrSnsRawHistory, ptrSnsRawHistoryLow);
+        }
+    #else
+        (void)ptrSnsRawHistory;
+        (void)ptrSnsRawHistoryLow;
+    #endif
+
+    if (0u != (mode & CY_CAPSENSE_PROCESS_BASELINE))
+    {
+        result = Cy_CapSense_FtUpdateBaseline(ptrWdCxt, ptrSnsContext, ptrBslnInvSns, context);
+    }
+    if (0u != (mode & CY_CAPSENSE_PROCESS_DIFFCOUNTS))
+    {
+        Cy_CapSense_DpUpdateDifferences(ptrWdCxt, ptrSnsContext);
+    }
+
+    return result;
+}
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessCsdWidgetStatus
+****************************************************************************//**
+*
+* Updates the status of the CSD widget in the Data Structure.
+*
+* This function determines the type of widget and runs the appropriate function
+* that implements the status update algorithm for this type of widget.
+*
+* When the widget-specific processing completes this function updates the
+* sensor and widget status registers in the data structure.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_DpProcessCsdWidgetStatus(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_context_t * context)
+{
+    (void)context;
+    switch (ptrWdConfig->wdType)
+    {
+        #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_BUTTON_EN)
+            case (uint8_t)CY_CAPSENSE_WD_BUTTON_E:
+                Cy_CapSense_DpProcessButton(ptrWdConfig);
+                break;
+        #endif
+
+        #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_SLIDER_EN)
+            case (uint8_t)CY_CAPSENSE_WD_LINEAR_SLIDER_E:
+            case (uint8_t)CY_CAPSENSE_WD_RADIAL_SLIDER_E:
+                Cy_CapSense_DpProcessSlider(ptrWdConfig);
+                break;
+        #endif
+
+        #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN)
+            case (uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E:
+                Cy_CapSense_DpProcessCsdMatrix(ptrWdConfig);
+                break;
+        #endif
+
+        #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)
+            case (uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E:
+                Cy_CapSense_DpProcessCsdTouchpad(ptrWdConfig, context);
+                break;
+        #endif
+
+        #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_PROXIMITY_EN)
+            case (uint8_t)CY_CAPSENSE_WD_PROXIMITY_E:
+                Cy_CapSense_DpProcessProximity(ptrWdConfig);
+                break;
+        #endif
+
+        default:
+            /* No other widget types */
+            break;
+    }
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpUpdateThresholds
+****************************************************************************//**
+*
+* Updates noise and finger thresholds for a specified widget.
+*
+* Used for smart sensing algorithm.
+*
+* \param ptrWdContext
+* The pointer to the widget context structure.
+*
+* \param ptrNoiseEnvelope
+* The pointer to the noise-envelope history structure.
+*
+* \param startFlag
+* The flag indicates when a new widget is processed.
+*
+*******************************************************************************/
+void Cy_CapSense_DpUpdateThresholds(
+                cy_stc_capsense_widget_context_t * ptrWdContext,
+                const cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNoiseEnvelope,
+                uint32_t startFlag)
+{
+    cy_stc_capsense_smartsense_update_thresholds_t thresholds;
+
+    /* Calculate Thresholds */
+    thresholds.fingerTh = ptrWdContext->fingerTh;
+    Cy_CapSense_UpdateThresholds_Lib(ptrNoiseEnvelope, &thresholds, ptrWdContext->sigPFC, startFlag);
+
+    /* Update CAPSENSE&trade; context */
+    ptrWdContext->fingerTh = thresholds.fingerTh;
+    ptrWdContext->noiseTh = (uint16_t)thresholds.noiseTh;
+    ptrWdContext->nNoiseTh = (uint16_t)thresholds.nNoiseTh;
+    ptrWdContext->hysteresis = (uint16_t)thresholds.hysteresis;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpUpdateDifferences
+****************************************************************************//**
+*
+* Calculates new difference values.
+*
+* This function calculates the difference between the baseline and raw counts.
+* If the difference is positive (raw > baseline), and higher than the widget
+* noise threshold, it is saved into the data structure for further processing.
+* Otherwise the difference is set to zero. The final difference value is saved
+* with the subtracted noise threshold value.
+*
+* \param ptrWdContext
+* The pointer to the widget context structure.
+*
+* \param ptrSnsContext
+* The pointer to the sensor context structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpUpdateDifferences(
+                const cy_stc_capsense_widget_context_t * ptrWdContext,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext)
+{
+    ptrSnsContext->diff = 0u;
+    if ((uint32_t)ptrSnsContext->raw > ((uint32_t)ptrSnsContext->bsln + ptrWdContext->noiseTh))
+    {
+        ptrSnsContext->diff = ptrSnsContext->raw - ptrSnsContext->bsln;
+    }
+}
+
+
+#if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_BUTTON_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_MATRIX_EN))
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessButton
+****************************************************************************//**
+*
+* Processes the status of the Button widget.
+*
+* This function processes the status of the CSD/CSX Button widget and
+* CSX Matrix Button widget. It applies the hysteresis and debounce algorithm
+* to each sensor difference value. This function is expected to be called
+* after each new widget scan. If it is called multiple times for the same
+* scan data, the debounce algorithm will not work properly.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpProcessButton(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t snsIndex;
+    uint32_t activeCount = 0u;
+    uint32_t touchTh;
+    #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_MATRIX_EN)
+        uint32_t startIndex = 0u;
+    #endif
+
+    uint8_t * ptrDebounceCnt = ptrWdConfig->ptrDebounceArr;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+
+    ptrWdCxt->status &= (uint8_t)~CY_CAPSENSE_WD_ACTIVE_MASK;
+
+    /* Go through all widget's sensors */
+    for (snsIndex = 0u; snsIndex < ptrWdConfig->numSns; snsIndex++)
+    {
+        /* Calculate touch threshold based on current sensor state */
+        touchTh = (0u == ptrSnsCxt->status) ?
+                  ((uint32_t)ptrWdCxt->fingerTh + ptrWdCxt->hysteresis) :
+                  ((uint32_t)ptrWdCxt->fingerTh - ptrWdCxt->hysteresis);
+
+        if (0u < (*ptrDebounceCnt))
+        {
+            /* Decrement debounce counter */
+            (*ptrDebounceCnt)--;
+        }
+
+        /* No touch */
+        if (ptrSnsCxt->diff <= touchTh)
+        {
+            /* Reset debounce counter */
+            *ptrDebounceCnt = ptrWdCxt->onDebounce;
+            ptrSnsCxt->status = 0u;
+        }
+
+        /* New touch or touch still exists */
+        if (0u == (*ptrDebounceCnt))
+        {
+            ptrSnsCxt->status = CY_CAPSENSE_SNS_TOUCH_STATUS_MASK;
+            activeCount++;
+            #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_MATRIX_EN)
+                startIndex = snsIndex;
+            #endif
+        }
+
+        /* Update widget status */
+        if (0u != ptrSnsCxt->status)
+        {
+            ptrWdCxt->status |= (uint8_t)CY_CAPSENSE_WD_ACTIVE_MASK;
+        }
+
+        ptrSnsCxt++;
+        ptrDebounceCnt++;
+    }
+    /* Update position struct */
+    #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_MATRIX_EN)
+        if (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdConfig->wdType) &&
+            (CY_CAPSENSE_CSX_GROUP == ptrWdConfig->senseMethod))
+        {
+            ptrWdCxt->wdTouch.numPosition = (uint8_t)activeCount;
+            ptrWdCxt->wdTouch.ptrPosition->id = (uint16_t)startIndex;
+            ptrWdCxt->wdTouch.ptrPosition->x = (uint16_t)(startIndex / ptrWdConfig->numRows);
+            ptrWdCxt->wdTouch.ptrPosition->y = (uint16_t)(startIndex % ptrWdConfig->numRows);
+        }
+    #endif
+}
+#endif /* ((CY_CAPSENSE_DISABLE != CY_CAPSENSE_BUTTON_EN) || (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_MATRIX_EN)) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_PROXIMITY_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessProximity
+****************************************************************************//**
+*
+* Processes the status of the Proximity widget.
+*
+* This function processes the status of the CSD Proximity widget. It applies the
+* hysteresis and debounce algorithm to each sensor difference value.
+* The proximity and touch events are considered independently so debounce and
+* hysteresis are also applied independently.
+*
+* This function is expected to be called after each new widget scan. If it is
+* called multiple times for the same scan data the debounce algorithm
+* will not work properly.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpProcessProximity(const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t snsTh;
+    uint32_t snsIndex;
+    uint32_t snsStMask;
+
+    uint8_t * ptrDebounceCnt = ptrWdConfig->ptrDebounceArr;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+
+    /* Reset widget status */
+    ptrWdCxt->status &= (uint8_t)~CY_CAPSENSE_WD_ACTIVE_MASK;
+
+    /* Go through all sensor's status bits */
+    for (snsIndex = 0u; snsIndex < ((uint32_t)ptrWdConfig->numSns << 1u); snsIndex++)
+    {
+        /*
+        * Proximity - odd; Touch - even. Example:
+        * Bit 0 -> touch event
+        * Bit 1 -> proximity event
+        */
+        snsTh = ptrWdCxt->proxTh;
+        snsStMask = CY_CAPSENSE_SNS_PROX_STATUS_MASK;
+        if (0u == (snsIndex & 0x01u))
+        {
+            snsTh = ptrWdCxt->fingerTh;
+            snsStMask = CY_CAPSENSE_SNS_TOUCH_STATUS_MASK;
+        }
+        /* Calculate threshold based on current sensor state */
+        snsTh = (0u == (snsStMask & ptrSnsCxt->status)) ?
+                  (snsTh + ptrWdCxt->hysteresis) :
+                  (snsTh - ptrWdCxt->hysteresis);
+
+        if (0u < (*ptrDebounceCnt))
+        {
+            /* Decrement debounce counter */
+            (*ptrDebounceCnt)--;
+        }
+
+        /* No touch */
+        if (ptrSnsCxt->diff <= snsTh)
+        {
+            /* Reset debounce counter */
+            *ptrDebounceCnt = ptrWdCxt->onDebounce;
+            ptrSnsCxt->status &= (uint8_t)(~snsStMask);
+        }
+
+        /* New touch or touch still exists */
+        if (0u == (*ptrDebounceCnt))
+        {
+            ptrSnsCxt->status |= (uint8_t)snsStMask;
+        }
+
+        /* Update widget status */
+        if (0u != (ptrSnsCxt->status & (uint8_t)snsStMask))
+        {
+            ptrWdCxt->status |= (uint8_t)CY_CAPSENSE_WD_ACTIVE_MASK;
+        }
+
+        if (0u != (snsIndex & 0x01u))
+        {
+            ptrSnsCxt++;
+        }
+        ptrDebounceCnt++;
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_PROXIMITY_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_SLIDER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessSlider
+****************************************************************************//**
+*
+* Processes the status of the Linear/Radial Slider widget.
+* The process involves running the Linear/Radial centroid algorithm.
+*
+* It applies the hysteresis and debounce algorithm to the widget ignoring
+* the individual states of the sensors.
+*
+* This function is expected to be called after each new widget scan. If it is
+* called multiple times for the same scan data, the debounce algorithm
+* will not work properly.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpProcessSlider(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t snsIndex;
+    uint32_t touchTh;
+    uint32_t wdActive = 0u;
+    uint8_t * ptrDebounceCnt = ptrWdConfig->ptrDebounceArr;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+    uint32_t sensorNumber = ptrWdConfig->numSns;
+    cy_stc_capsense_position_t newPosition[CY_CAPSENSE_MAX_CENTROIDS];
+    cy_stc_capsense_touch_t newTouch = {&newPosition[0u], CY_CAPSENSE_POSITION_NONE};
+
+    /* Calculate touch threshold based on current slider state */
+    touchTh = (0u == (ptrWdCxt->status & CY_CAPSENSE_WD_ACTIVE_MASK)) ?
+              ((uint32_t)ptrWdCxt->fingerTh + ptrWdCxt->hysteresis) :
+              ((uint32_t)ptrWdCxt->fingerTh - ptrWdCxt->hysteresis);
+
+    if (0u < (*ptrDebounceCnt))
+    {
+        /* Decrement debounce counter */
+        (*ptrDebounceCnt)--;
+    }
+
+    /* Check new widget activity */
+    for (snsIndex = sensorNumber; snsIndex-- > 0u;)
+    {
+        ptrSnsCxt->status = (touchTh < ptrSnsCxt->diff) ? CY_CAPSENSE_SNS_TOUCH_STATUS_MASK : 0u;
+        wdActive |= ptrSnsCxt->status;
+        ptrSnsCxt++;
+    }
+
+    /* No touch detected */
+    if (0u == wdActive)
+    {
+        /* Reset debounce counter */
+        (*ptrDebounceCnt) = ptrWdCxt->onDebounce;
+        ptrWdCxt->status &= (uint8_t)(~CY_CAPSENSE_WD_ACTIVE_MASK);
+    }
+
+    if (0u == (*ptrDebounceCnt))
+    {
+        /* New touch detected or touch still exists from previous cycle */
+        ptrWdCxt->status |= CY_CAPSENSE_WD_ACTIVE_MASK;
+    }
+    else
+    {
+        if (0u != wdActive)
+        {
+            /* Clear sensor state if activity was detected but debounce was not passed */
+            ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+
+            for (snsIndex = sensorNumber; snsIndex-- > 0u;)
+            {
+                ptrSnsCxt->status = 0u;
+                ptrSnsCxt++;
+            }
+        }
+    }
+
+    /* Centroid processing */
+    if (CY_CAPSENSE_WD_ACTIVE_MASK == (ptrWdCxt->status & CY_CAPSENSE_WD_ACTIVE_MASK))
+    {
+        switch (ptrWdConfig->wdType)
+        {
+            #if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_RADIAL_SLIDER_EN)
+                case (uint8_t)CY_CAPSENSE_WD_RADIAL_SLIDER_E:
+                    Cy_CapSense_DpCentroidRadial(&newTouch, ptrWdConfig);
+                    break;
+            #endif
+
+            #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_LINEAR_SLIDER_EN) ||\
+                (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_LINEAR_SLIDER_EN))
+                case (uint8_t)CY_CAPSENSE_WD_LINEAR_SLIDER_E:
+                    #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_DIPLEX_SLIDER_EN) ||\
+                        (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_DIPLEX_SLIDER_EN))
+                        if ((0u != (ptrWdConfig->centroidConfig & CY_CAPSENSE_DIPLEXING_MASK)))
+                        {
+                            /* Run local maximum search for diplexed slider */
+                            Cy_CapSense_DpCentroidDiplex(&newTouch, ptrWdConfig);
+                        }
+                        else
+                        {
+                            Cy_CapSense_DpCentroidLinear(&newTouch, ptrWdConfig);
+                        }
+                    #else
+                        Cy_CapSense_DpCentroidLinear(&newTouch, ptrWdConfig);
+                    #endif
+                    break;
+            #endif
+
+            default:
+                /* No action on other widget types */
+                break;
+        }
+    }
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POSITION_FILTER_EN)
+        /* Position filtering */
+        if (0u != (ptrWdConfig->posFilterConfig & CY_CAPSENSE_POSITION_FILTERS_MASK))
+        {
+            Cy_CapSense_ProcessPositionFilters(&newTouch, ptrWdConfig);
+        }
+    #endif
+
+    /* Copy positions into public structure */
+    ptrWdConfig->ptrWdContext->wdTouch.numPosition = newTouch.numPosition;
+    for (snsIndex = 0u; snsIndex < newTouch.numPosition; snsIndex++)
+    {
+        ptrWdConfig->ptrWdContext->wdTouch.ptrPosition[snsIndex] = newTouch.ptrPosition[snsIndex];
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_SLIDER_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessCsdMatrix
+****************************************************************************//**
+*
+* Processes the status of the CSD Matrix Button widget.
+*
+* This function processes the status of the CSD Matrix Button widget.
+* It applies the hysteresis and debounce algorithm to each sensor value.
+*
+* Then the function analyzes how many row and column sensors are active.
+* If only one per row and one per column, the function considers this as
+* a valid touch and updates the corresponding Data Structure registers
+* with the button id and active row and column sensors.
+*
+* If multiple sensors are active in row or column sensors, this function sets
+* the corresponding registers to the CY_CAPSENSE_POSITION_MULTIPLE
+* value that indicates that it is not possible to detect the touched button id.
+*
+* This function is expected to be called after each new widget scan. If it is
+* called multiple times for the same scan data, the debounce algorithm
+* will not work properly.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpProcessCsdMatrix(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t snsIndex;
+    uint32_t touchTh;
+
+    uint32_t colNumber = ptrWdConfig->numCols;
+    uint8_t * ptrDebounceCnt = ptrWdConfig->ptrDebounceArr;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+    cy_stc_capsense_position_t * ptrSnsTouch = ptrWdCxt->wdTouch.ptrPosition;
+
+    uint32_t numActiveRows = 0u;
+    uint32_t numActiveCols = 0u;
+
+    uint32_t activeRow = 0u;
+    uint32_t activeCol = 0u;
+
+    /* Reset status */
+    ptrWdCxt->status &= (uint8_t)~CY_CAPSENSE_WD_ACTIVE_MASK;
+
+    /* Go through all widget's sensors */
+    for (snsIndex = 0u; snsIndex < ptrWdConfig->numSns; snsIndex++)
+    {
+        /* Calculate touch threshold based on current sensor state */
+        touchTh = (0u == ptrSnsCxt->status) ?
+                  ((uint32_t)ptrWdCxt->fingerTh + ptrWdCxt->hysteresis) :
+                  ((uint32_t)ptrWdCxt->fingerTh - ptrWdCxt->hysteresis);
+
+        if (0u < (*ptrDebounceCnt))
+        {
+            /* Decrement debounce counter */
+            (*ptrDebounceCnt)--;
+        }
+
+        /* No touch */
+        if (ptrSnsCxt->diff <= touchTh)
+        {
+            /* Reset debounce counter */
+            *ptrDebounceCnt = ptrWdCxt->onDebounce;
+            ptrSnsCxt->status = 0u;
+        }
+
+        /* New touch or touch still exists */
+        if (0u == (*ptrDebounceCnt))
+        {
+            ptrSnsCxt->status = CY_CAPSENSE_SNS_TOUCH_STATUS_MASK;
+        }
+
+        /* Update information about active row/col sensors */
+        if (0u != ptrSnsCxt->status)
+        {
+            if (snsIndex < colNumber)
+            {
+                numActiveCols++;
+                activeCol = snsIndex;
+            }
+            else
+            {
+                numActiveRows++;
+                activeRow = snsIndex - colNumber;
+            }
+        }
+
+        ptrSnsCxt++;
+        ptrDebounceCnt++;
+    }
+
+    /*
+    * Number of touches (numActiveCols * numActiveRows):
+    * 0 -> No touch
+    * 1 -> One touch
+    * 2+ -> Multiple touches
+    */
+
+    ptrWdCxt->wdTouch.numPosition = (uint8_t)(numActiveCols * numActiveRows);
+    if (ptrWdCxt->wdTouch.numPosition > CY_CAPSENSE_POSITION_ONE)
+    {
+        ptrWdCxt->wdTouch.numPosition = CY_CAPSENSE_POSITION_MULTIPLE;
+    }
+
+    if (CY_CAPSENSE_POSITION_ONE == ptrWdCxt->wdTouch.numPosition)
+    {
+        ptrSnsTouch->x = (uint16_t)activeCol;
+        ptrSnsTouch->y = (uint16_t)activeRow;
+        ptrSnsTouch->z = 0u;
+        ptrSnsTouch->id = (uint16_t)((activeRow * colNumber) + activeCol);
+    }
+
+    /* Update widget status if any activity is detected (even non-valid) */
+    if ((0u != numActiveRows) || (0u != numActiveCols))
+    {
+        ptrWdCxt->status |= (uint8_t)CY_CAPSENSE_WD_ACTIVE_MASK;
+    }
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessCsdTouchpad
+****************************************************************************//**
+*
+* Processes status of the CSD Touchpad widget. This includes running
+* Centroid algorithm and updating status in the Data Structure registers.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_DpProcessCsdTouchpad(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+    uint32_t touchTh;
+    uint32_t wdActiveCol = 0uL;
+    uint32_t wdActiveRow = 0uL;
+    uint8_t * ptrDebounceCnt = ptrWdConfig->ptrDebounceArr;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+    uint32_t sensorNumber = ptrWdConfig->numSns;
+    uint32_t colNumber = ptrWdConfig->numCols;
+    uint32_t rowNumber = ptrWdConfig->numRows;
+    cy_stc_capsense_position_t newPosition[CY_CAPSENSE_MAX_CENTROIDS];
+    cy_stc_capsense_touch_t newTouch = {&newPosition[0u], CY_CAPSENSE_POSITION_NONE};
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_BALLISTIC_MULTIPLIER_EN)
+        cy_stc_capsense_ballistic_delta_t delta;
+    #endif
+
+    /* Calculate touch threshold based on current sensor state */
+    touchTh = (0u == (ptrWdCxt->status & CY_CAPSENSE_WD_ACTIVE_MASK)) ?
+              ((uint32_t)ptrWdCxt->fingerTh + ptrWdCxt->hysteresis) :
+              ((uint32_t)ptrWdCxt->fingerTh - ptrWdCxt->hysteresis);
+
+    if (0u < (*ptrDebounceCnt))
+    {
+        /* Decrement debounce counter */
+        (*ptrDebounceCnt)--;
+    }
+
+    /* Widget is considered as active if at least one sensor is active on both axes */
+    for (snsIndex = colNumber; snsIndex-- > 0uL;)
+    {
+        ptrSnsCxt->status = (touchTh < ptrSnsCxt->diff) ? CY_CAPSENSE_SNS_TOUCH_STATUS_MASK : 0u;
+        wdActiveCol |= ptrSnsCxt->status;
+        ptrSnsCxt++;
+    }
+    for (snsIndex = rowNumber; snsIndex-- > 0uL;)
+    {
+        ptrSnsCxt->status = (touchTh < ptrSnsCxt->diff) ? CY_CAPSENSE_SNS_TOUCH_STATUS_MASK : 0u;
+        wdActiveRow |= ptrSnsCxt->status;
+        ptrSnsCxt++;
+    }
+
+    /* No touch detected */
+    if ((0uL == wdActiveCol) || (0uL == wdActiveRow))
+    {
+        /* Reset debounce counter */
+        (*ptrDebounceCnt) = ptrWdCxt->onDebounce;
+        ptrWdCxt->status &= (uint8_t)(~CY_CAPSENSE_WD_ACTIVE_MASK);
+    }
+    if (0u == (*ptrDebounceCnt))
+    {
+        /* New touch detected or touch still exists from previous cycle */
+        ptrWdCxt->status |= CY_CAPSENSE_WD_ACTIVE_MASK;
+    }
+    else
+    {
+        if ((0uL != wdActiveCol) && (0uL != wdActiveRow))
+        {
+            /* Clear sensor state if activity was detected but debounce was not passed */
+            ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+            for (snsIndex = sensorNumber; snsIndex-- > 0uL;)
+            {
+                ptrSnsCxt->status = 0u;
+                ptrSnsCxt++;
+            }
+        }
+    }
+
+    /* If widget is still active after debounce run the centroid algorithm */
+    if (CY_CAPSENSE_WD_ACTIVE_MASK == (ptrWdCxt->status & CY_CAPSENSE_WD_ACTIVE_MASK))
+    {
+        /* 3x3 CSD Touchpad processing */
+        if (0u != (ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_3X3_MASK))
+        {
+            /* Centroid processing */
+            Cy_CapSense_DpCentroidTouchpad(&newTouch, ptrWdConfig);
+        }
+        #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_ADVANCED_CENTROID_5X5_EN)
+            /* 5x5 Advanced CSD Touchpad processing */
+            if (0u != (ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_5X5_MASK))
+            {
+                /* Centroid processing */
+                Cy_CapSense_DpAdvancedCentroidTouchpad(&newTouch, ptrWdConfig);
+            }
+        #endif
+    }
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_POSITION_FILTER_EN)
+        /* Position filtering */
+        if (0u != (ptrWdConfig->posFilterConfig & CY_CAPSENSE_POSITION_FILTERS_MASK))
+        {
+            Cy_CapSense_ProcessPositionFilters(&newTouch, ptrWdConfig);
+        }
+    #endif
+
+    /* Copy positions into public structure */
+    ptrWdCxt->wdTouch.numPosition = newTouch.numPosition;
+    if (CY_CAPSENSE_POSITION_MULTIPLE != ptrWdCxt->wdTouch.numPosition)
+    {
+        for (snsIndex = 0u; snsIndex < newTouch.numPosition; snsIndex++)
+        {
+            ptrWdCxt->wdTouch.ptrPosition[snsIndex] = newTouch.ptrPosition[snsIndex];
+        }
+    }
+
+
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_BALLISTIC_MULTIPLIER_EN)
+        /* Ballistic Multiplier Filtering */
+        if (0u != (ptrWdConfig->centroidConfig & CY_CAPSENSE_CENTROID_BALLISTIC_MASK))
+        {
+            Cy_CapSense_BallisticMultiplier_Lib(&ptrWdConfig->ballisticConfig,
+                                                &ptrWdCxt->wdTouch,
+                                                &delta,
+                                                context->ptrCommonContext->timestamp,
+                                                ptrWdConfig->ptrBallisticContext);
+            ptrWdCxt->xDelta = delta.deltaX;
+            ptrWdCxt->yDelta = delta.deltaY;
+        }
+    #else
+        (void) context;
+    #endif
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN) */
+
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_DpProcessCsxTouchpad
+****************************************************************************//**
+*
+* Processes the status of the CSX Touchpad widget.
+* The process involves running the 3x3 centroid algorithm with the
+* tracking of finger id.
+*
+* \param ptrWdConfig
+* The pointer to the widget configuration structure.
+*
+*******************************************************************************/
+void Cy_CapSense_DpProcessCsxTouchpad(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig)
+{
+    uint32_t touchTh;
+    uint32_t snsIndex;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = ptrWdConfig->ptrSnsContext;
+    cy_stc_capsense_widget_context_t * ptrWdCxt = ptrWdConfig->ptrWdContext;
+
+    /* Calculate touch threshold based on current sensor state */
+    touchTh = (0u == (ptrWdCxt->status & CY_CAPSENSE_WD_ACTIVE_MASK)) ?
+              ((uint32_t)ptrWdCxt->fingerTh + ptrWdCxt->hysteresis) :
+              ((uint32_t)ptrWdCxt->fingerTh - ptrWdCxt->hysteresis);
+
+    for (snsIndex = 0u; snsIndex < ptrWdConfig->numSns; snsIndex++)
+    {
+        ptrSnsCxt->status = (touchTh < ptrSnsCxt->diff) ? CY_CAPSENSE_SNS_TOUCH_STATUS_MASK : 0u;
+        ptrSnsCxt++;
+    }
+
+    /* Check whether sensors are active and located all local maxima */
+    Cy_CapSense_DpFindLocalMaxDd(ptrWdConfig);
+    /* Calculate centroid position for all found local maxima */
+    Cy_CapSense_DpCalcTouchPadCentroid(ptrWdConfig);
+    /* Identify all touches and assign them correct ID based on historical data */
+    Cy_CapSense_DpTouchTracking(ptrWdConfig);
+    /* Filter the position data and write it into data structure */
+    Cy_CapSense_DpFilterTouchRecord(ptrWdConfig);
+}
+#endif /* (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN) */
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunMfsFiltering
+****************************************************************************//**
+*
+* Selects the median difference signal when the multi-frequency scan is enabled.
+*
+* \param ptrSnsContext
+* The pointer to the widget configuration structure.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_RunMfsFiltering(
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                const cy_stc_capsense_context_t * context)
+{
+    ptrSnsContext->diff = (uint16_t)Cy_CapSense_FtMedian((uint32_t)ptrSnsContext->diff,
+                  (uint32_t)ptrSnsContext[CY_CAPSENSE_MFS_CH1_INDEX * context->ptrCommonConfig->numSns].diff,
+                  (uint32_t)ptrSnsContext[CY_CAPSENSE_MFS_CH2_INDEX * context->ptrCommonConfig->numSns].diff);
+}
+#endif
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_PHASE_ENABLED)
+/*******************************************************************************
+* Function Name: Cy_CapSense_ProcessWidgetMptxDeconvolution
+****************************************************************************//**
+*
+* Performs raw count deconvolution for the specified CSX widget when
+* Multi-phase Tx is enabled.
+*
+* This function decodes raw counts received after scanning into normal view by
+* performing deconvolution algorithm. If the function is called for a widget with
+* disabled Multi-phase Tx, the function returns CY_CAPSENSE_STATUS_BAD_DATA.
+*
+* No need to call this function from application layer since the
+* Cy_CapSense_ProcessAllWidgets() and Cy_CapSense_ProcessWidget() functions calls
+* deconvolution automatically.
+*
+* DAC auto-calibration when enabled performs sensor auto-calibration without
+* performing deconvolution.
+* The deconvolution algorithm for even number of TX electrodes decreases raw count
+* level twice (keeping the signal on the same level).
+*
+* If specific processing is implemented using the Cy_CapSense_ProcessWidgetExt()
+* and Cy_CapSense_ProcessSensorExt() function then a call of this function is
+* required prior doing the specific processing.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the processing operation.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_ProcessWidgetMptxDeconvolution(
+                uint32_t widgetId,
+                cy_stc_capsense_context_t * context)
+{
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+    uint32_t idx;
+    uint32_t sumIdx;
+    uint32_t ceIdx;
+    uint32_t rotIdx;
+    /* Order of multi-TX sequence */
+    uint32_t mptxOrderLocal;
+    int32_t localBuf[CY_CAPSENSE_MPTX_MAX_ORDER];
+    int16_t deconvCoefRot[CY_CAPSENSE_MAX_TX_PATTERN_NUM * 2u];
+    int32_t accum;
+    uint32_t accumTmp;
+    cy_capsense_status_t result = CY_CAPSENSE_STATUS_BAD_DATA;
+    uint32_t freqChIndex;
+
+    ptrWdCfg = &context->ptrWdConfig[widgetId];
+    mptxOrderLocal = ptrWdCfg->mptxOrder;
+    if (mptxOrderLocal >= CY_CAPSENSE_MPTX_MIN_ORDER)
+    {
+        result = CY_CAPSENSE_STATUS_SUCCESS;
+
+        (void)memcpy(&deconvCoefRot[0], (const void *)&ptrWdCfg->ptrMptxTable->deconvCoef[0u], mptxOrderLocal * CY_CAPSENSE_BYTES_IN_16_BITS);
+        (void)memcpy(&deconvCoefRot[mptxOrderLocal], (const void *)&ptrWdCfg->ptrMptxTable->deconvCoef[0u], mptxOrderLocal * CY_CAPSENSE_BYTES_IN_16_BITS);
+
+        for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+        {
+            ceIdx = (uint32_t)ptrWdCfg->numRows * ptrWdCfg->numCols;
+            while (ceIdx >= mptxOrderLocal)
+            {
+                ceIdx -= mptxOrderLocal;
+                /* Copy vector formed by RX[rxIdx] and TX[txIdx..txIdx+mptxOrderLocal]
+                * from sensors to localBuf */
+                idx = mptxOrderLocal;
+                while (0u != idx--)
+                {
+                    localBuf[idx] = (int32_t)ptrWdCfg->ptrSnsContext[idx + ceIdx +
+                                    (context->ptrCommonConfig->numSns * freqChIndex)].raw;
+                }
+
+                /* Multiply vector stored in localBuf by the matrix of deconvolution coefficients. */
+                idx = mptxOrderLocal;
+                while (0u != idx--)
+                {
+                    accum = 0;
+                    rotIdx = idx + mptxOrderLocal - 1u;
+                    sumIdx = mptxOrderLocal;
+                    while (0u != sumIdx--)
+                    {
+                        accum += localBuf[sumIdx] * deconvCoefRot[rotIdx];
+                        rotIdx--;
+                    }
+
+                    if (0 > accum)
+                    {
+                        accumTmp = 0u;
+                    }
+                    else
+                    {
+                        accumTmp = (uint32_t)accum;
+
+                        /* Shift the result in such a way that guarantees no overflow */
+                        accumTmp >>= CY_CAPSENSE_SCALING_SHIFT;
+
+                        if ((uint32_t)UINT16_MAX < accumTmp)
+                        {
+                            accumTmp = UINT16_MAX;
+                        }
+                    }
+
+                    /* Convert the result to unsigned 16 bit and store in the target buffer */
+                    ptrWdCfg->ptrSnsContext[idx + ceIdx +
+                                    (context->ptrCommonConfig->numSns * freqChIndex)].raw = (uint16_t)accumTmp;
+                }
+            }
+        }
+    }
+    return result;
+}
+#endif
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_PreProcessWidget
+****************************************************************************//**
+*
+* Executes the pre-processing of scan raw data for specified widgets.
+*
+* This function is called prior any other processing function for
+* the fifth CAPSENSE&trade; HW generation. The pre-processing routine implements
+* the following operations:
+* - Executes the CIC2 pre-processing if the filter mode is set to CIC2.
+* - Limits raw count to maximum value.
+* - Executes the raw data inversion for the CSX sensors.
+*
+* No need to call this function from application layer since the
+* Cy_CapSense_ProcessAllWidgets() and Cy_CapSense_ProcessWidget() functions
+* calls it automatically.
+*
+* If specific processing is implemented using the Cy_CapSense_ProcessWidgetExt()
+* and Cy_CapSense_ProcessSensorExt() function then a call of this function is
+* required prior doing the specific processing. If Multi-phase TX is enabled
+* then deconvolution should be executed after call of this function using
+* the Cy_CapSense_ProcessWidgetMptxDeconvolution() function.
+*
+* \param widgetId
+* The widget ID, for which the pre-processing should be executed.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_PreProcessWidget(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    /* Adjusts raw count if CIC2 enabled */
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN)
+        Cy_CapSense_PreProcessWidgetCic2Raw(widgetId, context);
+    #endif
+
+    /* Limit raw count to the maximum possible raw count value */
+    Cy_CapSense_PreProcessWidgetLimitRaw(widgetId, context);
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+        /* Inverts raw count for CSX widgets */
+        if(CY_CAPSENSE_CSX_GROUP == context->ptrWdConfig[widgetId].senseMethod)
+        {
+            Cy_CapSense_PreProcessWidgetInvertRaw(widgetId, context);
+        }
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_PreProcessSensor
+****************************************************************************//**
+*
+* Executes the pre-processing of scan raw data for specified sensor.
+*
+* This function is called prior any other processing function for
+* the fifth CAPSENSE&trade; HW generation. The pre-processing routine implements
+* the following operations:
+* - Executes the CIC2 pre-processing if the filter mode is set to CIC2.
+* - Limits raw count to maximum value.
+* - Executes the raw data inversion for the CSX sensors.
+*
+* No need to call this function from application layer since the
+* Cy_CapSense_ProcessAllWidgets() and Cy_CapSense_ProcessWidget() functions
+* calls it automatically.
+*
+* If specific processing is implemented using the Cy_CapSense_ProcessWidgetExt()
+* and Cy_CapSense_ProcessSensorExt() function then a call of this function is
+* required prior doing the specific processing. If Multi-phase TX is enabled
+* then deconvolution should be executed after pre-processing of all sensors
+* of the specified widget using the Cy_CapSense_ProcessWidgetMptxDeconvolution()
+* function.
+*
+* \param widgetId
+* The widget ID, for which the pre-processing should be executed.
+*
+* \param sensorId
+* The sensor ID, for which the pre-processing should be executed.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_PreProcessSensor(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                const cy_stc_capsense_context_t * context)
+{
+    /* Adjusts raw count if CIC2 enabled */
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN)
+        Cy_CapSense_PreProcessSensorCic2Raw(widgetId, sensorId, context);
+    #endif
+
+    /* Limit raw count to the maximum possible raw count value */
+    Cy_CapSense_PreProcessSensorLimitRaw(widgetId, sensorId, context);
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+        /* Inverts raw count for CSX widgets */
+        if(CY_CAPSENSE_CSX_GROUP == context->ptrWdConfig[widgetId].senseMethod)
+        {
+            Cy_CapSense_PreProcessSensorInvertRaw(widgetId, sensorId, context);
+        }
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_PreProcessWidgetLimitRaw
+****************************************************************************//**
+*
+* This internal function limits the raw data for specified
+* widgets to the maximum possible raw data for the specified CAPSENSE&trade;
+* configuration.
+*
+* \param widgetId
+* The widget ID, for which the pre-processing should be executed.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_PreProcessWidgetLimitRaw(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = &ptrWdCfg->ptrSnsContext[0u];
+    uint32_t maxCount = ptrWdCfg->ptrWdContext->maxRawCount;
+
+    for(snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
+    {
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+            if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && (ptrWdCfg->numCols <= snsIndex))
+            {
+                maxCount = ptrWdCfg->ptrWdContext->maxRawCountRow;
+            }
+        #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+        if((uint32_t)ptrSnsCxt->raw > maxCount)
+        {
+            ptrSnsCxt->raw = (uint16_t)maxCount;
+        }
+        ptrSnsCxt++;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_PreProcessSensorLimitRaw
+****************************************************************************//**
+*
+* This internal function limits the raw data for specified
+* widgets to the maximum possible raw data for the specified CAPSENSE&trade;
+* configuration.
+*
+* \param widgetId
+* The widget ID, for which the pre-processing should be executed.
+*
+* \param sensorId
+* The sensor ID, for which the pre-processing should be executed.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_PreProcessSensorLimitRaw(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                const cy_stc_capsense_context_t * context)
+{
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = &ptrWdCfg->ptrSnsContext[sensorId];
+    uint32_t maxCount = ptrWdCfg->ptrWdContext->maxRawCount;
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+        if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && (ptrWdCfg->numCols <= sensorId))
+        {
+            maxCount = ptrWdCfg->ptrWdContext->maxRawCountRow;
+        }
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+    if((uint32_t)ptrSnsCxt->raw > maxCount)
+    {
+        ptrSnsCxt->raw = (uint16_t)maxCount;
+    }
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_PreProcessWidgetInvertRaw
+****************************************************************************//**
+*
+* This internal function executes the raw data inversion for specified
+* widgets. Raw data is inverted relative to the theoretical MAX value.
+*
+* \param widgetId
+* The widget ID, for which the pre-processing should be executed.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_PreProcessWidgetInvertRaw(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = &ptrWdCfg->ptrSnsContext[0u];
+    uint32_t maxCount = ptrWdCfg->ptrWdContext->maxRawCount;
+
+    for(snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
+    {
+        ptrSnsCxt->raw = (uint16_t)(maxCount - ptrSnsCxt->raw);
+        ptrSnsCxt++;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_PreProcessSensorInvertRaw
+****************************************************************************//**
+*
+* This internal function executes the raw data inversion for specified
+* sensors. The raw data is inverted relative to the theoretical MAX value.
+*
+* \param widgetId
+* The widget ID, for which the pre-processing should be executed.
+*
+* \param sensorId
+* The sensor ID, for which the pre-processing should be executed.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_PreProcessSensorInvertRaw(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                const cy_stc_capsense_context_t * context)
+{
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = &ptrWdCfg->ptrSnsContext[sensorId];
+    uint32_t maxCount = ptrWdCfg->ptrWdContext->maxRawCount;
+
+    ptrSnsCxt->raw = (uint16_t)(maxCount - ptrSnsCxt->raw);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_PreProcessWidgetCic2Raw
+****************************************************************************//**
+*
+* This internal function executes the pre-processing
+* of raw data, for specified widgets produced by the fifth CAPSENSE&trade; HW generation with the
+* filter mode set to CIC2.
+*
+* \param widgetId
+* The widget ID, for which the pre-processing should be executed.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_PreProcessWidgetCic2Raw(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t snsIndex;
+    uint32_t tmpVal;
+    uint32_t clkDivider;
+    uint32_t cic2Samples;
+    uint32_t cic2Divider;
+
+    #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) ||\
+        (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+        uint32_t cic2SamplesRow;
+        uint32_t cic2DividerRow;
+        uint32_t twoDimWidget = 0u;
+    #endif
+
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = &ptrWdCfg->ptrSnsContext[0u];
+
+    clkDivider = context->ptrWdContext[widgetId].snsClk;
+    cic2Samples = ((clkDivider * ptrWdCfg->ptrWdContext->numSubConversions /
+                    ptrWdCfg->ptrWdContext->cicRate) - 1u) * ptrWdCfg->numChopCycles;
+    cic2Divider = Cy_CapSense_GetCIC2HwDivider(cic2Samples);
+
+    #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) ||\
+        (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+        if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) &&
+            (((uint8_t)CY_CAPSENSE_WD_MATRIX_BUTTON_E == ptrWdCfg->wdType) ||
+             ((uint8_t)CY_CAPSENSE_WD_TOUCHPAD_E == ptrWdCfg->wdType)))
+        {
+            twoDimWidget = 1u;
+            clkDivider = context->ptrWdContext[widgetId].rowSnsClk;
+            cic2SamplesRow = ((clkDivider * ptrWdCfg->ptrWdContext->numSubConversions /
+                            ptrWdCfg->ptrWdContext->cicRate) - 1u) * ptrWdCfg->numChopCycles;
+            cic2DividerRow = Cy_CapSense_GetCIC2HwDivider(cic2SamplesRow);
+        }
+    #endif
+
+    for(snsIndex = 0u; snsIndex < ptrWdCfg->numSns; snsIndex++)
+    {
+        #if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN) ||\
+            (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN))
+            if ((0u != twoDimWidget) && (ptrWdCfg->numCols <= snsIndex))
+            {
+                tmpVal = ((uint32_t)ptrSnsCxt->raw * cic2DividerRow) / cic2SamplesRow;
+            }
+            else
+            {
+                tmpVal = ((uint32_t)ptrSnsCxt->raw * cic2Divider) / cic2Samples;
+            }
+        #else
+            tmpVal = ((uint32_t)ptrSnsCxt->raw * cic2Divider) / cic2Samples;
+        #endif
+
+        if (tmpVal > CY_CAPSENSE_16_BIT_MASK)
+        {
+            tmpVal = CY_CAPSENSE_16_BIT_MASK;
+        }
+        ptrSnsCxt->raw = (uint16_t)tmpVal;
+        ptrSnsCxt++;
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_PreProcessSensorCic2Raw
+****************************************************************************//**
+*
+* This internal function executes the pre-processing of raw data
+* produced by the fifth CAPSENSE&trade; HW generation with the filter mode set
+* to CIC2.
+*
+* \param widgetId
+* The widget ID, for which the pre-processing should be executed.
+*
+* \param sensorId
+* The sensor ID, for which the pre-processing should be executed.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_PreProcessSensorCic2Raw(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t tmpVal;
+    uint32_t clkDivider;
+    uint32_t cic2Samples;
+    uint32_t cic2Divider;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg = &context->ptrWdConfig[widgetId];
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt = &ptrWdCfg->ptrSnsContext[sensorId];
+
+    clkDivider = context->ptrWdContext[widgetId].snsClk;
+    if ((CY_CAPSENSE_CSD_GROUP == ptrWdCfg->senseMethod) && (ptrWdCfg->numCols <= sensorId))
+    {
+        clkDivider = context->ptrWdContext[widgetId].rowSnsClk;
+    }
+
+    cic2Samples = ((clkDivider * ptrWdCfg->ptrWdContext->numSubConversions /
+                    ptrWdCfg->ptrWdContext->cicRate) - 1u) * ptrWdCfg->numChopCycles;
+    cic2Divider = Cy_CapSense_GetCIC2HwDivider(cic2Samples);
+
+    tmpVal = ((uint32_t)ptrSnsCxt->raw * cic2Divider) / cic2Samples;
+    if (tmpVal > CY_CAPSENSE_16_BIT_MASK)
+    {
+        tmpVal = CY_CAPSENSE_16_BIT_MASK;
+    }
+    ptrSnsCxt->raw = (uint16_t)tmpVal;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_GetCIC2HwDivider
+****************************************************************************//**
+*
+* This internal function determines the value of the divider that will be
+* applied to the data, accumulated by the CIC2 HW for the specified number of
+* samples.
+*
+* \param cic2Samples
+* The number of CIC2 samples for the specified sensing parameters. This value
+* can be obtained by using the Cy_CapSense_GetCIC2SamplesNum function.
+*
+* \return
+* The CIC2 HW divider value.
+*
+*******************************************************************************/
+uint32_t Cy_CapSense_GetCIC2HwDivider(
+                uint32_t cic2Samples)
+{
+    uint32_t cic2Divider;
+
+    if(cic2Samples > CY_CAPSENSE_CIC2_DIVIDER_8)
+    {
+        cic2Divider = CY_CAPSENSE_CIC2_DIVIDER_16;
+    }
+    else if(cic2Samples > CY_CAPSENSE_CIC2_DIVIDER_4)
+    {
+        cic2Divider = CY_CAPSENSE_CIC2_DIVIDER_8;
+    }
+    else if(cic2Samples > CY_CAPSENSE_CIC2_DIVIDER_2)
+    {
+        cic2Divider = CY_CAPSENSE_CIC2_DIVIDER_4;
+    }
+    else if(cic2Samples > CY_CAPSENSE_CIC2_DIVIDER_1)
+    {
+        cic2Divider = CY_CAPSENSE_CIC2_DIVIDER_2;
+    }
+    else
+    {
+        cic2Divider = CY_CAPSENSE_CIC2_DIVIDER_1;
+    }
+
+    return(cic2Divider);
+}
+#endif /* #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN) */
+
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunMfsMedian
+****************************************************************************//**
+*
+* Applies the median filter to the specified multi-frequency widget and updates
+* the specified widget diff counts.
+*
+* This function is a low-level function and is called automatically by
+* high-level processing functions like Cy_CapSense_ProcessWidget()
+* and Cy_CapSense_ProcessAllWidgets().
+*
+* It is not recommended to use this function directly on application level.
+*
+* The function applies the median filter to diff count of each sensor of the
+* specified widget (with enabled multi-frequency feature) and update the diff
+* count of the specified main widget.
+*
+* This function is needed to implement customer-specific use cases.
+*
+* \note
+* This function is available only for the fifth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget. A macro for the widget ID can be found
+* in the cycfg_capsense.h file defined as CY_CAPSENSE_<WIDGET_NAME>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the widget processing:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is successfully completed
+* - CY_CAPSENSE_STATUS_BAD_PARAM     - The input parameter is invalid
+* either widgetId is not valid or multi-frequency is not enabled for this widget
+* or the specified widgetId is derivative of the main widget.
+*
+*******************************************************************************/
+cy_capsense_status_t Cy_CapSense_RunMfsMedian(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context)
+{
+    cy_capsense_status_t result = CY_CAPSENSE_STATUS_BAD_PARAM;
+
+    uint32_t snsIndex;
+    const cy_stc_capsense_widget_config_t * ptrWdCfg;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt0;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt1;
+    cy_stc_capsense_sensor_context_t * ptrSnsCxt2;
+
+    /* Check parameter validity */
+    if (widgetId < context->ptrCommonConfig->numWd)
+    {
+        ptrWdCfg = &context->ptrWdConfig[widgetId];
+        ptrSnsCxt0 = ptrWdCfg[CY_CAPSENSE_MFS_CH0_INDEX].ptrSnsContext;
+        ptrSnsCxt1 = ptrWdCfg[CY_CAPSENSE_MFS_CH1_INDEX].ptrSnsContext;
+        ptrSnsCxt2 = ptrWdCfg[CY_CAPSENSE_MFS_CH2_INDEX].ptrSnsContext;
+
+        if (((ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_EN_MASK) != 0u) &&
+            ((ptrWdCfg->mfsConfig & CY_CAPSENSE_MFS_WIDGET_FREQ_ALL_CH_MASK) == 0u))
+        {
+            /* Calculate median */
+            for (snsIndex = ptrWdCfg->numSns; snsIndex-- > 0u;)
+            {
+                ptrSnsCxt0->diff = (uint16_t)Cy_CapSense_FtMedian(ptrSnsCxt0->diff,
+                                                                  ptrSnsCxt1->diff,
+                                                                  ptrSnsCxt2->diff);
+                ptrSnsCxt0++;
+                ptrSnsCxt1++;
+                ptrSnsCxt2++;
+            }
+            result = CY_CAPSENSE_STATUS_SUCCESS;
+        }
+    }
+
+    return (result);
+}
+#endif
+
+#endif /* CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN */
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+
+/* [] END OF FILE */

+ 218 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_processing.h

@@ -0,0 +1,218 @@
+/***************************************************************************//**
+* \file cy_capsense_processing.h
+* \version 3.0
+*
+* \brief
+* This file provides the function prototypes for the Data Processing module.
+* The Data Processing module is responsible for the low level raw counts
+* processing provided by the sensing module, maintaining baseline and
+* difference values and performing high-level widget processing like updating
+* button status or calculating slider position.
+*
+********************************************************************************
+* \copyright
+* Copyright 2018-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_PROCESSING_H)
+#define CY_CAPSENSE_PROCESSING_H
+
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_lib.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+/******************************************************************************/
+/** \addtogroup group_capsense_high_level *//** \{ */
+/******************************************************************************/
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_GESTURE_EN)
+    uint32_t Cy_CapSense_DecodeWidgetGestures(
+                    uint32_t widgetId,
+                    const cy_stc_capsense_context_t * context);
+#endif
+/** \} */
+
+/******************************************************************************/
+/** \addtogroup group_capsense_low_level *//** \{ */
+/******************************************************************************/
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_GESTURE_EN)
+    void Cy_CapSense_InitializeWidgetGestures(
+                    uint32_t widgetId,
+                    const cy_stc_capsense_context_t * context);
+#endif
+void Cy_CapSense_InitializeAllStatuses(const cy_stc_capsense_context_t * context);
+void Cy_CapSense_InitializeWidgetStatus(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_PHASE_ENABLED)
+        cy_capsense_status_t Cy_CapSense_ProcessWidgetMptxDeconvolution(
+                        uint32_t widgetId,
+                        cy_stc_capsense_context_t * context);
+    #endif
+void Cy_CapSense_PreProcessWidget(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context);
+void Cy_CapSense_PreProcessSensor(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                const cy_stc_capsense_context_t * context);
+    #if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_WIDGET_EN)
+        cy_capsense_status_t Cy_CapSense_RunMfsMedian(
+                        uint32_t widgetId,
+                        const cy_stc_capsense_context_t * context);
+    #endif
+#endif
+
+/** \} */
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+#if((CY_CAPSENSE_DISABLE != CY_CAPSENSE_BUTTON_EN) ||\
+    (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_MATRIX_EN))
+    void Cy_CapSense_DpProcessButton(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSX_TOUCHPAD_EN)
+    void Cy_CapSense_DpProcessCsxTouchpad(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_PROXIMITY_EN)
+    void Cy_CapSense_DpProcessProximity(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_TOUCHPAD_EN)
+    void Cy_CapSense_DpProcessCsdTouchpad(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                    const cy_stc_capsense_context_t * context);
+#endif
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_SLIDER_EN)
+    void Cy_CapSense_DpProcessSlider(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+
+#if(CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_MATRIX_EN)
+    void Cy_CapSense_DpProcessCsdMatrix(
+                    const cy_stc_capsense_widget_config_t * ptrWdConfig);
+#endif
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+void Cy_CapSense_DpProcessCsdWidgetStatus(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_context_t * context);
+
+uint32_t Cy_CapSense_DpProcessCsdWidgetRawCounts(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context);
+
+uint32_t Cy_CapSense_DpProcessCsdSensorRawCountsExt(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory,
+                uint8_t * ptrSnsRawHistoryLow,
+                uint32_t mode,
+                uint16_t * ptrBslnInvSns,
+                const cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+void Cy_CapSense_DpProcessCsxWidgetStatus(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig);
+
+uint32_t Cy_CapSense_DpProcessCsxWidgetRawCounts(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context);
+
+uint32_t Cy_CapSense_DpProcessCsxSensorRawCountsExt(
+                const cy_stc_capsense_widget_config_t * ptrWdConfig,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                uint16_t * ptrSnsRawHistory,
+                uint8_t * ptrSnsRawHistoryLow,
+                uint32_t mode,
+                uint16_t * ptrSnsBslnInv,
+                const cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+void Cy_CapSense_DpUpdateDifferences(
+                const cy_stc_capsense_widget_context_t * ptrWdContext,
+                cy_stc_capsense_sensor_context_t * ptrSnsContext);
+
+void Cy_CapSense_DpUpdateThresholds(
+                cy_stc_capsense_widget_context_t * ptrWdContext,
+                const cy_stc_capsense_smartsense_csd_noise_envelope_t * ptrNoiseEnvelope,
+                uint32_t startFlag);
+
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_MULTI_FREQUENCY_SCAN_EN)
+    void Cy_CapSense_RunMfsFiltering(
+                    cy_stc_capsense_sensor_context_t * ptrSnsContext,
+                    const cy_stc_capsense_context_t * context);
+#endif
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+void Cy_CapSense_PreProcessWidgetInvertRaw(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context);
+void Cy_CapSense_PreProcessSensorInvertRaw(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                const cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+void Cy_CapSense_PreProcessWidgetLimitRaw(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context);
+void Cy_CapSense_PreProcessSensorLimitRaw(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                const cy_stc_capsense_context_t * context);
+#if (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CIC2_FILTER_EN)
+void Cy_CapSense_PreProcessWidgetCic2Raw(
+                uint32_t widgetId,
+                const cy_stc_capsense_context_t * context);
+void Cy_CapSense_PreProcessSensorCic2Raw(
+                uint32_t widgetId,
+                uint32_t sensorId,
+                const cy_stc_capsense_context_t * context);
+uint32_t Cy_CapSense_GetCIC2HwDivider(
+                uint32_t cic2Samples);
+#endif
+
+#endif /* CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN */
+/** \} \endcond */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+#endif /* CY_CAPSENSE_PROCESSING_H */
+
+
+/* [] END OF FILE */

+ 708 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest.c

@@ -0,0 +1,708 @@
+/***************************************************************************//**
+* \file cy_capsense_selftest.c
+* \version 3.0
+*
+* \brief
+* This file provides the source code to the Built-in Self-test (BIST)
+* functions.
+*
+********************************************************************************
+* \copyright
+* Copyright 2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include <stddef.h>
+#include <string.h>
+#include "cy_capsense_selftest.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN)
+
+/*******************************************************************************
+* 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_BIST_RUN_AVAILABLE_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:
+* for the fourth-generation CAPSENSE&trade;:
+* - Cy_CapSense_CheckCRCWidget()
+* - Cy_CapSense_CheckIntegritySensorPins()
+* - Cy_CapSense_MeasureCapacitanceSensor()
+* - Cy_CapSense_MeasureCapacitanceShield()
+* - Cy_CapSense_MeasureCapacitanceCap()
+* - Cy_CapSense_MeasureVdda()
+* for the fifth-generation CAPSENSE&trade;:
+* - Cy_CapSense_CheckCRCWidget()
+* - Cy_CapSense_CheckIntegritySensorPins()
+* - Cy_CapSense_MeasureCapacitanceSensorElectrode()
+* - Cy_CapSense_MeasureCapacitanceSlotSensors()
+* - Cy_CapSense_MeasureCapacitanceShieldElectrode()
+*
+* 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_MASK       - Verifies the RAM widget structure CRC
+*                                          for all the widgets.
+* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK  - Checks all the sensors for a short
+*                                          to GND / VDD / other sensors.
+* - CY_CAPSENSE_BIST_SNS_CAP_MASK        - Measures all the sensors capacitance.
+* - CY_CAPSENSE_BIST_ELTD_CAP_MASK       - Measures all the electrodes capacitance
+*                                          (only for the fifth-generation CAPSENSE&trade;).
+* - CY_CAPSENSE_BIST_SHIELD_CAP_MASK     - Measures the shield capacitance.
+* - CY_CAPSENSE_BIST_EXTERNAL_CAP_MASK   - Measures the capacitance of the available
+*                                          external capacitors
+*                                          (only for the fourth-generation CAPSENSE&trade;).
+* - CY_CAPSENSE_BIST_VDDA_MASK           - Measures the VDDA voltage
+*                                          (only for the fourth-generation CAPSENSE&trade;).
+* - CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK
+*                                        - Executes all available tests.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_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)
+
+{
+    cy_en_capsense_bist_status_t result;
+
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+        result = Cy_CapSense_RunSelfTest_V3(testEnMask, context);
+    #else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
+        result = Cy_CapSense_RunSelfTest_V2(testEnMask, context);
+    #endif
+
+    return (result);
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+/*******************************************************************************
+* 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_MASK bit is set in the .testResultMask field.
+*
+* The function never clears the CY_CAPSENSE_BIST_CRC_WDGT_MASK bit.
+* If the CY_CAPSENSE_BIST_CRC_WDGT_MASK 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 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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_en_capsense_bist_status_t Cy_CapSense_CheckCRCWidget(
+                uint32_t widgetId,
+                cy_stc_capsense_context_t * context)
+{
+    cy_en_capsense_bist_status_t result;
+
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+        result = Cy_CapSense_CheckCRCWidget_V3(widgetId, context);
+    #else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
+        result = Cy_CapSense_CheckCRCWidget_V2(widgetId, context);
+    #endif
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)
+/*******************************************************************************
+* 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_MASK bit
+* in the .testResultMask field of the \ref cy_stc_capsense_bist_context_t
+* structure.
+*
+* The test is integrated into the CAPSENSE&trade; Middleware. All CAPSENSE&trade;
+* 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_CAPSENSE_STATUS_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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_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&trade; 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_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;
+
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+        result = Cy_CapSense_CheckIntegritySensorBaseline_V3(widgetId,
+                                                            sensorId,
+                                                            baselineHighLimit,
+                                                            baselineLowLimit,
+                                                            context);
+    #else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
+        result = Cy_CapSense_CheckIntegritySensorBaseline_V2(widgetId,
+                                                            sensorId,
+                                                            baselineHighLimit,
+                                                            baselineLowLimit,
+                                                            context);
+    #endif
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN)
+/*******************************************************************************
+* 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_MASK 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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_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&trade; 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_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;
+
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+        result = Cy_CapSense_CheckIntegritySensorRawcount_V3(widgetId,
+                                                            sensorId,
+                                                            rawcountHighLimit,
+                                                            rawcountLowLimit,
+                                                            context);
+    #else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
+        result = Cy_CapSense_CheckIntegritySensorRawcount_V2(widgetId,
+                                                            sensorId,
+                                                            rawcountHighLimit,
+                                                            rawcountLowLimit,
+                                                            context);
+    #endif
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+/*******************************************************************************
+* 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&trade; (such as sensors, Tx, Rx,
+*   shield electrodes, and external capacitors)
+* * Other non-CAPSENSE&trade; 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&trade; 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&trade; 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&trade; 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_INTEGRITY_MASK bit is set in the .testResultMask field
+*   of the \ref cy_stc_capsense_bist_context_t structure.
+* * If CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK 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_INTEGRITY_MASK 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_INTEGRITY_MASK mask.
+*
+* To detect an electrical short or fault condition with resistance
+* higher than 1500 ohm, the Cy_CapSense_MeasureCapacitanceSensor() (4th Generation)
+* or Cy_CapSense_MeasureCapacitanceSensorElectrode() (5th Generation) function can
+* be used as the fault condition affects the measured sensor capacitance.
+*
+* This test can be executed only if the CAPSENSE&trade; Middleware is in the IDLE
+* state. This function must not be called while CAPSENSE&trade; Middleware is busy.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; 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&trade; Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense_<WidgetName>_RX<RXNumber>_ID
+* * CapSense_<WidgetName>_TX<TXNumber>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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&trade; 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_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;
+
+    #if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+        result = Cy_CapSense_CheckIntegritySensorPins_V3(widgetId, sensorId, context);
+    #else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
+        result = Cy_CapSense_CheckIntegritySensorPins_V2(widgetId, sensorId, context);
+    #endif
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+
+/*******************************************************************************
+* 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&trade; start and performs
+* the \ref cy_stc_capsense_bist_context_t structure initialization 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()
+*
+* \note
+* Two last functions are available only for the fourth-generation CAPSENSE&trade;.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistDsInitialize(cy_stc_capsense_context_t * context)
+{
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+    Cy_CapSense_BistDsInitialize_V3(context);
+#else /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
+    Cy_CapSense_BistDsInitialize_V2(context);
+#endif
+}
+
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceCap
+****************************************************************************//**
+*
+* Measures the capacitance in picofarads of the specified CAPSENSE&trade; 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&trade; 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_EXTERNAL_CAP_MASK 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&trade; Middleware is in the IDLE
+* state. This function must not be called while the CAPSENSE&trade; Middleware is busy.
+* The function is blocking, i.e. waits for the measurement to be completed
+* prior to returning to the caller.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \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&trade; 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_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 bistStatus = CY_CAPSENSE_BIST_SUCCESS_E;
+
+    bistStatus = Cy_CapSense_MeasureCapacitanceCap_V2(integrationCapId,
+                                                     ptrValue,
+                                                     maxCapacitance,
+                                                     context);
+
+    return (bistStatus);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)
+/*******************************************************************************
+* 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&trade; middleware is in the IDLE
+* state. This function must not be called while the CAPSENSE&trade; middleware is busy.
+* The function is blocking, i.e. waits for the conversion to be completed
+* prior to returning to the caller.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \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&trade; 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_en_capsense_bist_status_t Cy_CapSense_MeasureVdda(
+                uint32_t * ptrValue,
+                cy_stc_capsense_context_t * context)
+{
+    cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+    result = Cy_CapSense_MeasureVdda_V2(ptrValue, context);
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN) */
+
+#endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) */
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+
+/* [] END OF FILE */

+ 124 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest.h

@@ -0,0 +1,124 @@
+/***************************************************************************//**
+* \file cy_capsense_selftest.h
+* \version 3.0
+*
+* \brief
+* This file provides the function prototypes of the BIST module.
+*
+********************************************************************************
+* \copyright
+* Copyright 2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_SELFTEST_H)
+#define CY_CAPSENSE_SELFTEST_H
+
+#include "cy_syslib.h"
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+    #include "cy_capsense_selftest_v2.h"
+#else /* (CY_CAPSENSE_PSOC4_FIFTH_GEN) */
+    #include "cy_capsense_selftest_v3.h"
+#endif
+
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN)
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/*******************************************************************************
+* 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 *//** \{ */
+/******************************************************************************/
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_CheckCRCWidget(
+                    uint32_t widgetId,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN)
+    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);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)
+    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);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorPins(
+                    uint32_t widgetId,
+                    uint32_t sensorId,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN)
+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);
+#endif /* (CY_CAPSENSE_PLATFORM_BLOCK_FOURTH_GEN) */
+
+/** \} */
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+void Cy_CapSense_BistDsInitialize(cy_stc_capsense_context_t * context);
+
+/** \} \endcond */
+
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) */
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2) || defined(CY_IP_M0S8MSCV3)) */
+
+#endif /* CY_CAPSENSE_SELFTEST_H */
+
+
+/* [] END OF FILE */

+ 4523 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest_v2.c

@@ -0,0 +1,4523 @@
+/***************************************************************************//**
+* \file cy_capsense_selftest.c
+* \version 3.0
+*
+* \brief
+* This file provides the source code to the Built-in Self-test (BIST)
+* functions.
+*
+********************************************************************************
+* \copyright
+* Copyright 2019-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include <stddef.h>
+#include <string.h>
+#include "cycfg_capsense_defines.h"
+#include "cy_syslib.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cy_capsense_sensing.h"
+#include "cy_capsense_sensing_v2.h"
+#include "cy_capsense_lib.h"
+#include "cy_capsense_selftest_v2.h"
+#include "cy_gpio.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN)
+
+/*******************************************************************************
+* 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_FOURTH_GEN)
+    #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_FOURTH_GEN)
+    #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 *//** \{ */
+/******************************************************************************/
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+    /* CRC test-related functions */
+    static cy_en_capsense_bist_status_t Cy_CapSense_CheckAllWidgetCRC(
+                cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+    /* 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);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+     (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN))
+    /* 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);
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        static void Cy_CapSense_BistMeasureCapacitanceSensorShieldEnable(
+                        cy_stc_capsense_context_t * context);
+    #endif
+
+    static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensorRun(
+                    cy_stc_capsense_context_t * context);
+#endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+           (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+    static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensorAll(
+                    cy_stc_capsense_context_t * context);
+#endif
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
+    /* 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 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);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)
+    /* 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);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+    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);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+    /* Common functions for all hardware-dependent 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);
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        static void Cy_CapSense_BistSwitchAllShieldPinState(
+                        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);
+    #endif
+
+    static void Cy_CapSense_BistSwitchAllExternalCapPinState(
+                    cy_en_capsense_bist_io_state_t desiredPinState,
+                    const cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+    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);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) || \
+    (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN)  || \
+    (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
+    static uint32_t Cy_CapSense_BistWaitEndOfScan(
+                uint32_t watchdogCycleNum,
+                const cy_stc_capsense_context_t * context);
+#endif
+
+/** \} \endcond */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunSelfTest_V2
+****************************************************************************//**
+*
+* 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_V2()
+* - Cy_CapSense_MeasureVdda()
+*
+* Refer to these functions descriptions for detail information
+* on the corresponding test.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \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_MASK       - Verifies the RAM widget structure CRC
+*                                          for all the widgets.
+* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK  - Checks all the sensors for a short
+*                                          to GND / VDD / other sensors.
+* - CY_CAPSENSE_BIST_SNS_CAP_MASK        - Measures all the sensors capacitance.
+* - CY_CAPSENSE_BIST_SHIELD_CAP_MASK     - Measures the shield capacitance.
+* - CY_CAPSENSE_BIST_EXTERNAL_CAP_MASK   - Measures the capacitance of the
+*                                          available external capacitors.
+* - CY_CAPSENSE_BIST_VDDA_MASK           - Measures the VDDA voltage.
+* - CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK
+*                                        - Executes all available tests.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_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_V2(
+                uint32_t testEnMask,
+                cy_stc_capsense_context_t * context)
+
+{
+    cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)     || \
+        ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)     && \
+        ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)         || \
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN) || \
+        ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)       && \
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))      || \
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)    || \
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN))))
+    cy_en_capsense_bist_status_t bistStatus;
+    #endif
+
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) && \
+       ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN) || \
+       ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+        (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))))
+        uint32_t tmpVal;
+    #endif
+
+    if (0u == (testEnMask & (~CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK)))
+    {
+        if(NULL != context)
+        {
+            if(CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(context))
+            {
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+                    if (0u != (CY_CAPSENSE_BIST_CRC_WDGT_MASK & testEnMask))
+                    {
+                        bistStatus = Cy_CapSense_CheckAllWidgetCRC(context);
+                        if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+                        {
+                            result = CY_CAPSENSE_BIST_FAIL_E;
+                            context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_CRC_WDGT_MASK;
+                        }
+                    }
+                #endif
+
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+                    /* The next group of tests is hardware-dependent, the request is to switch the sense method */
+                    if(CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchSensingMode(CY_CAPSENSE_BIST_GROUP, context))
+                    {
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)
+                            if (0u != (CY_CAPSENSE_BIST_VDDA_MASK  & testEnMask))
+                            {
+                                bistStatus = Cy_CapSense_MeasureVdda_V2(&tmpVal, context);
+                                if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+                                {
+                                    result = CY_CAPSENSE_BIST_FAIL_E;
+                                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_VDDA_MASK;
+                                }
+                            }
+                        #endif
+
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
+                            if (0u != (CY_CAPSENSE_BIST_EXTERNAL_CAP_MASK & testEnMask))
+                            {
+                                bistStatus = Cy_CapSense_BistMeasureCapacitanceCapAll(context);
+                                if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+                                {
+                                    result = CY_CAPSENSE_BIST_FAIL_E;
+                                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_EXTERNAL_CAP_MASK;
+                                }
+                            }
+                        #endif
+
+                        #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+                             (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))
+                            if ((0u != (CY_CAPSENSE_BIST_SHIELD_CAP_MASK & 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 |= CY_CAPSENSE_BIST_SHIELD_CAP_MASK;
+                                }
+                            }
+                        #endif
+
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+                            if (0u != (CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK & testEnMask))
+                            {
+                                bistStatus = Cy_CapSense_SnsShortCheckAllSensors(context);
+                                if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+                                {
+                                    result = CY_CAPSENSE_BIST_FAIL_E;
+                                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK;
+                                }
+                            }
+                        #endif
+
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+                            if (0u != (CY_CAPSENSE_BIST_SNS_CAP_MASK & testEnMask))
+                            {
+                                bistStatus = Cy_CapSense_BistMeasureCapacitanceSensorAll(context);
+                                if (CY_CAPSENSE_BIST_SUCCESS_E != bistStatus)
+                                {
+                                    result = CY_CAPSENSE_BIST_FAIL_E;
+                                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SNS_CAP_MASK;
+                                }
+                            }
+                        #endif
+
+                    }
+                    else
+                    {
+                        result = CY_CAPSENSE_BIST_ERROR_E;
+                    }
+                #endif
+
+                if (CY_CAPSENSE_BIST_FAIL_E != result)
+                {
+                    result = CY_CAPSENSE_BIST_SUCCESS_E;
+                }
+            }
+            else
+            {
+                result = CY_CAPSENSE_BIST_HW_BUSY_E;
+            }
+        }
+    }
+
+    return (result);
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckCRCWidget_V2
+****************************************************************************//**
+*
+* 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_MASK bit is set in the .testResultMask field.
+*
+* The function never clears the CY_CAPSENSE_BIST_CRC_WDGT_MASK bit.
+* If the CY_CAPSENSE_BIST_CRC_WDGT_MASK 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 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.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_en_capsense_bist_status_t Cy_CapSense_CheckCRCWidget_V2(
+                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 (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_MASK))
+                {
+                    context->ptrBistContext->wdgtCrcCalc = crcValue;
+                    context->ptrBistContext->crcWdgtId = (uint8_t)widgetId;
+                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_CRC_WDGT_MASK;
+                }
+                ptrWdCxt->status &= (uint8_t)~CY_CAPSENSE_WD_WORKING_MASK;
+                result = CY_CAPSENSE_BIST_FAIL_E;
+            }
+            else
+            {
+                result = CY_CAPSENSE_BIST_SUCCESS_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&trade; 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_V2(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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_UpdateCrcWidget(
+                uint32_t 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;
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckIntegritySensorBaseline_V2
+****************************************************************************//**
+*
+* 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_MASK bit
+* in the .testResultMask field of the \ref cy_stc_capsense_bist_context_t
+* structure.
+*
+* The test is integrated into the CAPSENSE&trade; Middleware. All CAPSENSE&trade;
+* 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_CAPSENSE_STATUS_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.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_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&trade; 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_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorBaseline_V2(
+                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;
+    uint16_t bslnInv;
+    uint32_t freqChIndex;
+    uint32_t cxtOffset;
+
+    const cy_stc_capsense_sensor_context_t *ptrSnsCxt;
+    cy_stc_capsense_widget_config_t const *ptrWdgtCfg;
+
+    if(NULL != context)
+    {
+        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 baselines for all frequencies */
+            for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; 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 |= CY_CAPSENSE_BIST_BSLN_INTEGRITY_MASK;
+                    result = CY_CAPSENSE_BIST_FAIL_E;
+                    break;
+                }
+
+                ptrSnsCxt += context->ptrCommonConfig->numSns;
+            }
+
+            if (CY_CAPSENSE_BIST_FAIL_E != result)
+            {
+                result = CY_CAPSENSE_BIST_SUCCESS_E;
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckIntegritySensorRawcount_V2
+****************************************************************************//**
+*
+* 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_MASK 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.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_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&trade; 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_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorRawcount_V2(
+                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;
+    const cy_stc_capsense_sensor_context_t *ptrSnsCxt;
+    cy_stc_capsense_widget_config_t const *ptrWdgtCfg;
+
+    if(NULL != context)
+    {
+        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 raw counts for all frequencies */
+            for(freqChIndex = 0u; freqChIndex < CY_CAPSENSE_CONFIGURED_FREQ_NUM; freqChIndex++)
+            {
+                if ((ptrSnsCxt->raw  > rawcountHighLimit) ||
+                    (ptrSnsCxt->raw  < rawcountLowLimit))
+                {
+                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_RAW_INTEGRITY_MASK;
+                    result = CY_CAPSENSE_BIST_FAIL_E;
+                    break;
+                }
+
+                ptrSnsCxt += context->ptrCommonConfig->numSns;
+            }
+
+            if (CY_CAPSENSE_BIST_FAIL_E != result)
+            {
+                result = CY_CAPSENSE_BIST_SUCCESS_E;
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckIntegritySensorPins_V2
+****************************************************************************//**
+*
+* 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&trade; (such as sensors, Tx, Rx,
+*   shield electrodes, and external capacitors)
+* * Other non-CAPSENSE&trade; 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&trade; 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&trade; 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&trade; 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_INTEGRITY_MASK bit is set in the .testResultMask field
+*   of the \ref cy_stc_capsense_bist_context_t structure.
+* * If CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK 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_INTEGRITY_MASK 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_INTEGRITY_MASK mask.
+*
+* To detect an electrical short or fault condition with resistance
+* higher than 1500 ohm, the Cy_CapSense_MeasureCapacitanceSensor() function can
+* be used as the fault condition affects the measured sensor capacitance.
+*
+* This test can be executed only if the CAPSENSE&trade; Middleware is in the IDLE
+* state. This function must not be called while CAPSENSE&trade; Middleware is busy.
+*
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; 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&trade; Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense_<WidgetName>_RX<RXNumber>_ID
+* * CapSense_<WidgetName>_TX<TXNumber>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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&trade; 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_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorPins_V2(
+                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 (context->ptrCommonConfig->numWd > widgetId)
+        {
+            /* Get a total number of the widget elements: for CSX it is numRows + numCols, for CSD it is totalNumSns */
+            if (CY_CAPSENSE_CSX_GROUP == 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(CY_CAPSENSE_BIST_GROUP, context))
+                {
+                    /* Switch the HW resource configuration to the sensor short test */
+                    Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_SHORT_E, context);
+
+                    /* Set all CAPSENSE&trade; pins to strong-high */
+                    Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+
+                    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+                    #endif
+
+                    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&trade; pins to strong-low */
+                    Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+
+                    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+                    #endif
+
+                    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;
+                }
+            }
+        }
+    }
+
+    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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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_<WIDGET_NAME>_SNS<SENSOR_NUMBER>_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_<WIDGET_NAME>_<TX/RX><TX/RX_NUMBER>_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&trade; 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 (CY_CAPSENSE_CSX_GROUP == 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_SnsShortCheckElectrodeV2
+****************************************************************************//**
+*
+* 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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; 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_CAPSENSE_DM_GPIO_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_MASK 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&trade; 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_MASK))
+    {
+        /* Write to the BIST context structure widgetId and sensorId of the first shorted sensor */
+        context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK;
+        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&trade; 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);
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+    #endif
+    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);
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+    #endif
+    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);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceSensor
+****************************************************************************//**
+*
+* Measures the specified CSD sensor / CSX electrode capacitance in femtofarads.
+*
+* 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 or -shorted sensors. For example, the PCB track is
+* broken or shorted to other nodes in the system - in all of these conditions,
+* this function returns changed 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&trade; sensors (electrodes) that are not being
+* measured are set to the GND state for CSD measured electrodes (sensors) and
+* to the HIGH-Z state for CSX measured electrodes (Rx and Tx).
+* Shield electrodes are also configured to the GND state.
+* The inactive state can be changed in run-time by using
+* the Cy_CapSense_SetInactiveElectrodeState() function.
+*
+* 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 mask.
+*
+* This function must not be called while the CSD HW block is busy by another
+* state.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; 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&trade; Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense_<WidgetName>_RX<RXNumber>_ID
+* * CapSense_<WidgetName>_TX<TXNumber>_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&trade; 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_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 ((context->ptrCommonConfig->numWd > widgetId))
+        {
+            /* Get a total number of the widget elements: for CSX, it is numRows + numCols, for CSD, it is totalNumSns */
+            if (CY_CAPSENSE_CSX_GROUP == 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(CY_CAPSENSE_BIST_GROUP, 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 CY_CAPSENSE_CSD_GROUP:
+                            desiredIoState = context->ptrBistContext->intrEltdCapCsdISC;
+                            break;
+                        case CY_CAPSENSE_CSX_GROUP:
+                            desiredIoState = context->ptrBistContext->intrEltdCapCsxISC;
+                            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);
+
+                    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+                    #endif
+
+                    /* 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) */
+                    context->ptrCommonConfig->ptrCsdBase->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;
+                    }
+                    context->ptrCommonConfig->ptrCsdBase->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;
+                }
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) &&\
+     (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN))
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceShield
+****************************************************************************//**
+*
+* Measures shield electrode capacitance in femtofarads.
+*
+* 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 or -short 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 changed capacitance that can be compared
+* against pre-determined capacitance for the shield electrode to
+* detect a fault condition.
+*
+* By default, all CAPSENSE&trade; sensors (electrodes) that are not being
+* measured are set to the GND state.
+* The inactive state can be changed in run-time by using
+* the Cy_CapSense_SetInactiveElectrodeState() function.
+* When the inactive sensor (electrode) connection is set
+* to the CY_CAPSENSE_SNS_CONNECTION_SHIELD state,
+* all the CAPSENSE&trade; electrodes are connected to the shield and
+* the total capacitance are measured.
+*
+* 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 mask.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \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&trade; 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_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((0u != context->ptrCommonConfig->csdShieldNumPin) ||
+           (CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->intrEltdCapShieldISC))
+        {
+            /* Release previously-captured HW resources by the other mode and capture them for BIST */
+            if (CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchSensingMode(CY_CAPSENSE_BIST_GROUP, 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->intrEltdCapShieldISC)
+                {
+                    Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_SENSE_E, context);
+                }
+                else
+                {
+                    Cy_CapSense_BistSwitchAllSnsPinState(context->ptrBistContext->intrEltdCapShieldISC, 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) */
+                context->ptrCommonConfig->ptrCsdBase->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 */
+                context->ptrCommonConfig->ptrCsdBase->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;
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) && (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+/*******************************************************************************
+* 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&trade; 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&trade; 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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; 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&trade; Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense_<WidgetName>_RX<RXNumber>_ID
+* * CapSense_<WidgetName>_TX<TXNumber>_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&trade; 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_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 ((context->ptrCommonConfig->numWd > widgetId))
+        {
+            /* Get a total number of widget elements: for CSX, it is numRows + numCols, for CSD, it is totalNumSns */
+            if (CY_CAPSENSE_CSX_GROUP == 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->intrEltdCapCsxISC;
+            }
+            else
+            {
+                numWdgtElectrodes = context->ptrWdConfig[widgetId].numSns;
+                desiredIoState = context->ptrBistContext->intrEltdCapCsdISC;
+            }
+            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(CY_CAPSENSE_BIST_GROUP, 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);
+                    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+                    #endif
+                    /* 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_FOURTH_GEN)
+                        if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+                        {
+                            temp = CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk;
+                        }
+                    #endif
+                    context->ptrCommonConfig->ptrCsdBase->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) */
+                    context->ptrCommonConfig->ptrCsdBase->SENSE_PERIOD = ((uint32_t)ptrScanConfig->snsClk - 1u);
+                    /* Set Number Of Conversions for the custom scan */
+                    context->ptrCommonConfig->ptrCsdBase->SEQ_NORM_CNT = (uint32_t)ptrScanConfig->convNum;
+                    /* Setup the IDAC code and Gain */
+                    context->ptrCommonConfig->ptrCsdBase->IDACA =
+                            (context->ptrCommonConfig->ptrCsdBase->IDACA & ~CY_CAPSENSE_BIST_IDAC_BITS_TO_WRITE) |
+                            ((context->ptrCommonConfig->idacGainTable[idacIdx].gainReg | idacCode |
+                            CSD_IDACA_LEG1_MODE_Msk | CSD_IDACA_LEG2_MODE_Msk) & CY_CAPSENSE_BIST_IDAC_BITS_TO_WRITE);
+
+                    /* 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 = (context->ptrCommonConfig->ptrCsdBase->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 */
+                    context->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+                    (void)context->ptrCommonConfig->ptrCsdBase->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;
+                }
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+     (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN))
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSensorInit
+****************************************************************************//**
+*
+* 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&trade; 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&trade; MW or calling of the Cy_CapSense_BistDsInitialize()
+* function overwrites the output parameters.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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 (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        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;
+    #endif
+
+    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_FOURTH_GEN)
+        if (CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+        {
+            ptrBistCxt->regSwRefgenSel = CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRP_MSK;
+        }
+    #endif
+
+    #if (CY_CAPSENSE_PSOC4_FOURTH_GEN)
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+            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:
+                    /* No action on other connection types */
+                    break;
+            }
+
+            #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+                (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN))
+                switch (context->ptrInternalContext->csdCshConnection)
+                {
+                    case (uint8_t)CY_CAPSENSE_CMODPAD_E:
+                        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:
+                        /* No action on other connection types */
+                        break;
+                }
+            #endif
+        #else
+            ptrBistCxt->regSwDsiSel = CY_CAPSENSE_CSD_SW_DSI_SEL_CMOD_MSK |
+                    CY_CAPSENSE_CSD_SW_DSI_SEL_CSH_TANK_MSK;
+        #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+    #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_FOURTH_GEN)
+        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 (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN)
+            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;
+        #endif
+    #endif
+
+    /* High-Speed Comparator initialization */
+    ptrBistCxt->regHscmpScan = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
+    ptrBistCxt->regHscmpScanShield = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        ptrBistCxt->regHscmpScan = 0u;
+        ptrBistCxt->regHscmpScanShield = 0u;
+    #endif
+
+    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 == CY_CAPSENSE_CSD_SHIELD_EN)
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN)
+            switch (context->ptrInternalContext->csdCshConnection)
+            {
+                case (uint8_t)CY_CAPSENSE_CMODPAD_E:
+                    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;
+        #endif
+    #endif
+
+    /* Pre-calculate config with a shield */
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        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;
+    #endif
+
+    /* Switch AMUXBUF selection */
+    ptrBistCxt->regSwAmuxbufSel = 0u;
+    ptrBistCxt->regSwAmuxbufSelShield = 0u;
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        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;
+        }
+    #endif
+
+    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&trade; 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 == CY_CAPSENSE_CSD_EN)
+        Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCmod,
+                (uint32_t)context->ptrCommonConfig->pinCmod, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+        ptrCsdHwBase->SW_CMP_P_SEL = context->ptrInternalContext->csdRegSwCmpPSel;
+
+        #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+             (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN))
+            Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh,
+                    CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXB);
+        #endif
+    #else /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+        Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA,
+                (uint32_t)context->ptrCommonConfig->pinCintA, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+        Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB,
+                (uint32_t)context->ptrCommonConfig->pinCintB, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+        ptrCsdHwBase->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;
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+    ptrCsdHwBase->CONFIG = context->ptrBistContext->regConfig;
+    ptrCsdHwBase->REFGEN =
+            CSD_REFGEN_REFGEN_EN_Msk |
+            CSD_REFGEN_RES_EN_Msk    |
+            ((uint32_t)context->ptrBistContext->eltdCapVrefGain << CSD_REFGEN_GAIN_Pos);
+    #if (CY_CAPSENSE_PSOC4_FOURTH_GEN)
+        if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+        {
+            ptrCsdHwBase->REFGEN = CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk;
+        }
+    #endif
+    ptrCsdHwBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK;
+    ptrCsdHwBase->AMBUF = context->ptrBistContext->regAmbuf;
+    ptrCsdHwBase->ADC_CTL = 0u;
+    ptrCsdHwBase->SEQ_TIME = 0u;
+    ptrCsdHwBase->IDACA = 0u;
+    ptrCsdHwBase->IDACB = 0u;
+    ptrCsdHwBase->SENSE_DUTY = CY_CAPSENSE_CSD_SENSE_DUTY_CFG;
+    ptrCsdHwBase->INTR_SET = 0u;
+    ptrCsdHwBase->SEQ_INIT_CNT = (uint32_t)context->ptrBistContext->fineInitTime;
+    ptrCsdHwBase->SW_REFGEN_SEL = context->ptrBistContext->regSwRefgenSel;
+    ptrCsdHwBase->SW_HS_N_SEL = CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_CLOSE;
+    ptrCsdHwBase->SW_CMP_N_SEL = CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE;
+    ptrCsdHwBase->SW_HS_P_SEL = 0u;
+    ptrCsdHwBase->SW_AMUXBUF_SEL = context->ptrBistContext->regSwAmuxbufSel;
+    ptrCsdHwBase->SW_BYP_SEL = context->ptrBistContext->regSwBypSel;
+    #if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
+        ptrCsdHwBase->IO_SEL = context->ptrBistContext->regIoSel;
+    #endif
+    ptrCsdHwBase->SW_DSI_SEL = context->ptrBistContext->regSwDsiSel;
+}
+#endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+           (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN)
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+/*******************************************************************************
+* 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&trade; 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&trade; 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 == CY_CAPSENSE_CSD_EN)
+        Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCmod,
+                (uint32_t)context->ptrCommonConfig->pinCmod, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+        ptrCsdHwBase->SW_CMP_P_SEL = context->ptrInternalContext->csdRegSwCmpPSel;
+
+        #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+             (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN))
+            Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh,
+                    CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXB);
+        #endif
+    #else /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+        Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA,
+                (uint32_t)context->ptrCommonConfig->pinCintA, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+        Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB,
+                (uint32_t)context->ptrCommonConfig->pinCintB, CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+        ptrCsdHwBase->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;
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+    ptrCsdHwBase->CONFIG = context->ptrBistContext->regConfigShield;
+    ptrCsdHwBase->REFGEN =
+            CSD_REFGEN_REFGEN_EN_Msk |
+            CSD_REFGEN_RES_EN_Msk    |
+            ((uint32_t)context->ptrBistContext->eltdCapVrefGain << CSD_REFGEN_GAIN_Pos);
+    #if (CY_CAPSENSE_PSOC4_FOURTH_GEN)
+        if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+        {
+            ptrCsdHwBase->REFGEN = CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk;
+        }
+    #endif
+    ptrCsdHwBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK;
+    ptrCsdHwBase->AMBUF = context->ptrBistContext->regAmbufShield;
+    ptrCsdHwBase->ADC_CTL = 0u;
+    ptrCsdHwBase->SEQ_TIME = 0u;
+    ptrCsdHwBase->IDACA = 0u;
+    ptrCsdHwBase->IDACB = 0u;
+    ptrCsdHwBase->SENSE_DUTY = CY_CAPSENSE_CSD_SENSE_DUTY_CFG;
+    ptrCsdHwBase->INTR_SET = 0u;
+    ptrCsdHwBase->SEQ_INIT_CNT = (uint32_t)context->ptrBistContext->fineInitTime;
+    ptrCsdHwBase->SW_REFGEN_SEL = context->ptrBistContext->regSwRefgenSel;
+    ptrCsdHwBase->SW_HS_N_SEL = CY_CAPSENSE_CSD_SW_HS_N_SEL_SW_HCRH_STATIC_CLOSE;
+    ptrCsdHwBase->SW_CMP_N_SEL = CY_CAPSENSE_CSD_SW_CMP_N_SEL_SW_SCRH_STATIC_CLOSE;
+    ptrCsdHwBase->SW_HS_P_SEL = context->ptrBistContext->regSwHsPSelScanShield;
+    ptrCsdHwBase->SW_AMUXBUF_SEL = context->ptrBistContext->regSwAmuxbufSelShield;
+    ptrCsdHwBase->SW_BYP_SEL = context->ptrBistContext->regSwBypSelShield;
+    #if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
+        ptrCsdHwBase->IO_SEL = context->ptrBistContext->regIoSelShield;
+    #endif
+    ptrCsdHwBase->SW_DSI_SEL = context->ptrBistContext->regSwDsiSel;
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) */
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) */
+
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+     (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN))
+/*******************************************************************************
+* 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&trade; 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];
+        context->ptrCommonConfig->ptrCsdBase->IDACA =
+                (context->ptrCommonConfig->ptrCsdBase->IDACA & ~CY_CAPSENSE_BIST_IDAC_BITS_TO_WRITE) |
+                ((context->ptrCommonConfig->idacGainTable[idacIdx].gainReg | idacCode |
+                CSD_IDACA_LEG1_MODE_Msk | CSD_IDACA_LEG2_MODE_Msk) & CY_CAPSENSE_BIST_IDAC_BITS_TO_WRITE);
+
+        /* 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 = context->ptrCommonConfig->ptrCsdBase->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 */
+    context->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)context->ptrCommonConfig->ptrCsdBase->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&trade; 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_SUCCESS_E;
+    CSD_Type * ptrCsdHwBase = context->ptrCommonConfig->ptrCsdBase;
+    uint32_t watchdogSize;
+    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;
+
+    watchdogSize = Cy_CapSense_WatchdogCyclesNum(initWatchdogTimeUs,
+            context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA,
+            intrInitLoopDuration);
+
+    Cy_CapSense_DischargeExtCapacitors(context);
+
+    /* External capacitor pre-charging */
+    ptrCsdHwBase->CSDCMP = 0u;
+    ptrCsdHwBase->HSCMP = CY_CAPSENSE_CSD_HSCMP_HSCMP_EN_MSK;
+    ptrCsdHwBase->SW_RES = context->ptrBistContext->regSwResInit;
+    ptrCsdHwBase->SW_FW_MOD_SEL = 0u;
+    ptrCsdHwBase->SW_FW_TANK_SEL = 0u;
+
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN))
+        /* Clear previous interrupts */
+        ptrCsdHwBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+        (void)ptrCsdHwBase->INTR;
+
+        ptrCsdHwBase->SW_HS_P_SEL = context->ptrBistContext->regSwHsPSelCtankInit;
+        ptrCsdHwBase->SW_SHIELD_SEL = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_HSCMP;
+
+        /* Start SEQUENCER for coarse initialization for Ctank */
+        ptrCsdHwBase->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;
+    #endif
+
+    /* Init Watchdog Counter to prevent a hang */
+    watchdogCounter = Cy_CapSense_WaitForSeqIdle(watchdogSize, context);
+    if (0u == watchdogCounter)
+    {
+        /* Set the sequencer to the idle state if the coarse initialization fails */
+        ptrCsdHwBase->SEQ_START = CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK;
+        result = CY_CAPSENSE_BIST_TIMEOUT_E;
+    }
+
+    if (CY_CAPSENSE_BIST_SUCCESS_E == result)
+    {
+        /* Clear previous interrupts */
+        context->ptrCommonConfig->ptrCsdBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+        (void)ptrCsdHwBase->INTR;
+
+        ptrCsdHwBase->SW_HS_P_SEL = context->ptrBistContext->regSwHsPSelCmodInit;
+        ptrCsdHwBase->SW_SHIELD_SEL = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCAV_HSCMP;
+
+        /* Start SEQUENCER for coarse initialization for Cmod */
+        ptrCsdHwBase->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 */
+        watchdogCounter = Cy_CapSense_WaitForSeqIdle(watchdogSize, context);
+
+        if (0u == watchdogCounter)
+        {
+            /* Set the sequencer to the idle state if the coarse initialization fails */
+            ptrCsdHwBase->SEQ_START = CY_CAPSENSE_CSD_SEQ_START_ABORT_MSK;
+            result = CY_CAPSENSE_BIST_TIMEOUT_E;
+        }
+    }
+
+    /* Scanning */
+    if (CY_CAPSENSE_BIST_SUCCESS_E == result)
+    {
+        /* Clear previous interrupts */
+        ptrCsdHwBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+        (void)ptrCsdHwBase->INTR;
+
+        ptrCsdHwBase->CSDCMP = CY_CAPSENSE_CSD_CSDCMP_CSDCMP_EN_MSK;
+        ptrCsdHwBase->SW_RES = context->ptrBistContext->regSwResScan;
+
+        if (CY_CAPSENSE_BIST_HW_ELTD_CAP_SH_E != context->ptrBistContext->hwConfig)
+        {
+            ptrCsdHwBase->SW_HS_P_SEL = context->ptrBistContext->regSwHsPSelScan;
+            ptrCsdHwBase->HSCMP = context->ptrBistContext->regHscmpScan;
+            ptrCsdHwBase->SW_SHIELD_SEL = context->ptrBistContext->regSwShieldSelScan;
+        }
+        else
+        {
+            ptrCsdHwBase->SW_HS_P_SEL = context->ptrBistContext->regSwHsPSelScanShield;
+            ptrCsdHwBase->HSCMP = context->ptrBistContext->regHscmpScanShield;
+            ptrCsdHwBase->SW_SHIELD_SEL = context->ptrBistContext->regSwShieldSelScanShield;
+        }
+
+        ptrCsdHwBase->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;
+        result = CY_CAPSENSE_BIST_HW_BUSY_E;
+    }
+
+    return (result);
+}
+#endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+           (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+/*******************************************************************************
+* 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&trade; 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 (CY_CAPSENSE_CSX_GROUP == 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);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceCap_V2
+****************************************************************************//**
+*
+* Measures the capacitance in picofarads of the specified CAPSENSE&trade; 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&trade; 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_INTEGRITY_MASK 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&trade; Middleware is in the IDLE
+* state. This function must not be called while the CAPSENSE&trade; Middleware is busy.
+* The function is blocking, i.e. waits for the measurement to be completed
+* prior to returning to the caller.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \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&trade; 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_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceCap_V2(
+                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_SUCCESS_E != Cy_CapSense_SwitchSensingMode(CY_CAPSENSE_BIST_GROUP, 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;
+            #if((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+                (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN))
+            case CY_CAPSENSE_BIST_CSH_ID_E:
+                ptrCapPort = context->ptrCommonConfig->portCsh;
+                capacitorPin = (uint32_t)context->ptrCommonConfig->pinCsh;
+                ptrResult = &context->ptrBistContext->cShieldCap;
+                break;
+            #endif
+            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;
+        context->ptrCommonConfig->ptrCsdBase->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_CAPSENSE_DM_GPIO_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&trade; 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&trade; MW or calling of the Cy_CapSense_BistDsInitialize()
+* function overwrites the output parameters.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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&trade; 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 */
+    ptrCsdHwBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK;
+    (void)ptrCsdHwBase->INTR_MASK;
+    /* Clear all pending interrupt requests */
+    ptrCsdHwBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)ptrCsdHwBase->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);
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+    #endif
+    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 */
+    ptrCsdHwBase->CONFIG = CY_CAPSENSE_BIST_CAP_CONFIG_DEFAULT;
+    ptrCsdHwBase->SW_REFGEN_SEL = CY_CAPSENSE_BIST_CAP_SW_REFGEN_SEL_SRSS_DEFAULT;
+    #if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
+        if (CY_CAPSENSE_IREF_PASS == context->ptrCommonConfig->ssIrefSource)
+        {
+            ptrCsdHwBase->CONFIG = CY_CAPSENSE_BIST_CAP_CONFIG_IREF_DEFAULT;
+        }
+        if (CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+        {
+            ptrCsdHwBase->SW_REFGEN_SEL = CY_CAPSENSE_BIST_CAP_SW_REFGEN_SEL_PASS_DEFAULT;
+        }
+        ptrCsdHwBase->IO_SEL = CY_CAPSENSE_BIST_CAP_IO_SEL_DEFAULT;
+    #endif
+    ptrCsdHwBase->REFGEN = CY_CAPSENSE_BIST_CAP_REFGEN_DEFAULT |
+                          ((uint32_t)context->ptrBistContext->extCapVrefGain << CSD_REFGEN_GAIN_Pos);
+    #if (CY_CAPSENSE_PSOC4_FOURTH_GEN)
+        if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+        {
+            ptrCsdHwBase->REFGEN = CY_CAPSENSE_BIST_CAP_REFGEN_LOW_VOLTAGE_DEFAULT;
+        }
+    #endif
+    ptrCsdHwBase->CSDCMP = CY_CAPSENSE_BIST_CAP_CSDCMP_DEFAULT;
+    ptrCsdHwBase->SENSE_DUTY = CY_CAPSENSE_BIST_CAP_SENSE_DUTY_DEFAULT;
+    ptrCsdHwBase->SENSE_PERIOD = (uint32_t)context->ptrBistContext->extCapSnsClk - 1u;
+    ptrCsdHwBase->SEQ_NORM_CNT = 1u;
+    ptrCsdHwBase->SEQ_TIME = 0uL;
+    ptrCsdHwBase->SEQ_INIT_CNT = 0uL;
+    ptrCsdHwBase->ADC_CTL = 0uL;
+    ptrCsdHwBase->IDACA = 0u;
+    ptrCsdHwBase->IDACB = 0u;
+    ptrCsdHwBase->INTR_SET = 0uL;
+    ptrCsdHwBase->HSCMP = 0uL;
+    ptrCsdHwBase->AMBUF = 0uL;
+    ptrCsdHwBase->SW_RES = 0uL;
+    ptrCsdHwBase->SW_HS_P_SEL = 0uL;
+    ptrCsdHwBase->SW_HS_N_SEL = 0uL;
+    ptrCsdHwBase->SW_SHIELD_SEL = 0u;
+    ptrCsdHwBase->SW_AMUXBUF_SEL = 0uL;
+    ptrCsdHwBase->SW_FW_MOD_SEL = 0uL;
+    ptrCsdHwBase->SW_FW_TANK_SEL = 0uL;
+    ptrCsdHwBase->SW_DSI_SEL = 0uL;
+    ptrCsdHwBase->SW_BYP_SEL = CY_CAPSENSE_BIST_CAP_SW_BYP_SEL_DEFAULT;
+    ptrCsdHwBase->SW_CMP_N_SEL = CY_CAPSENSE_BIST_CAP_SW_CMP_N_SEL_DEFAULT;
+    ptrCsdHwBase->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&trade; 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 */
+    ptrCsdHwBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)ptrCsdHwBase->INTR;
+
+    /* Start SEQUENCER for fine initialization and then for conversion */
+    ptrCsdHwBase->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 = ptrCsdHwBase->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&trade; 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.
+*
+*******************************************************************************/
+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 == CY_CAPSENSE_CSD_EN)
+        tempStatus = Cy_CapSense_MeasureCapacitanceCap_V2(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 == CY_CAPSENSE_CSD_SHIELD_EN) && \
+             (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN))
+            tempStatus = Cy_CapSense_MeasureCapacitanceCap_V2(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;
+            }
+        #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+                   (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_CAP_EN)) */
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+        tempStatus = Cy_CapSense_MeasureCapacitanceCap_V2(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_V2(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;
+        }
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+
+    return (bistStatus);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureVdda_V2
+****************************************************************************//**
+*
+* 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 various cases, for example to monitor
+* the battery voltage.
+*
+* A measurement can be done only if the CAPSENSE&trade; middleware is in the IDLE
+* state. This function must not be called while the CAPSENSE&trade; middleware is busy.
+* The function is blocking, i.e. waits for the conversion to be completed
+* prior to returning to the caller.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \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&trade; 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_en_capsense_bist_status_t Cy_CapSense_MeasureVdda_V2(
+                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)
+    {
+        csStatus = Cy_CapSense_SwitchSensingMode(CY_CAPSENSE_BIST_GROUP, 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;
+        }
+    }
+
+    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&trade; 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&trade; MW or calling of the Cy_CapSense_BistDsInitialize()
+* function overwrites the output parameters.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_FOURTH_GEN)
+        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&trade; 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 */
+    ptrCsdHwBase->INTR_MASK = CY_CAPSENSE_CSD_INTR_MASK_CLEAR_MSK;
+    (void)ptrCsdHwBase->INTR_MASK;
+    /* Clear all pending interrupt requests */
+    ptrCsdHwBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)ptrCsdHwBase->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);
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+    #endif
+    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 */
+    ptrCsdHwBase->CONFIG = CY_CAPSENSE_BIST_VDDA_CONFIG_DEFAULT;
+    ptrCsdHwBase->SW_REFGEN_SEL = CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGR_MSK;
+    #if (CY_CAPSENSE_PSOC6_FOURTH_GEN)
+        if (CY_CAPSENSE_IREF_PASS == context->ptrCommonConfig->ssIrefSource)
+        {
+            ptrCsdHwBase->CONFIG = CY_CAPSENSE_BIST_VDDA_CONFIG_DEFAULT |
+                                   CY_CAPSENSE_CSD_CONFIG_IREF_SEL_MSK;
+        }
+        if (CY_CAPSENSE_VREF_PASS == context->ptrCommonConfig->ssVrefSource)
+        {
+            ptrCsdHwBase->SW_REFGEN_SEL = CY_CAPSENSE_CSD_SW_REFGEN_SEL_SW_SGRP_MSK;
+        }
+        ptrCsdHwBase->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_FOURTH_GEN)
+        if (CY_CAPSENSE_LOW_VOLTAGE_LIMIT > context->ptrCommonConfig->vdda)
+        {
+            temp = CSD_REFGEN_REFGEN_EN_Msk | CSD_REFGEN_BYPASS_Msk;
+        }
+    #endif
+
+    ptrCsdHwBase->HSCMP = CY_CAPSENSE_BIST_VDDA_HSCMP_DEFAULT;
+    ptrCsdHwBase->AMBUF = CY_CAPSENSE_BIST_VDDA_AMBUF_DEFAULT;
+    ptrCsdHwBase->REFGEN = temp;
+    ptrCsdHwBase->SENSE_PERIOD = (uint32_t)CY_CAPSENSE_BIST_VDDA_SENSE_PERIOD_DEFAULT - 1u;
+    ptrCsdHwBase->CSDCMP = CY_CAPSENSE_BIST_VDDA_CSDCMP_DEFAULT;
+    ptrCsdHwBase->IDACA = CY_CAPSENSE_BIST_VDDA_IDACA_DEFAULT;
+    ptrCsdHwBase->IDACB = (uint32_t)CY_CAPSENSE_BIST_VDDA_IDACB_DEFAULT |
+                          context->ptrBistContext->vddaIdacDefault;
+    ptrCsdHwBase->SEQ_TIME = (uint32_t)context->ptrBistContext->vddaAzCycles - 1u;
+    ptrCsdHwBase->ADC_CTL = (uint32_t)context->ptrBistContext->vddaAcqCycles - 1u;
+    ptrCsdHwBase->SENSE_DUTY = CY_CAPSENSE_BIST_VDDA_SENSE_DUTY_DEFAULT;
+    ptrCsdHwBase->SEQ_INIT_CNT = CY_CAPSENSE_BIST_VDDA_SEQ_INIT_CNT_DEFAULT;
+    ptrCsdHwBase->SEQ_NORM_CNT = CY_CAPSENSE_BIST_VDDA_SEQ_NORM_CNT_DEFAULT;
+    ptrCsdHwBase->SW_RES = CY_CAPSENSE_BIST_VDDA_SW_RES_DEFAULT;
+    ptrCsdHwBase->SW_HS_P_SEL = CY_CAPSENSE_BIST_VDDA_SW_HS_P_SEL_DEFAULT;
+    ptrCsdHwBase->SW_HS_N_SEL = CY_CAPSENSE_BIST_VDDA_SW_HS_N_SEL_DEFAULT;
+    ptrCsdHwBase->SW_SHIELD_SEL = CY_CAPSENSE_BIST_VDDA_SW_SHIELD_SEL_DEFAULT;
+    ptrCsdHwBase->SW_AMUXBUF_SEL = CY_CAPSENSE_BIST_VDDA_SW_AMUXBUF_SEL_DEFAULT;
+    ptrCsdHwBase->SW_BYP_SEL = CY_CAPSENSE_BIST_VDDA_SW_BYP_SEL_DEFAULT;
+    ptrCsdHwBase->SW_CMP_P_SEL = CY_CAPSENSE_BIST_VDDA_SW_CMP_P_SEL_DEFAULT;
+    ptrCsdHwBase->SW_CMP_N_SEL = CY_CAPSENSE_BIST_VDDA_SW_CMP_N_SEL_DEFAULT;
+    ptrCsdHwBase->SW_FW_MOD_SEL = CY_CAPSENSE_BIST_VDDA_SW_FW_MOD_SEL_DEFAULT;
+    ptrCsdHwBase->SW_FW_TANK_SEL = CY_CAPSENSE_BIST_VDDA_SW_FW_TANK_SEL_DEFAULT;
+    ptrCsdHwBase->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&trade; 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
+     */
+    ptrCsdHwBase->ADC_CTL = (ptrCsdHwBase->ADC_CTL & ~CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK) |
+            ((uint32_t)CY_CAPSENSE_BIST_VDDA_MEASMODE_VREF & CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK);
+    ptrCsdHwBase->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));
+    ptrCsdHwBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+    (void)ptrCsdHwBase->INTR;
+    tVssa2Vref = ptrCsdHwBase->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)
+    {
+        ptrCsdHwBase->ADC_CTL = (ptrCsdHwBase->ADC_CTL & ~CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK) |
+                ((uint32_t)CY_CAPSENSE_BIST_VDDA_MEASMODE_VREFBY2 & CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK);
+        ptrCsdHwBase->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));
+        ptrCsdHwBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+        (void)ptrCsdHwBase->INTR;
+        tRecover = ptrCsdHwBase->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 */
+        ptrCsdHwBase->SW_SHIELD_SEL = CY_CAPSENSE_CSD_SW_SHIELD_SEL_SW_HCBV_STATIC_CLOSE;
+        ptrCsdHwBase->ADC_CTL = (ptrCsdHwBase->ADC_CTL & ~CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK) |
+                ((uint32_t)CY_CAPSENSE_BIST_VDDA_MEASMODE_VIN & CY_CAPSENSE_CSD_ADC_CTL_ADC_MODE_MSK);
+        ptrCsdHwBase->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));
+        ptrCsdHwBase->INTR = CY_CAPSENSE_CSD_INTR_ALL_MSK;
+        (void)ptrCsdHwBase->INTR;
+        tVdda2Vref = ptrCsdHwBase->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);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN) */
+
+
+/*******************************************************************************
+* 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&trade; 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;
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDisableMode
+****************************************************************************//**
+*
+* This internal function releases HW resources and pins captured by BIST
+* to be used by other CAPSENSE&trade; 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&trade; 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);
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_UNDEFINED_E, context);
+    #endif
+    Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDsInitialize_V2
+****************************************************************************//**
+*
+* 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&trade; 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistDsInitialize_V2(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++)
+    {
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+            Cy_CapSense_UpdateCrcWidget(wdIndex, context);
+        #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+        context->ptrWdContext[wdIndex].status |= (uint8_t)CY_CAPSENSE_WD_WORKING_MASK;
+    }
+
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN))
+        Cy_CapSense_BistMeasureCapacitanceSensorInit(context);
+    #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+               (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)) */
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
+        Cy_CapSense_BistMeasureCapacitanceCapInit(context);
+    #endif
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)
+        Cy_CapSense_BistMeasureVddaInit(context);
+    #endif
+
+    context->ptrBistContext->hwConfig = CY_CAPSENSE_BIST_HW_UNDEFINED_E;
+    context->ptrBistContext->currentISC = CY_CAPSENSE_BIST_IO_UNDEFINED_E;
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+/*******************************************************************************
+* 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&trade; 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;
+            }
+
+            #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+                 (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN))
+                case CY_CAPSENSE_BIST_HW_ELTD_CAP_E:
+                {
+                    Cy_CapSense_BistMeasureCapacitanceSensorEnable(context);
+                    break;
+                }
+
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                    case CY_CAPSENSE_BIST_HW_ELTD_CAP_SH_E:
+                    {
+                        Cy_CapSense_BistMeasureCapacitanceSensorShieldEnable(context);
+                        break;
+                    }
+                #endif
+            #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN) ||\
+                 (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)) */
+
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
+                case CY_CAPSENSE_BIST_HW_EXTERNAL_CAP_E:
+                {
+                    Cy_CapSense_BistMeasureCapacitanceCapEnable(context);
+                    break;
+                }
+            #endif
+
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)
+                case CY_CAPSENSE_BIST_HW_VDDA_E:
+                {
+                    Cy_CapSense_BistMeasureVddaEnable(context);
+                    break;
+                }
+            #endif
+
+            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&trade; 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_CAPSENSE_DM_GPIO_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_CAPSENSE_DM_GPIO_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_DM_SHIELD;
+            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_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+            desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+            desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2VDD;
+        }
+        else
+        {
+            /* Do nothing */
+        }
+        /* Set all sensor electrodes to the desired state.*/
+        Cy_CapSense_SetIOsInDesiredState(desiredDriveMode, desiredPinOutput, desiredHsiom, context);
+        context->ptrBistContext->currentISC = desiredPinState;
+    }
+}
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+/*******************************************************************************
+* 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&trade; 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_CAPSENSE_DM_GPIO_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)
+    {
+        /* Change Drive mode and HSIOM depending on the current inactive sensor connection */
+        if (CY_CAPSENSE_BIST_IO_STRONG_E == desiredPinState)
+        {
+            desiredDriveMode = CY_CAPSENSE_DM_GPIO_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_DM_SHIELD;
+            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_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+            desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+            desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2VDD;
+        }
+        else
+        {
+            /* Do nothing */
+        }
+        /* Set all CAPSENSE&trade; pins to the desired state */
+        Cy_CapSense_SetShieldPinState(desiredDriveMode, desiredPinOutput, desiredHsiom, context);
+    }
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) */
+
+
+/*******************************************************************************
+* 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&trade; 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 == CY_CAPSENSE_CSD_EN)
+        Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCmod, (uint32_t)context->ptrCommonConfig->pinCmod, CY_CAPSENSE_DM_GPIO_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 == CY_CAPSENSE_CSD_SHIELD_CAP_EN)
+            Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCsh, (uint32_t)context->ptrCommonConfig->pinCsh, CY_CAPSENSE_DM_GPIO_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);
+            }
+        #endif
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+    /* If CSX is enabled, set the CintA and CintB pins to the desired state */
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN)
+        Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintA, (uint32_t)context->ptrCommonConfig->pinCintA, CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF, CY_CAPSENSE_HSIOM_SEL_GPIO);
+        Cy_CapSense_SsConfigPinRegisters(context->ptrCommonConfig->portCintB, (uint32_t)context->ptrCommonConfig->pinCintB, CY_CAPSENSE_DM_GPIO_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);
+        }
+    #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSX_EN) */
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+/*******************************************************************************
+* 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&trade; 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++;
+    }
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+/*******************************************************************************
+* 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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; Configuration header file (cycfg_capsense.h)
+* defined as CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_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&trade; Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense_<WidgetName>_RX<RXNumber>_ID
+* * CapSense_<WidgetName>_TX<TXNumber>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; Configuration header file (cycfg_capsense.h)
+* defined as CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_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&trade; Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense_<WidgetName>_RX<RXNumber>_ID
+* * CapSense_<WidgetName>_TX<TXNumber>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+            hsiomTmp = CY_CAPSENSE_HSIOM_SEL_GPIO;
+            break;
+        case CY_CAPSENSE_BIST_IO_SHIELD_E:
+            driveModeTmp = CY_CAPSENSE_DM_SHIELD;
+            hsiomTmp = CY_CAPSENSE_HSIOM_SEL_AMUXB;
+            break;
+        default:
+            driveModeTmp = CY_CAPSENSE_DM_GPIO_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++;
+    }
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) || \
+    (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN)  || \
+    (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
+/*******************************************************************************
+* 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&trade; 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 (((context->ptrCommonConfig->ptrCsdBase->INTR &
+             CY_CAPSENSE_CSD_INTR_SAMPLE_MSK) == 0u) && (0u != watchdogCounter))
+    {
+        watchdogCounter--;
+    }
+
+    return (watchdogCounter);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) || \
+          (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN)  || \
+          (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN) */
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) */
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2)) */
+
+
+/* [] END OF FILE */

+ 179 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest_v2.h

@@ -0,0 +1,179 @@
+/***************************************************************************//**
+* \file cy_capsense_selftest.h
+* \version 3.0
+*
+* \brief
+* This file provides the function prototypes of the BIST module.
+*
+********************************************************************************
+* \copyright
+* Copyright 2019-2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_SELFTEST_V2_H)
+#define CY_CAPSENSE_SELFTEST_V2_H
+
+#include "cy_syslib.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+#include "cycfg_capsense_defines.h"
+
+#if (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN)
+
+#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)
+
+
+/*******************************************************************************
+* CAPSENSE&trade; 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_low_level *//** \{ */
+/******************************************************************************/
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSensor(
+                    uint32_t widgetId,
+                    uint32_t sensorId,
+                    uint32_t * ptrValue,
+                    cy_stc_capsense_context_t * context);
+#endif
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) &&\
+     (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))
+    cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceShield(
+                    uint32_t * ptrValue,
+                    cy_stc_capsense_context_t * context);
+#endif
+
+/** \} */
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+cy_en_capsense_bist_status_t Cy_CapSense_RunSelfTest_V2(
+                uint32_t testEnMask,
+                cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+cy_en_capsense_bist_status_t Cy_CapSense_CheckCRCWidget_V2(
+                uint32_t widgetId,
+                cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorRawcount_V2(
+                    uint32_t widgetId,
+                    uint32_t sensorId,
+                    uint16_t rawcountHighLimit,
+                    uint16_t rawcountLowLimit,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorBaseline_V2(
+                    uint32_t widgetId,
+                    uint32_t sensorId,
+                    uint16_t baselineHighLimit,
+                    uint16_t baselineLowLimit,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorPins_V2(
+                    uint32_t widgetId,
+                    uint32_t sensorId,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceCap_V2(
+                cy_en_capsense_bist_external_cap_id_t integrationCapId,
+                uint32_t * ptrValue,
+                uint32_t maxCapacitance,
+                cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_EXTERNAL_CAP_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_MeasureVdda_V2(
+                uint32_t * ptrValue,
+                cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_VDDA_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+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);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+void Cy_CapSense_BistInitialize(
+                cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+    void Cy_CapSense_BistDisableMode(
+                    cy_stc_capsense_context_t * context);
+#endif
+
+void Cy_CapSense_BistDsInitialize_V2(
+                cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+    void Cy_CapSense_UpdateCrcWidget(
+                    uint32_t widgetId,
+                    cy_stc_capsense_context_t * context);
+#endif
+
+
+/** \} \endcond */
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) */
+
+#endif /* (defined(CY_IP_MXCSDV2) || defined(CY_IP_M0S8CSDV2)) */
+
+#endif /* CY_CAPSENSE_SELFTEST_V2_H */
+
+
+/* [] END OF FILE */

+ 4007 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest_v3.c

@@ -0,0 +1,4007 @@
+/***************************************************************************//**
+* \file cy_capsense_selftest.c
+* \version 3.0
+*
+* \brief
+* This file provides the source code to the Built-in Self-test (BIST)
+* functions.
+*
+********************************************************************************
+* \copyright
+* Copyright 2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#include <stddef.h>
+#include <string.h>
+#include "cy_syslib.h"
+#include "cy_sysclk.h"
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_sensing.h"
+#include "cy_capsense_sensing_v3.h"
+#include "cy_capsense_generator_v3.h"
+#include "cy_capsense_selftest_v3.h"
+#include "cy_gpio.h"
+
+
+#if (CY_CAPSENSE_PLATFORM_BLOCK_FIFTH_GEN)
+    #include "cy_msc.h"
+#endif
+
+#if (defined(CY_IP_M0S8MSCV3))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN)
+
+/*******************************************************************************
+* 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)
+/* Electrode capacitance measurement macros for BIST */
+#define CY_CAPSENSE_BIST_CAP_SLOT_SCAN                          (0u)
+#define CY_CAPSENSE_BIST_CAP_ELTD_SCAN                          (1u)
+#define CY_CAPSENSE_BIST_CAP_SHIELD_SCAN                        (2u)
+/** The number of BIST sense mode configurations for capacitance measurements (CSD + CSX) */
+#define CY_CAPSENSE_BIST_SENSE_MODE_CONFIG_NUMBER               (2u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_MODCLK_DIV_DEFAULT            (1u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_MAX_MODCLK                    (48000000u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_SNSCLK_DIV_DEFAULT            (256u)
+#define CY_CAPSENSE_BIST_SHIELD_CAP_SNSCLK_DIV_DEFAULT          (1024u)
+#define CY_CAPSENSE_BIST_SNS_CLK_MIN_DIVIDER                    (4u)
+#define CY_CAPSENSE_BIST_SNS_CLK_MAX_DIVIDER                    (4096u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_SUBCONV_NUM_DEFAULT           (100u)
+#define CY_CAPSENSE_BIST_SHIELD_CAP_REF_CDAC_DEFAULT            (200u)
+#define CY_CAPSENSE_BIST_ELTD_CAP_REF_CDAC_DEFAULT              (100u)
+#define CY_CAPSENSE_BIST_MUTUAL_CAP_REF_CDAC_DEFAULT            (50u)
+#define CY_CAPSENSE_BIST_WATCHDOG_MARGIN_COEFF                  (3u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_WDT_CYCLES_PER_LOOP           (5u)
+#define CY_CAPSENSE_BIST_V3_ELTD_CAP_CYCLES_NUM                 (1u)
+#define CY_CAPSENSE_BIST_CAP_MEAS_CDAC_LSB_FF_DIV_1000          (8860u)
+#define CY_CAPSENSE_BIST_CP_MAX_VALUE                           (200000u)
+#define CY_CAPSENSE_BIST_CSH_MAX_VALUE                          (1600000u)
+#define CY_CAPSENSE_BIST_PROMILLE_FACTOR                        (1000u)
+
+/** Initialization of sensing method template variable */
+#define CY_CAPSENSE_BIST_SENSING_METHOD_BASE_TEMPLATE   \
+    {                                                   \
+        .ctl = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_SENSE_EN << MSC_CTL_SENSE_EN_Pos)                    | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_MSCCMP_EN << MSC_CTL_MSCCMP_EN_Pos)                   | \
+                    ((uint32_t)CY_CAPSENSE_SCAN_MODE_INT_DRIVEN << MSC_CTL_OPERATING_MODE_Pos)                       | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_BUF_MODE << MSC_CTL_BUF_MODE_Pos)                     | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_CLK_MSC_RATIO << MSC_CTL_CLK_MSC_RATIO_Pos)           | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_CTL_FLD_ENABLED << MSC_CTL_ENABLED_Pos)),                      \
+        .spare              = 0x00uL, \
+        .scanCtl1           = 0x00uL, \
+        .scanCtl2           = 0x00uL, \
+        .initCtl1           = 0x00uL, \
+        .initCtl2           = 0x00uL, \
+        .initCtl3           = 0x00uL, \
+        .initCtl4           = 0x00uL, \
+        .senseDutyCtl = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SENSE_DUTY_CTL_FLD_PHASE_WIDTH << MSC_SENSE_DUTY_CTL_PHASE_WIDTH_Pos)              | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_CYCLES << MSC_SENSE_DUTY_CTL_PHASE_SHIFT_CYCLES_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SENSE_DUTY_CTL_FLD_PHASE_WIDTH_SEL << MSC_SENSE_DUTY_CTL_PHASE_WIDTH_SEL_Pos)),      \
+        .sensePeriodCtl     = 0x00uL, \
+        .filterCtl          = 0x00uL, \
+        .ccompCdacCtl       = 0x00uL, \
+        .ditherCdacCtl      = 0x00uL, \
+        .cswCtl             = 0x00uL, \
+        .swSelGpio          = 0x00uL, \
+        .swSelCdacRe = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_RETCA << MSC_SW_SEL_CDAC_RE_SW_RETCA_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_RECB   << MSC_SW_SEL_CDAC_RE_SW_RECB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_RETV   << MSC_SW_SEL_CDAC_RE_SW_RETV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_RETG   << MSC_SW_SEL_CDAC_RE_SW_RETG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_REBV   << MSC_SW_SEL_CDAC_RE_SW_REBV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CDAC_RE_FLD_SW_REBG   << MSC_SW_SEL_CDAC_RE_SW_REBG_Pos)), \
+        .swSelCdacCo        = 0x00uL, \
+        .swSelCdacCf        = 0x00uL, \
+        .swSelCmod1 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CA << MSC_SW_SEL_CMOD1_SW_C1CA_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CB  << MSC_SW_SEL_CMOD1_SW_C1CB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CC  << MSC_SW_SEL_CMOD1_SW_C1CC_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CV  << MSC_SW_SEL_CMOD1_SW_C1CV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_SW_C1CG  << MSC_SW_SEL_CMOD1_SW_C1CG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_REF_MODE << MSC_SW_SEL_CMOD1_REF_MODE_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD1_FLD_ENABLED  << MSC_SW_SEL_CMOD1_ENABLED_Pos)), \
+        .swSelCmod2 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CA << MSC_SW_SEL_CMOD2_SW_C2CA_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CB  << MSC_SW_SEL_CMOD2_SW_C2CB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CC  << MSC_SW_SEL_CMOD2_SW_C2CC_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CV  << MSC_SW_SEL_CMOD2_SW_C2CV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_SW_C2CG  << MSC_SW_SEL_CMOD2_SW_C2CG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_REF_MODE << MSC_SW_SEL_CMOD2_REF_MODE_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD2_FLD_ENABLED  << MSC_SW_SEL_CMOD2_ENABLED_Pos)), \
+        .swSelCmod3 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CA << MSC_SW_SEL_CMOD3_SW_C3CA_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CB  << MSC_SW_SEL_CMOD3_SW_C3CB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CC  << MSC_SW_SEL_CMOD3_SW_C3CC_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CV  << MSC_SW_SEL_CMOD3_SW_C3CV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_SW_C3CG  << MSC_SW_SEL_CMOD3_SW_C3CG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_REF_MODE << MSC_SW_SEL_CMOD3_REF_MODE_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD3_FLD_ENABLED  << MSC_SW_SEL_CMOD3_ENABLED_Pos)), \
+        .swSelCmod4 = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CA << MSC_SW_SEL_CMOD4_SW_C4CA_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CB  << MSC_SW_SEL_CMOD4_SW_C4CB_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CC  << MSC_SW_SEL_CMOD4_SW_C4CC_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CV  << MSC_SW_SEL_CMOD4_SW_C4CV_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_SW_C4CG  << MSC_SW_SEL_CMOD4_SW_C4CG_Pos)  | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_REF_MODE << MSC_SW_SEL_CMOD4_REF_MODE_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_SW_SEL_CMOD4_FLD_ENABLED  << MSC_SW_SEL_CMOD4_ENABLED_Pos)), \
+        .obsCtl             = 0x00uL, \
+        .status1            = 0x00uL, \
+        .status2            = 0x00uL, \
+        .status3            = 0x00uL, \
+        .resultFifoStatus   = 0x00uL, \
+        .resultFifoRd       = 0x00uL, \
+        .intr = \
+                    ((CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_SUB_SAMPLE    << MSC_INTR_SUB_SAMPLE_Pos)     | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_SAMPLE         << MSC_INTR_SAMPLE_Pos)         | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_SCAN           << MSC_INTR_SCAN_Pos)           | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_INIT           << MSC_INTR_INIT_Pos)           | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_FRAME          << MSC_INTR_FRAME_Pos)          | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_FIFO_UNDERFLOW << MSC_INTR_FIFO_UNDERFLOW_Pos) | \
+                    (CY_CAPSENSE_SM_BASE_FULL_WAVE_REG_INTR_FLD_FIFO_OVERFLOW  << MSC_INTR_FIFO_OVERFLOW_Pos)), \
+        .intrSet            = 0x00uL, \
+        .intrMask           = 0x00uL, \
+        .intrMasked         = 0x00uL, \
+        .frameCmd           = 0x00uL, \
+        .sensorConfig = \
+        { \
+            .snsSwSelCswMask2   = 0x00uL, \
+            .snsSwSelCswMask1   = 0x00uL, \
+            .snsSwSelCswMask0   = 0x00uL, \
+            .snsScanCtl         = 0x00uL, \
+            .snsCdacCtl         = 0x00uL, \
+            .snsCtl             = 0x00uL, \
+        }, \
+        .swSelCsw = \
+        { \
+            [0u]       = 0x00uL, \
+            [1u]       = 0x00uL, \
+            [2u]       = 0x00uL, \
+            [3u]       = 0x00uL, \
+            [4u]       = 0x00uL, \
+            [5u]       = 0x00uL, \
+            [6u]       = 0x00uL, \
+            [7u]       = 0x00uL, \
+            [8u]       = 0x00uL, \
+            [9u]       = 0x00uL, \
+            [10u]      = 0x00uL, \
+            [11u]      = 0x00uL, \
+            [12u]      = 0x00uL, \
+            [13u]      = 0x00uL, \
+            [14u]      = 0x00uL, \
+            [15u]      = 0x00uL, \
+            [16u]      = 0x00uL, \
+            [17u]      = 0x00uL, \
+            [18u]      = 0x00uL, \
+            [19u]      = 0x00uL, \
+            [20u]      = 0x00uL, \
+            [21u]      = 0x00uL, \
+            [22u]      = 0x00uL, \
+            [23u]      = 0x00uL, \
+            [24u]      = 0x00uL, \
+            [25u]      = 0x00uL, \
+            [26u]      = 0x00uL, \
+            [27u]      = 0x00uL, \
+            [28u]      = 0x00uL, \
+            [29u]      = 0x00uL, \
+            [30u]      = 0x00uL, \
+            [31u]      = 0x00uL, \
+        }, \
+        .swSelCswFunc = \
+        { \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_RX] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW0_RX_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_TX] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW1_TX_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_TX_NEGATIVE] = 0x00uL, \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_GND] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW4_GND_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_SNS] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW3_SNS_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_HIGH_Z] = (CY_CAPSENSE_SM_REG_SW_SEL_CSW5_HIGH_Z_VALUE), \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_SHIELD] = 0x00uL, \
+            [CY_CAPSENSE_CTRLMUX_PIN_STATE_VDDA2] = 0x00uL, \
+        }, \
+        .mode = \
+        { \
+            [CY_CAPSENSE_CSD_RM_SENSING_METHOD_INDEX] = \
+            { \
+                .senseDutyCtl = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH2_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH3_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN     << MSC_MODE_SENSE_DUTY_CTL_PH_GAP_2CYCLE_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN    << MSC_MODE_SENSE_DUTY_CTL_PHX_GAP_2CYCLE_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN       << MSC_MODE_SENSE_DUTY_CTL_PHASE_SHIFT_EN_Pos)       | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL       << MSC_MODE_SENSE_DUTY_CTL_PHASE_MODE_SEL_Pos)),      \
+                .swSelCdacFl =  0u, \
+                .swSelTop = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACB     << MSC_MODE_SW_SEL_TOP_CACB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACC     << MSC_MODE_SW_SEL_TOP_CACC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CBCC     << MSC_MODE_SW_SEL_TOP_CBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBCC     << MSC_MODE_SW_SEL_TOP_MBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYA_CTL  << MSC_MODE_SW_SEL_TOP_AYA_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYB_CTL  << MSC_MODE_SW_SEL_TOP_AYB_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BYB      << MSC_MODE_SW_SEL_TOP_BYB_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SOSH     << MSC_MODE_SW_SEL_TOP_SOSH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHV      << MSC_MODE_SW_SEL_TOP_SHV_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHG      << MSC_MODE_SW_SEL_TOP_SHG_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BGRF     << MSC_MODE_SW_SEL_TOP_BGRF_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_RMF      << MSC_MODE_SW_SEL_TOP_RMF_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBF      << MSC_MODE_SW_SEL_TOP_MBF_Pos)),    \
+                .swSelComp = 0u, \
+                .swSelSh = \
+                        ((CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SH    << MSC_MODE_SW_SEL_SH_C1SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SH    << MSC_MODE_SW_SEL_SH_C3SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SOMB    << MSC_MODE_SW_SEL_SH_SOMB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CBSO    << MSC_MODE_SW_SEL_SH_CBSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS1   << MSC_MODE_SW_SEL_SH_SPCS1_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS3   << MSC_MODE_SW_SEL_SH_SPCS3_Pos)   | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_FSP     << MSC_MODE_SW_SEL_SH_FSP_Pos)     | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CCSO    << MSC_MODE_SW_SEL_SH_CCSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_SEL << MSC_MODE_SW_SEL_SH_BUF_SEL_Pos) | \
+                         (CY_CAPSENSE_SM_CSD_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_EN  << MSC_MODE_SW_SEL_SH_BUF_EN_Pos)), \
+            }, \
+            [CY_CAPSENSE_CSX_RM_SENSING_METHOD_INDEX] = \
+            { \
+                .senseDutyCtl = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH2_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH2_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH3_EN     << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH3_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH0_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_FS2_PH1_EN << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PH_GAP_2CYCLE_EN     << MSC_MODE_SENSE_DUTY_CTL_PH_GAP_2CYCLE_EN_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH0X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH0X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_GAP_PH1X_EN    << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_PH1X_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHX_GAP_2CYCLE_EN    << MSC_MODE_SENSE_DUTY_CTL_PHX_GAP_2CYCLE_EN_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_SHIFT_EN       << MSC_MODE_SENSE_DUTY_CTL_PHASE_SHIFT_EN_Pos)       | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SENSE_DUTY_CTL_FLD_PHASE_MODE_SEL       << MSC_MODE_SENSE_DUTY_CTL_PHASE_MODE_SEL_Pos)),      \
+                .swSelCdacFl =  0u, \
+                .swSelTop = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACB     << MSC_MODE_SW_SEL_TOP_CACB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CACC     << MSC_MODE_SW_SEL_TOP_CACC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_CBCC     << MSC_MODE_SW_SEL_TOP_CBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBCC     << MSC_MODE_SW_SEL_TOP_MBCC_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYA_CTL  << MSC_MODE_SW_SEL_TOP_AYA_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_AYB_CTL  << MSC_MODE_SW_SEL_TOP_AYB_CTL_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BYB      << MSC_MODE_SW_SEL_TOP_BYB_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SOSH     << MSC_MODE_SW_SEL_TOP_SOSH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHV      << MSC_MODE_SW_SEL_TOP_SHV_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_SHG      << MSC_MODE_SW_SEL_TOP_SHG_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_BGRF     << MSC_MODE_SW_SEL_TOP_BGRF_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_RMF      << MSC_MODE_SW_SEL_TOP_RMF_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_TOP_FLD_MBF      << MSC_MODE_SW_SEL_TOP_MBF_Pos)),    \
+                .swSelComp = 0u, \
+                .swSelSh = \
+                        ((CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SHG   << MSC_MODE_SW_SEL_SH_C1SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C1SH    << MSC_MODE_SW_SEL_SH_C1SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SHG   << MSC_MODE_SW_SEL_SH_C3SHG_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_C3SH    << MSC_MODE_SW_SEL_SH_C3SH_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SOMB    << MSC_MODE_SW_SEL_SH_SOMB_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CBSO    << MSC_MODE_SW_SEL_SH_CBSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS1   << MSC_MODE_SW_SEL_SH_SPCS1_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_SPCS3   << MSC_MODE_SW_SEL_SH_SPCS3_Pos)   | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_FSP     << MSC_MODE_SW_SEL_SH_FSP_Pos)     | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_CCSO    << MSC_MODE_SW_SEL_SH_CCSO_Pos)    | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_SEL << MSC_MODE_SW_SEL_SH_BUF_SEL_Pos) | \
+                         (CY_CAPSENSE_SM_CSX_FULL_WAVE_CTRL_MUX_REG_MODE0_SW_SEL_SH_FLD_BUF_EN  << MSC_MODE_SW_SEL_SH_BUF_EN_Pos)), \
+            }, \
+            [2u] = \
+            { \
+                .senseDutyCtl   = 0x00uL, \
+                .swSelCdacFl    = 0x00uL, \
+                .swSelTop       = 0x00uL, \
+                .swSelComp      = 0x00uL, \
+                .swSelSh        = 0x00uL, \
+            }, \
+            [3u] = \
+            { \
+                .senseDutyCtl   = 0x00uL, \
+                .swSelCdacFl    = 0x00uL, \
+                .swSelTop       = 0x00uL, \
+                .swSelComp      = 0x00uL, \
+                .swSelSh        = 0x00uL, \
+            }, \
+        }, \
+    }
+
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+    static cy_en_capsense_bist_status_t Cy_CapSense_CheckAllWidgetCRC(
+                cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+    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);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+    static void Cy_CapSense_BistSwitchHwConfig(
+                    cy_en_capsense_bist_hw_config_t hwCfg,
+                    uint8_t bistSenseGroup,
+                    uint8_t bistScanMode,
+                    cy_stc_capsense_context_t * context);
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+        static void Cy_CapSense_BistSetPinDr(
+                        cy_stc_capsense_pin_config_t const *ioPtr,
+                        uint32_t value);
+        static void Cy_CapSense_BistSetPinPc(
+                        cy_stc_capsense_pin_config_t const *ioPtr,
+                        uint32_t value);
+    #endif
+    static void Cy_CapSense_BistSwitchAllSnsPinState(
+                    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);
+    void Cy_CapSense_BistSetAllSnsPinsState(
+                    uint32_t desiredDriveMode,
+                    uint32_t desiredPinOutput,
+                    en_hsiom_sel_t desiredHsiom,
+                    const cy_stc_capsense_context_t * context);
+    void Cy_CapSense_BistSetAllCmodPinsState(
+                    uint32_t desiredDriveMode,
+                    uint32_t desiredPinOutput,
+                    en_hsiom_sel_t desiredHsiom,
+                    const cy_stc_capsense_context_t * context);
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        static void Cy_CapSense_BistSwitchAllShieldPinState(
+                        cy_en_capsense_bist_io_state_t desiredPinState,
+                        const cy_stc_capsense_context_t * context);
+        void Cy_CapSense_BistSetAllShieldPinsState(
+                        uint32_t desiredDriveMode,
+                        uint32_t desiredPinOutput,
+                        en_hsiom_sel_t desiredHsiom,
+                        const cy_stc_capsense_context_t * context);
+    #endif
+
+    static void Cy_CapSense_BistSetDmHsiomPinState(
+                    cy_en_capsense_bist_io_state_t desiredPinState,
+                    const cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN)
+    static cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceAllElectrodes(
+                cy_stc_capsense_context_t * context);
+#endif
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+    static cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceAllSensors(
+                cy_stc_capsense_context_t * context);
+#endif
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN)
+    static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSensor(
+                    uint32_t * cpPtr,
+                    cy_stc_capsense_context_t * context);
+#endif
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) || \
+    ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+     (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN)))
+    static cy_en_capsense_bist_status_t Cy_CapSense_BistMeasureCapacitanceSlot(
+                    uint32_t slotId,
+                    cy_stc_capsense_context_t * context);
+#endif
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN)
+    static cy_capsense_status_t Cy_CapSense_BistMeasureCapacitanceSensorEnable(
+                    cy_stc_capsense_context_t * context);
+    static void Cy_CapSense_BistMeasureCapacitanceSensorRun(
+                    cy_stc_capsense_context_t * context);
+    static void Cy_CapSense_BistGenerateBaseConfig(
+                    uint32_t chIndex,
+                    cy_stc_capsense_context_t * context);
+    static void Cy_CapSense_BistGenerateSensorConfig(
+                    uint32_t chIndex,
+                    uint32_t * ptrSensorCfg,
+                    cy_stc_capsense_context_t * context);
+
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+        static void Cy_CapSense_BistGenerateSnsCfgMaskReg(
+                        const cy_stc_capsense_electrode_config_t * ptrEltdCfg,
+                        uint32_t * ptrSensorCfg,
+                        uint32_t cswFuncNum);
+    #endif
+
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN) && \
+         (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD))
+        static void Cy_CapSense_BistConnectEltd(
+                        const cy_stc_capsense_electrode_config_t * ptrEltdConfig,
+                        const cy_stc_capsense_context_t * context);
+        static void Cy_CapSense_BistDisconnectEltd(
+                        const cy_stc_capsense_electrode_config_t * ptrEltdConfig,
+                        cy_en_capsense_bist_io_state_t desiredPinState,
+                        const cy_stc_capsense_context_t * context);
+    #endif
+
+    static uint32_t Cy_CapSense_BistWatchdogPeriodCalc(
+                    const cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN) */
+
+
+/** \} \endcond */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_RunSelfTest_V3
+****************************************************************************//**
+*
+* Runs built-in self-tests for 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_BIST_RUN_AVAILABLE_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_MeasureCapacitanceSensorElectrode()
+* - Cy_CapSense_MeasureCapacitanceSlotSensors()
+* - Cy_CapSense_MeasureCapacitanceChannelsShield()
+*
+* Refer to these functions descriptions for detail information
+* on the corresponding test.
+*
+* \note
+* The function is available only for the fifth-generation CAPSENSE&trade;.
+*
+* \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_MASK       - Verifies the RAM widget structure CRC
+*                                          for all the widgets.
+* - CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK  - Checks all the sensors for a short
+*                                          to GND / VDD / other sensors.
+* - CY_CAPSENSE_BIST_SNS_CAP_MASK        - Measures all the sensors capacitance.
+* - CY_CAPSENSE_BIST_ELTD_CAP_MASK       - Measures all the electrodes capacitance.
+* - CY_CAPSENSE_BIST_SHIELD_CAP_MASK     - Measures the shield capacitance.
+* - CY_CAPSENSE_BIST_RUN_AVAILABLE_SELF_TEST_MASK
+*                                        - Executes all available tests.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_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_V3(
+                uint32_t testEnMask,
+                cy_stc_capsense_context_t * context)
+{
+    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_NOT_BUSY == Cy_CapSense_IsBusy(context))
+            {
+                result = CY_CAPSENSE_BIST_SUCCESS_E;
+
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+                    if (0u != (CY_CAPSENSE_BIST_CRC_WDGT_MASK & testEnMask))
+                    {
+                        if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_CheckAllWidgetCRC(context))
+                        {
+                            result = CY_CAPSENSE_BIST_FAIL_E;
+                            context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_CRC_WDGT_MASK;
+                        }
+                    }
+                #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+
+                #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+                    /* The next group of tests is hardware-dependent and they need to switch the configuration to BIST one */
+                    if((uint32_t)CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_BIST_FUNCTIONALITY, context))
+                    {
+
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+                            if (0u != (CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK & testEnMask))
+                            {
+                                if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_SnsShortCheckAllSensors(context))
+                                {
+                                    result = CY_CAPSENSE_BIST_FAIL_E;
+                                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK;
+                                }
+                            }
+                        #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+                            if (0u != (CY_CAPSENSE_BIST_SNS_CAP_MASK & testEnMask))
+                            {
+                                if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_MeasureCapacitanceAllSensors(context))
+                                {
+                                    result = CY_CAPSENSE_BIST_FAIL_E;
+                                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SNS_CAP_MASK;
+                                }
+                            }
+                        #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN)
+                            if (0u != (CY_CAPSENSE_BIST_ELTD_CAP_MASK & testEnMask))
+                            {
+                                if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_MeasureCapacitanceAllElectrodes(context))
+                                {
+                                    result = CY_CAPSENSE_BIST_FAIL_E;
+                                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_ELTD_CAP_MASK;
+                                }
+                            }
+                        #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN) */
+
+                        #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) &&\
+                             (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))
+                            if ((0u != (CY_CAPSENSE_BIST_SHIELD_CAP_MASK & testEnMask)) &&
+                                (CY_CAPSENSE_DISABLE != context->ptrCommonConfig->csdShieldMode))
+                            {
+                                if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_MeasureCapacitanceShieldElectrode(0u, context))
+                                {
+                                    result = CY_CAPSENSE_BIST_FAIL_E;
+                                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SHIELD_CAP_MASK;
+                                }
+                            }
+                        #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) &&\
+                                   (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN)) */
+                    }
+                    else
+                    {
+                        result = CY_CAPSENSE_BIST_ERROR_E;
+                    }
+                #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */
+            }
+            else
+            {
+                result = CY_CAPSENSE_BIST_HW_BUSY_E;
+            }
+        }
+    }
+
+    return (result);
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckCRCWidget_V3
+****************************************************************************//**
+*
+* 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_MASK bit is set in the .testResultMask field.
+*
+* The function never clears the CY_CAPSENSE_BIST_CRC_WDGT_MASK bit.
+* If the CY_CAPSENSE_BIST_CRC_WDGT_MASK 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 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.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_en_capsense_bist_status_t Cy_CapSense_CheckCRCWidget_V3(
+                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 (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_MASK))
+                {
+                    context->ptrBistContext->wdgtCrcCalc = crcValue;
+                    context->ptrBistContext->crcWdgtId = (uint8_t)widgetId;
+                    context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_CRC_WDGT_MASK;
+                }
+                ptrWdCxt->status &= (uint8_t)~CY_CAPSENSE_WD_WORKING_MASK;
+                result = CY_CAPSENSE_BIST_FAIL_E;
+            }
+            else
+            {
+                result = CY_CAPSENSE_BIST_SUCCESS_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&trade; 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_V3(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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_WDGT_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_UpdateCrcWidget(
+                uint32_t 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_UpdateAllWidgetCrc
+****************************************************************************//**
+*
+* The internal function that updates CRC of all widget structures.
+*
+* The function implements the following functionality:
+* - Executes the Cy_CapSense_UpdateCrcWidget() for all widgets.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_UpdateAllWidgetCrc(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);
+    }
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckIntegritySensorBaseline_V3
+****************************************************************************//**
+*
+* 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_MASK bit
+* in the .testResultMask field of the \ref cy_stc_capsense_bist_context_t
+* structure.
+*
+* The test is integrated into the CAPSENSE&trade; Middleware. All CAPSENSE&trade;
+* 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_CAPSENSE_STATUS_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.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_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&trade; 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_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorBaseline_V3(
+                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;
+    uint16_t bslnInv;
+    uint32_t cxtOffset;
+    const cy_stc_capsense_sensor_context_t *ptrSnsCxt;
+    cy_stc_capsense_widget_config_t const *ptrWdgtCfg;
+
+    if(NULL != context)
+    {
+        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 baselines */
+
+            cxtOffset = sensorId;
+            bslnInv = (uint16_t)(~(ptrWdgtCfg->ptrBslnInv[cxtOffset]));
+            if ((ptrSnsCxt->bsln != bslnInv) ||
+                (ptrSnsCxt->bsln > baselineHighLimit) ||
+                (ptrSnsCxt->bsln < baselineLowLimit))
+            {
+                context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_BSLN_INTEGRITY_MASK;
+                result = CY_CAPSENSE_BIST_FAIL_E;
+            }
+
+            if (CY_CAPSENSE_BIST_FAIL_E != result)
+            {
+                result = CY_CAPSENSE_BIST_SUCCESS_E;
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckIntegritySensorRawcount_V3
+****************************************************************************//**
+*
+* 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_MASK 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.
+*
+* \note
+* This function is available only for the fourth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_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&trade; 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_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorRawcount_V3(
+                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;
+    const cy_stc_capsense_sensor_context_t *ptrSnsCxt;
+    cy_stc_capsense_widget_config_t const *ptrWdgtCfg;
+
+    if(NULL != context)
+    {
+        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 raw counts */
+            if ((ptrSnsCxt->raw  > rawcountHighLimit) ||
+                (ptrSnsCxt->raw  < rawcountLowLimit))
+            {
+                context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_RAW_INTEGRITY_MASK;
+                result = CY_CAPSENSE_BIST_FAIL_E;
+            }
+
+            if (CY_CAPSENSE_BIST_FAIL_E != result)
+            {
+                result = CY_CAPSENSE_BIST_SUCCESS_E;
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_CheckIntegritySensorPins_V3
+****************************************************************************//**
+*
+* 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&trade; (such as sensors, Tx, Rx,
+*   shield electrodes, and external capacitors)
+* * Other non-CAPSENSE&trade; 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&trade; 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&trade; 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&trade; 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_INTEGRITY_MASK bit is set in the .testResultMask field
+*   of the \ref cy_stc_capsense_bist_context_t structure.
+* * If CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK 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_INTEGRITY_MASK 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 in the .status field of the \ref cy_stc_capsense_widget_context_t structure
+*   of the specified widget.
+*
+* To check all the project sensors at once, use the Cy_CapSense_RunSelfTest()
+* function with the CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK mask.
+*
+* To detect an electrical short or fault condition with resistance
+* higher than 1500 ohm, the Cy_CapSense_MeasureCapacitanceSensorElectrode() function can
+* be used as the fault condition affects the measured sensor capacitance.
+*
+* This test can be executed only if the CAPSENSE&trade; Middleware is in the IDLE
+* state. This function must not be called while CAPSENSE&trade; Middleware is busy.
+*
+*
+* \note
+* This function is available only for the fifth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; 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&trade; Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense_<WidgetName>_RX<RXNumber>_ID
+* * CapSense_<WidgetName>_TX<TXNumber>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E          - Sensor pin resistances are in defined range.
+* - CY_CAPSENSE_BIST_FAIL_E             - The test failed and Sensor pin resistances
+*                                         are out of the defined range.
+* - 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_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorPins_V3(
+                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 (context->ptrCommonConfig->numWd > widgetId)
+        {
+            /* Get a total number of the widget elements: for CSX it is numRows + numCols, for CSD it is totalNumSns */
+            if (CY_CAPSENSE_CSX_GROUP == 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 ((uint32_t)CY_CAPSENSE_SUCCESS_E == Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_BIST_FUNCTIONALITY, context))
+                {
+                    /* Switch the HW resource configuration to the sensor short test */
+                    Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_SHORT_E, CY_CAPSENSE_UNDEFINED_GROUP, 0u,
+                                                   context);
+
+                    /* Set all CAPSENSE&trade; pins to strong-high */
+                    Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+                    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+                    #endif
+                    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->snsIntgShortSettlingTime);
+
+                    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&trade; pins to strong-low */
+                    Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+                    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+                    #endif
+                    Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+
+                    /* Wait for the maximum possible external capacitor charging time */
+                    Cy_SysLib_DelayUs(context->ptrBistContext->snsIntgShortSettlingTime);
+
+                    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;
+                }
+            }
+        }
+    }
+
+    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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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_<WIDGET_NAME>_SNS<SENSOR_NUMBER>_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_<WIDGET_NAME>_<TX/RX><TX/RX_NUMBER>_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&trade; 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 (CY_CAPSENSE_CSX_GROUP == 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: Cy_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&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_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&trade; 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_BistSetPinDr(ioPtr, (mode ^ 0x01u));
+        Cy_CapSense_BistSetPinPc(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_BistSetPinDr(ioPtr, mode);
+        Cy_CapSense_BistSetPinPc(ioPtr, CY_CAPSENSE_DM_GPIO_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_MASK 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&trade; 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_MASK))
+    {
+        /* Write to the BIST context structure widgetId and sensorId of the first shorted sensor */
+        context->ptrBistContext->testResultMask |= CY_CAPSENSE_BIST_SNS_INTEGRITY_MASK;
+        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&trade; 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;
+    uint32_t numWdgtElectrodes;
+    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, CY_CAPSENSE_UNDEFINED_GROUP, 0u,
+                                   context);
+
+    Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_HIGH_E, context);
+    #endif
+    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->snsIntgShortSettlingTime);
+
+    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 (CY_CAPSENSE_CSX_GROUP == 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;
+        }
+
+        for (sensorId = 0u; sensorId < numWdgtElectrodes; 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);
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+    #endif
+    Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+
+    /* Wait for the maximum possible external capacitor charging time */
+    Cy_SysLib_DelayUs(context->ptrBistContext->snsIntgShortSettlingTime);
+
+    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 (CY_CAPSENSE_CSX_GROUP == 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;
+        }
+
+        for (sensorId = 0u; sensorId < numWdgtElectrodes; 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_BistSetPinDr
+****************************************************************************//**
+*
+* 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_BistSetPinDr(
+                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_BistSetPinPc
+****************************************************************************//**
+*
+* 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_BistSetPinPc(
+                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);
+}
+#endif
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistSetAllSnsPinsState
+****************************************************************************//**
+*
+* Sets all CAPSENSE&trade; pins into a desired 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistSetAllSnsPinsState(
+                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 = context->ptrPinConfig;
+
+    /* Loop through all electrodes */
+    for (loopIndex = 0u; loopIndex < context->ptrCommonConfig->numPin; 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 next electrode */
+        ptrPinCfg++;
+    }
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistSetAllShieldPinsState
+****************************************************************************//**
+*
+* Sets all shield pins into a desired state.
+*
+* Sets all the dedicated shield electrodes into a desired state.
+* 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistSetAllShieldPinsState(
+                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 = context->ptrShieldPinConfig;
+
+    /* Loop through all electrodes */
+    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 next electrode */
+        ptrPinCfg++;
+    }
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) */
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistSetAllCmodPinsState
+****************************************************************************//**
+*
+* Sets all available MSC Cmod pins connected into a desired state .
+*
+* Sets all external capacitors connected into a desired state.
+* 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistSetAllCmodPinsState(
+                uint32_t desiredDriveMode,
+                uint32_t desiredPinOutput,
+                en_hsiom_sel_t desiredHsiom,
+                const cy_stc_capsense_context_t * context)
+{
+    uint32_t curChIndex;
+
+    uint8_t cmod1Pin;
+    uint8_t cmod2Pin;
+
+    GPIO_PRT_Type * cmod1Port;
+    GPIO_PRT_Type * cmod2Port;
+
+    const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig;
+
+    /* Loop through all electrodes */
+    for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+    {
+        cmod1Port = ptrCommonCfg->ptrMscChConfig[curChIndex].portCmod1;
+        cmod1Pin = ptrCommonCfg->ptrMscChConfig[curChIndex].pinCmod1;
+
+        cmod2Port = ptrCommonCfg->ptrMscChConfig[curChIndex].portCmod2;
+        cmod2Pin = ptrCommonCfg->ptrMscChConfig[curChIndex].pinCmod2;
+
+        Cy_CapSense_SsConfigPinRegisters(cmod1Port, (uint32_t)cmod1Pin, desiredDriveMode, desiredHsiom);
+        Cy_CapSense_SsConfigPinRegisters(cmod2Port, (uint32_t)cmod2Pin, desiredDriveMode, desiredHsiom);
+
+        if (0u != desiredPinOutput)
+        {
+            Cy_GPIO_Set(cmod1Port, (uint32_t)cmod1Pin);
+        }
+        else
+        {
+            Cy_GPIO_Clr(cmod1Port, (uint32_t)cmod1Pin);
+        }
+
+        if (0u != desiredPinOutput)
+        {
+            Cy_GPIO_Set(cmod2Port, (uint32_t)cmod2Pin);
+        }
+        else
+        {
+            Cy_GPIO_Clr(cmod2Port, (uint32_t)cmod2Pin);
+        }
+    }
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceSensorElectrode
+****************************************************************************//**
+*
+* Measures the specified CSD sensor / CSX electrode capacitance in femtofarads.
+*
+* This function measures the sensor capacitance for CSD widgets or the electrode
+* capacitance 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
+* eltdId 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 or -shorted sensors. For example, the PCB track is
+* broken or shorted to other nodes in the system - in all of these conditions,
+* this function returns changed 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 default scanning parameters are the following:
+* * SnsClk divider (256) is the divider for the sensor clock frequency.
+* * NumConv (100) is the number of sub-conversions.
+* * The reference CDAC capacitance (886 fF) is equivalent to CDAC Code of 100u.
+* * The compensation CDAC is disabled.
+* * The CIC2 filter is disabled.
+* * The dithering is disabled.
+* * The chopping is disabled.
+*
+* The raw count is converted into capacitance using the following equation:
+*
+*  Cs = Rawcount * RefCDAC capacitance / NumConv
+*
+* where:
+* * Cs is the sensor capacitance.
+* * Rawcount is the measured raw count value.
+*
+* The minimum measurable input by this function is 1pF and the
+* maximum is either 200pF 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 30% and
+* is defined by the RefCDAC tolerance.
+*
+* By default, all CAPSENSE&trade; sensors (electrodes) that are not being
+* measured are set to the GND state for CSD measured electrodes (sensors) and
+* to the HIGH-Z state for CSX measured electrodes (Rx and Tx).
+* Shield electrodes are also configured to the GND state.
+* The inactive state can be changed in run-time by using
+* the Cy_CapSense_SetInactiveElectrodeState() function.
+*
+* By default, the both Cmod1 and Cmod2 capacitors are used for the measurement.
+*
+* The sensor measurement can be done on all the electrodes using
+* the Cy_CapSense_RunSelfTest() function along with
+* the CY_CAPSENSE_BIST_ELTD_CAP_MASK mask.
+*
+* This function must not be called while the CAPSENSE&trade; MW is busy
+* by another scan.
+*
+* \note
+* This function is available only for the fifth-generation CAPSENSE&trade;.
+*
+* \param widgetId
+* Specifies the ID number of the widget.
+* A macro for the widget ID can be found in the
+* CAPSENSE&trade; Configuration header file (cycfg_capsense.h) defined as
+* CY_CAPSENSE_<WidgetName>_WDGT_ID.
+*
+* \param eltdId
+* Specifies the ID of the electrode within the widget (sensorID for CSD
+* widgets and Rx or Tx electrode ID for CSX widgets).
+*
+* For the CSD widgets, a macro for the sensor ID within the specified widget
+* can be found in the CAPSENSE&trade; Configuration header file (cycfg_capsense.h)
+* defined as CY_CAPSENSE_<WidgetName>_SNS<SensorNumber>_ID.
+*
+* For the CSX widgets, eltdId is an electrode ID and is defined as Rx ID
+* or Tx ID. The first Rx in a widget corresponds to eltdId = 0, the
+* second Rx in a widget corresponds to eltdId = 1, and so on.
+* The last Tx in a widget corresponds to eltdId = (RxNum + TxNum - 1).
+* Macros for Rx and Tx IDs can be found in the CAPSENSE&trade; Configuration header
+* file (cycfg_capsense.h) defined as:
+* * CapSense_<WidgetName>_RX<RXNumber>_ID
+* * CapSense_<WidgetName>_TX<TXNumber>_ID.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSensorElectrode(
+                uint32_t widgetId,
+                uint32_t eltdId,
+                cy_stc_capsense_context_t * context)
+{
+    cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+    uint32_t numWdgtElectrodes;
+    const cy_stc_capsense_electrode_config_t * ptrEltdCfg;
+
+    if(NULL != context)
+    {
+        if ((context->ptrCommonConfig->numWd > widgetId))
+        {
+            /* Get the total widget electrode number: for CSX it is numRows + numCols, for CSD it is totalNumSns */
+            if ((uint8_t)CY_CAPSENSE_CSX_GROUP == context->ptrWdConfig[widgetId].senseMethod)
+            {
+                /* For CSX widgets, get the sum of Rx and Tx electrode numbers */
+                numWdgtElectrodes = context->ptrWdConfig[widgetId].numRows +
+                          (uint32_t)context->ptrWdConfig[widgetId].numCols;
+                context->ptrBistContext->currentISC = context->ptrBistContext->intrEltdCapCsxISC;
+            }
+            else
+            {
+                numWdgtElectrodes = context->ptrWdConfig[widgetId].numSns;
+                context->ptrBistContext->currentISC = context->ptrBistContext->intrEltdCapCsdISC;
+            }
+            if (numWdgtElectrodes > eltdId)
+            {
+                if (CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(context))
+                {
+                    /* Set the BUSY status */
+                    context->ptrCommonContext->status = CY_CAPSENSE_BUSY | CY_CAPSENSE_MW_STATE_BIST_MASK;
+                    (void)Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_BIST_FUNCTIONALITY, context);
+                    /* Find the pointer to the electrode pin configuration and the electrode channel */
+                    ptrEltdCfg = &context->ptrWdConfig[widgetId].ptrEltdConfig[eltdId];
+                    /* Store the necessary values to the Bist context structure */
+                    context->ptrBistContext->curBistChId = ptrEltdCfg->chId;
+                    context->ptrBistContext->skipChannelMask = ~(1u << ptrEltdCfg->chId);
+                    context->ptrBistContext->curPtrEltdCfg = ptrEltdCfg;
+                    /* Switch the HW resource configuration to the sensor element capacitance measurement */
+                    Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_ELTD_CAP_E,
+                                                   CY_CAPSENSE_CSD_GROUP,
+                                                   CY_CAPSENSE_BIST_CAP_ELTD_SCAN,
+                                                   context);
+                    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                        Cy_CapSense_BistConnectEltd(ptrEltdCfg, context);
+                    #endif
+                    result = Cy_CapSense_BistMeasureCapacitanceSensor(
+                                &context->ptrWdConfig[widgetId].ptrEltdCapacitance[eltdId],
+                                context);
+                    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                        Cy_CapSense_BistDisconnectEltd(ptrEltdCfg, context->ptrBistContext->currentISC, context);
+                    #endif
+                    /* Clear the BUSY flag */
+                    context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY;
+                }
+                else
+                {
+                    result = CY_CAPSENSE_BIST_HW_BUSY_E;
+                }
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceAllSensors
+****************************************************************************//**
+*
+* This internal function measures all the sensor capacitances
+* (Cp for CSD sensors and Cm for CSX sensors).
+*
+* This function measures capacitances of all the sensors by using the
+* Cy_CapSense_MeasureCapacitanceSlotSensors() function.
+* The function stores sensor capacitance values in femtofarads
+* in the snsCap array defined
+* in the cycfg_capsense.c file. The pointer to the first element of the snsCap
+* array that contains the widget sensor capacitances is stored
+* in the .ptrSnsCapacitance field of the cy_stc_capsense_widget_config_t
+* structure.
+* The function is called by the Cy_CapSense_RunSelfTest() function.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_MeasureCapacitanceAllSensors(
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t slotId;
+    cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_SUCCESS_E;
+
+    /* Loop through all the slots */
+    for (slotId = 0u; slotId < CY_CAPSENSE_SLOT_COUNT; slotId++)
+    {
+        if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_MeasureCapacitanceSlotSensors(slotId, 0u, context))
+        {
+            if (CY_CAPSENSE_BIST_SUCCESS_E == result)
+            {
+                result = CY_CAPSENSE_BIST_FAIL_E;
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceAllElectrodes
+****************************************************************************//**
+*
+* This internal function measures all the electrodes (sensor for CSD widgets and
+* Rx/Tx electrodes for CSX widgets) parasitic capacitance (Cp).
+*
+* This function measures Cp of all the electrodes by using the
+* Cy_CapSense_MeasureCapacitanceSensorElectrode() function.
+* The function stores the Cp values in femtofarads in the eltdCap array defined
+* in the cycfg_capsense.c file. The pointer to the first element of the eltdCap
+* array that contains the widget electrode capacitances is stored
+* in the .ptrEltdCapacitance field of the cy_stc_capsense_widget_config_t
+* structure.
+* The function is called by the Cy_CapSense_RunSelfTest() function.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_MeasureCapacitanceAllElectrodes(
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t widgetId;
+    uint32_t electrodeId;
+    uint32_t numWdgtElectrodes;
+    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 (CY_CAPSENSE_CSX_GROUP == 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 (electrodeId = 0u; electrodeId < numWdgtElectrodes; electrodeId++)
+        {
+            if (CY_CAPSENSE_BIST_SUCCESS_E != Cy_CapSense_MeasureCapacitanceSensorElectrode(widgetId, electrodeId, context))
+            {
+                if (CY_CAPSENSE_BIST_SUCCESS_E == result)
+                {
+                    result = CY_CAPSENSE_BIST_FAIL_E;
+                }
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceSlotSensors
+****************************************************************************//**
+*
+* Measures the specified slot sensor capacitance in femtofarads. The function
+* measures the Cp capacitance for CSD widgets and the Cm capacitance
+* for CSX widgets.
+*
+* This function performs BIST slot scan with predefined parameters,
+* back-calculates the slot sensor capacitances (Cp for CSD and Cm for CSX)
+* by using the raw-count equation, stores the calculated capacitances
+* to the sensor context structure, and returns the measurement status.
+* If the specified slot has a ganged sensor, the capacitance
+* is measured for all the pins ganged together that belong to this sensor.
+*
+* Besides the sensor capacitance measuring, this function could be
+* used to identify various fault conditions with sensors such
+* as electrically-opened or -shorted sensors. For example, the PCB track is
+* broken or shorted to other nodes in the system - in all of these conditions,
+* the function returns changed 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 regular scan
+* configuration. For the capacitance measurement, the BIST specific scan
+* parameters are used. They can be found in the Electrode capacitance measurement
+* macros group.
+* The CDAC code for the CSD sensors is 100u and that provides about 0.886 pF
+* of the CDAC value and for CSX sensors the CDAC code is 50u (0.443 pF).
+* Compensation CDAC is disabled during the BIST scan.
+* Another default scanning parameters are the following:
+* * NumConv (100) is the number of sub-conversions.
+* * SnsClk divider (256) is the divider for the sensor clock frequency.
+*
+* The raw count is converted into capacitance using the following equation:
+*
+*  Cs = Rawcount * CDAC / 2 / NumConv / 2
+*
+* where:
+* * Cs is the sensor capacitance.
+* * Rawcount is the measured raw count value.
+* * The first divider of 2 is determined by the divided ref_clk frequency usage.
+* * The second divider of 2 is used only for CSX sensors.
+*
+* The minimum measurable input by this function is 0.5 pF and the
+* maximum is either 200pF or limited by the RC time constant
+* (Cs < 1 / (2*10*SnsClk*R), where R is the total sensor series
+* resistance that includes on-chip pin resistance ~500 Ohm and
+* external series resistance). The measurement accuracy is about 30%.
+*
+* By default, all CAPSENSE&trade; sensors (electrodes) that are not being
+* measured are set to the GND state for CSD measured electrodes (sensors) and
+* to the HIGH-Z state for CSX measured electrodes (Rx and Tx).
+* Shield electrodes are also configured to the GND state.
+* The inactive state can be changed in run-time by using
+* the Cy_CapSense_SetInactiveElectrodeState() function.
+*
+* By default, the both Cmod1 and Cmod2 capacitors are used for the measurement.
+*
+* Measured capacitance values (Cp for CSD widgets and Cm for CSX widgets)
+* are stored in the .snsCap field of the \ref cy_stc_capsense_sensor_context_t
+* structure.
+*
+* The all sensor measurement can be done on all the sensors using
+* the Cy_CapSense_RunSelfTest() function along with
+* the CY_CAPSENSE_BIST_SNS_CAP_MASK mask.
+*
+* This function must not be called while the CAPSENSE&trade; MW is busy
+* by another scan.
+*
+* \note
+* This function is available only for the fifth-generation CAPSENSE&trade;.
+*
+* \param slotId
+* Specifies the ID number of the slot to measure sensor capacitance.
+* The slot ID should be in the admissible range.
+*
+* \param skipChMask
+* Specifies the mask to skip some channels during the slot sensor capacitance
+* measurement. If the bit N in the skipChMask is set to 1, the channel N
+* will be excluded from measuring and all its pins will be set to the inactive
+* sensor connection state (see the .eltdCapCsdISC field
+* of the \ref cy_stc_capsense_bist_context_t structure for CSD widgets
+* and the .eltdCapCsxISC field respectively for CSX widgets).
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_ERROR_E            - An unexpected fault occurred during
+*                                         the measurement.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSlotSensors(
+                uint32_t slotId,
+                uint32_t skipChMask,
+                cy_stc_capsense_context_t * context)
+{
+    #if (CY_CAPSENSE_TOTAL_CH_NUMBER > 1u)
+        uint32_t i;
+    #endif
+
+    uint32_t wdIndex;
+    uint32_t snsIndex;
+    uint32_t curChIndex;
+    uint32_t curSlotIndex;
+    uint32_t scanSlotIndexValid;
+    const cy_stc_capsense_common_config_t * ptrCommonCfg;
+    cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+
+    if(NULL != context)
+    {
+        if (CY_CAPSENSE_SLOT_COUNT > slotId)
+        {
+            if (CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(context))
+            {
+                ptrCommonCfg = context->ptrCommonConfig;
+
+                /* Set the BUSY status */
+                context->ptrCommonContext->status = CY_CAPSENSE_BUSY | CY_CAPSENSE_MW_STATE_BIST_MASK;
+                (void)Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_BIST_FUNCTIONALITY, context);
+                /* Set the slot measurement mode for the BIST scan */
+                context->ptrBistContext->eltdCapScanMode = CY_CAPSENSE_BIST_CAP_SLOT_SCAN;
+                /* Store the current slot and the skip channel mask for the BIST scan */
+                context->ptrBistContext->curBistSlotId = (uint16_t)slotId;
+                context->ptrBistContext->skipChannelMask = (uint8_t)skipChMask;
+                /* Initialize active scan structure for BIST scan */
+                for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+                {
+                    Cy_CapSense_SetBusyFlags(curChIndex, context);
+                    curSlotIndex = slotId + ((curChIndex + ptrCommonCfg->channelOffset) * CY_CAPSENSE_SLOT_COUNT);
+                    scanSlotIndexValid = curSlotIndex;
+                    wdIndex = context->ptrScanSlots[curSlotIndex].wdId;
+                    if(CY_CAPSENSE_SLOT_EMPTY == wdIndex)
+                    {
+                        #if (CY_CAPSENSE_TOTAL_CH_NUMBER > 1u)
+                            for (i = 0u; i < CY_CAPSENSE_TOTAL_CH_NUMBER; i++)
+                            {
+                                /* Seek for the real sensor's slot index (not empty, not Tx only, not shield) */
+                                if (CY_CAPSENSE_SLOT_SHIELD_ONLY >
+                                    context->ptrScanSlots[slotId + ((i + ptrCommonCfg->channelOffset)
+                                                                    * CY_CAPSENSE_SLOT_COUNT)].wdId)
+                                {
+                                    scanSlotIndexValid = slotId + ((i + ptrCommonCfg->channelOffset)
+                                                                   * CY_CAPSENSE_SLOT_COUNT);
+                                    break;
+                                }
+                            }
+                            if (i == CY_CAPSENSE_TOTAL_CH_NUMBER)
+                            {
+                                result = CY_CAPSENSE_BIST_BAD_CONFIG_E;
+                            }
+                        #else
+                            result = CY_CAPSENSE_BIST_BAD_CONFIG_E;
+                        #endif /* (CY_CAPSENSE_TOTAL_CH_NUMBER > 1u) */
+                    }
+                    else if (CY_CAPSENSE_SLOT_SHIELD_ONLY <= wdIndex)
+                    {
+                        /* The snsId field keeps the channel number of the valid slot for Tx only slots */
+                        scanSlotIndexValid = ((uint32_t)context->ptrScanSlots[curSlotIndex].snsId * CY_CAPSENSE_SLOT_COUNT) +
+                                             slotId;
+                    }
+                    else
+                    {
+                        scanSlotIndexValid = curSlotIndex;
+                    }
+                    if (CY_CAPSENSE_BIST_BAD_CONFIG_E != result)
+                    {
+                        /* Initializes for each channel the active sensor structure for the current sensor */
+                        wdIndex = context->ptrScanSlots[scanSlotIndexValid].wdId;
+                        snsIndex = context->ptrScanSlots[scanSlotIndexValid].snsId;
+                        Cy_CapSense_InitActivePtr(curChIndex, wdIndex, snsIndex, context);
+                    }
+                }
+                if (CY_CAPSENSE_BIST_BAD_CONFIG_E != result)
+                {
+                    /* Define the current ISC for BIST scan.
+                     * The CSD or CSX group is the same for all slot sensors, choose the #0u channel
+                     */
+                    if (CY_CAPSENSE_CSD_GROUP == context->ptrActiveScanSns[0u].currentSenseMethod)
+                    {
+                        context->ptrBistContext->currentISC = context->ptrBistContext->intrEltdCapCsdISC;
+                        #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                            context->ptrInternalContext->csdInactiveSnsDm = CY_CAPSENSE_DM_GPIO_ANALOG;
+                            context->ptrInternalContext->csdInactiveSnsHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+                            /* Change Drive mode and HSIOM depending on the current inactive sensor connection */
+                            if (CY_CAPSENSE_BIST_IO_STRONG_E == context->ptrBistContext->currentISC)
+                            {
+                                context->ptrInternalContext->csdInactiveSnsDm = CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+                            }
+                            else if (CY_CAPSENSE_BIST_IO_HIGHZA_E == context->ptrBistContext->currentISC)
+                            {
+                                /* Do nothing */
+                            }
+                            else if (CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->currentISC)
+                            {
+                                context->ptrInternalContext->csdInactiveSnsDm = CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+                                context->ptrInternalContext->csdInactiveSnsHsiom = CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD;
+                            }
+                            else
+                            {
+                                /* Do nothing */
+                            }
+                        #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+                    }
+                    else
+                    {
+                        context->ptrBistContext->currentISC = context->ptrBistContext->intrEltdCapCsxISC;
+                        #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                            context->ptrInternalContext->csxInactiveSnsDm = CY_CAPSENSE_DM_GPIO_ANALOG;
+                            context->ptrInternalContext->csxInactiveSnsHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+                            /* Change Drive mode and HSIOM depending on the current inactive sensor connection */
+                            if (CY_CAPSENSE_BIST_IO_STRONG_E == context->ptrBistContext->currentISC)
+                            {
+                                context->ptrInternalContext->csxInactiveSnsDm = CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+                            }
+                        #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+                    }
+                    /* Switch the HW resource configuration to the sensor element capacitance measurement */
+                    Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_ELTD_CAP_E,
+                                                   context->ptrActiveScanSns[0u].currentSenseMethod,
+                                                   CY_CAPSENSE_BIST_CAP_SLOT_SCAN,
+                                                   context);
+                    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                        for (curChIndex = 0u; curChIndex < context->ptrCommonConfig->numChannels; curChIndex++)
+                        {
+                            if (((0x01uL << curChIndex) & skipChMask) == 0u)
+                            {
+                                curSlotIndex = slotId + ((curChIndex + ptrCommonCfg->channelOffset) * CY_CAPSENSE_SLOT_COUNT);
+                                if((context->ptrScanSlots[curSlotIndex].wdId != CY_CAPSENSE_SLOT_EMPTY) &&
+                                   (context->ptrScanSlots[curSlotIndex].wdId != CY_CAPSENSE_SLOT_SHIELD_ONLY))
+                                   {
+                                       Cy_CapSense_ConnectSensor(curChIndex, context);
+                                   }
+                            }
+                        }
+                    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+                    result = Cy_CapSense_BistMeasureCapacitanceSlot(slotId, context);
+                    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                        for (curChIndex = 0u; curChIndex < context->ptrCommonConfig->numChannels; curChIndex++)
+                        {
+                            if (((0x01uL << curChIndex) & skipChMask) == 0u)
+                            {
+                                curSlotIndex = slotId + ((curChIndex + ptrCommonCfg->channelOffset) * CY_CAPSENSE_SLOT_COUNT);
+                                if((context->ptrScanSlots[curSlotIndex].wdId != CY_CAPSENSE_SLOT_EMPTY) &&
+                                   (context->ptrScanSlots[curSlotIndex].wdId != CY_CAPSENSE_SLOT_SHIELD_ONLY))
+                                   {
+                                       Cy_CapSense_DisconnectSensor(curChIndex, context);
+                                   }
+                            }
+                        }
+                    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+                }
+                /* Clear the BUSY flag */
+                context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY;
+            }
+            else
+            {
+                result = CY_CAPSENSE_BIST_HW_BUSY_E;
+            }
+        }
+    }
+
+    return (result);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSensorEnable
+****************************************************************************//**
+*
+* The internal function sets up the MSC HW block to perform electrode
+* (sensor or shield) capacitance measuring.
+*
+* This function prepares the MSC HW block to CSD FW sensing mode
+* with BIST-defined parameters.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static cy_capsense_status_t Cy_CapSense_BistMeasureCapacitanceSensorEnable(
+                cy_stc_capsense_context_t * context)
+{
+    cy_en_msc_status_t mscStatus;
+    cy_capsense_status_t capStatus = CY_CAPSENSE_STATUS_SUCCESS;
+    uint32_t curChIndex;
+    const cy_stc_msc_base_config_t cy_capsense_BistBaseTemplate = CY_CAPSENSE_BIST_SENSING_METHOD_BASE_TEMPLATE;
+
+    /* Set the modClk divider for BIST scans */
+    Cy_CapSense_SetModClkDivider(context->ptrBistContext->eltdCapModClk, context);
+    /* Generate the MSC base configuration for BIST scan and send it to the MSC HW block */
+    for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+    {
+        mscStatus = Cy_MSC_Configure(context->ptrCommonConfig->ptrMscChConfig[curChIndex].ptrMscBase,
+                                     &cy_capsense_BistBaseTemplate, CY_MSC_CAPSENSE_KEY,
+                                     context->ptrCommonConfig->ptrMscChConfig[curChIndex].ptrMscContext);
+        if (CY_MSC_SUCCESS != mscStatus)
+        {
+            capStatus = CY_CAPSENSE_STATUS_HW_BUSY;
+            break;
+        }
+        Cy_CapSense_BistGenerateBaseConfig(curChIndex, context);
+    }
+    /* Check if all MSC channel is not busy and clear all pending interrupts */
+    if (CY_CAPSENSE_STATUS_SUCCESS == capStatus)
+    {
+        for (curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+        {
+            /* Clear all pending interrupts of the MSC HW block */
+            context->ptrCommonConfig->ptrMscChConfig[curChIndex].ptrMscBase->INTR =
+                                 CY_CAPSENSE_MSC_INTR_ALL_MSK;
+            (void)context->ptrCommonConfig->ptrMscChConfig[curChIndex].ptrMscBase->INTR;
+        }
+    }
+
+    return (capStatus);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN)
+/*******************************************************************************
+* 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 CSX
+* Rx/Tx electrode) by using CSD FW mode and defined scan configuration,
+* sense clock frequency and resolution.
+* The range for sensor measuring is 1 to 200 pF.
+* The function performs the CSD scan with the fixed CDAC value. This provides
+* a possibility of classical raw counts formula usage for the 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns a status of the test execution:
+* - CY_CAPSENSE_BIST_SUCCESS_E - The measurement is completed
+*                                successfully, the result is valid.
+* - CY_CAPSENSE_BIST_TIMEOUT_E - The scan reached the timeout. It can be caused
+*                                by a measured capacitance short or 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)
+{
+    uint64_t cp;
+    uint32_t watchdogPeriod;
+    cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_TIMEOUT_E;
+    const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig;
+    uint32_t rawCountTmp;
+    uint32_t chIndex;
+
+    /* Setup scan parameters: Ref CDAC code for Cp measurement */
+    context->ptrBistContext->eltdCapRefCdac = CY_CAPSENSE_BIST_ELTD_CAP_REF_CDAC_DEFAULT;
+    /* Perform BIST scan */
+    Cy_CapSense_BistMeasureCapacitanceSensorRun(context);
+    watchdogPeriod = Cy_CapSense_BistWatchdogPeriodCalc(context);
+    /* Wait for the end of scan and get the raw count */
+    while (((ptrCommonCfg->ptrMscChConfig[context->ptrBistContext->curBistChId].ptrMscBase->INTR &
+            MSC_INTR_MASK_SCAN_Msk) == 0u) && (0u != watchdogPeriod))
+    {
+        watchdogPeriod--;
+    }
+    if (0u != watchdogPeriod)
+    {
+        rawCountTmp =
+            ptrCommonCfg->ptrMscChConfig[context->ptrBistContext->curBistChId].ptrMscBase->RESULT_FIFO_RD;
+        result = CY_CAPSENSE_BIST_SUCCESS_E;
+    }
+    /* Clear all pending interrupts of all MSC HW blocks */
+    for (chIndex = 0u; chIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; chIndex++)
+    {
+        ptrCommonCfg->ptrMscChConfig[chIndex].ptrMscBase->INTR = CY_CAPSENSE_MSC_INTR_ALL_MSK;
+        (void)ptrCommonCfg->ptrMscChConfig[chIndex].ptrMscBase->INTR;
+    }
+    /* Check for timeout and if no, then calculate capacitance and store the value to the data structure */
+    if ((CY_CAPSENSE_BIST_TIMEOUT_E != result))
+    {
+        cp = (uint64_t)CY_CAPSENSE_BIST_CAP_MEAS_CDAC_LSB_FF_DIV_1000 * context->ptrBistContext->eltdCapRefCdac;
+        cp *= rawCountTmp;
+        cp /= CY_CAPSENSE_CONVERSION_KILO;
+        cp /= context->ptrBistContext->eltdCapSubConvNum;
+        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);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN_EN) */
+
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) || \
+    ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+     (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN)))
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSlot
+****************************************************************************//**
+*
+* This internal function measures slot sensor capacitances.
+*
+* The function measures Cp of a certain CSD sensor or shield
+* or Cm of a certain CSX sensor by using the predefined scan configuration.
+* The range for sensor measuring is 1 to 200 pF for CSD/CSX sensors and
+* 1600 pF for shield electrodes.
+* The function performs the CSD or CSX scan with fixed reference CDAC values
+* (100u and 50u respectively) and 200u for shield electrodes' capacitance
+* measurements. The function stores the Cp or Cm value
+* in the corresponding element
+* of the cy_capsense_snsCap[CY_CAPSENSE_SENSOR_COUNT] array and
+* Cshield values for each channel
+* in the corresponding element
+* of the cy_capsense_shieldCap[CY_CAPSENSE_TOTAL_CH_NUMBER] array.
+* The pointer to the first sensor capacitance value of a widget is
+* in the .ptrSnsCapacitance field of the \ref cy_stc_capsense_widget_config_t
+* structure.
+*
+* \param slotId
+* Specifies the ID number of the slot to measure sensor capacitance.
+* The slot ID should be in the admissible range.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_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_BistMeasureCapacitanceSlot(
+                uint32_t slotId,
+                cy_stc_capsense_context_t * context)
+{
+    uint64_t cp;
+    uint32_t watchdogPeriod;
+    cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_TIMEOUT_E;
+    const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig;
+    uint32_t * ptrSnsCap;
+    uint32_t rawCountTmp;
+    uint32_t chIndex;
+    uint32_t slotStcIdx;
+    uint32_t wdgtIdx;
+    uint32_t snsIdx;
+
+    /* Setup scan parameters: Ref CDAC code for shield or electrode Cp measurement */
+    if (CY_CAPSENSE_BIST_CAP_SHIELD_SCAN == context->ptrBistContext->eltdCapScanMode)
+    {
+        context->ptrBistContext->eltdCapRefCdac = CY_CAPSENSE_BIST_SHIELD_CAP_REF_CDAC_DEFAULT;
+    }
+    /* The CSD or CSX group is the same for all slot sensors, choose the group by the #0u channel */
+    else if (CY_CAPSENSE_CSX_GROUP == context->ptrActiveScanSns[0u].currentSenseMethod)
+    {
+        context->ptrBistContext->eltdCapRefCdac = CY_CAPSENSE_BIST_MUTUAL_CAP_REF_CDAC_DEFAULT;
+    }
+    else
+    {
+        context->ptrBistContext->eltdCapRefCdac = CY_CAPSENSE_BIST_ELTD_CAP_REF_CDAC_DEFAULT;
+    }
+    /* Perform BIST scan */
+    Cy_CapSense_BistMeasureCapacitanceSensorRun(context);
+    for (chIndex = 0u; chIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; chIndex++)
+    {
+        watchdogPeriod = Cy_CapSense_BistWatchdogPeriodCalc(context);
+        result = CY_CAPSENSE_BIST_TIMEOUT_E;
+        /* Wait for the end of scan and get the raw count */
+        while (((ptrCommonCfg->ptrMscChConfig[chIndex].ptrMscBase->INTR & MSC_INTR_MASK_SCAN_Msk) == 0u) &&
+                (0u != watchdogPeriod))
+        {
+            watchdogPeriod--;
+        }
+        if (0u != watchdogPeriod)
+        {
+            rawCountTmp = ptrCommonCfg->ptrMscChConfig[chIndex].ptrMscBase->RESULT_FIFO_RD;
+            result = CY_CAPSENSE_BIST_SUCCESS_E;
+        }
+        /* Clear all pending interrupts of the current MSC HW block */
+        ptrCommonCfg->ptrMscChConfig[chIndex].ptrMscBase->INTR = CY_CAPSENSE_MSC_INTR_ALL_MSK;
+        (void)ptrCommonCfg->ptrMscChConfig[chIndex].ptrMscBase->INTR;
+        /* Check for timeout and if no, then calculate capacitance and store the value to the data structure */
+        if (CY_CAPSENSE_BIST_TIMEOUT_E != result)
+        {
+            if (CY_CAPSENSE_BIST_CAP_SHIELD_SCAN != context->ptrBistContext->eltdCapScanMode)
+            {
+                /* Get the slot index in the slot structure for the current channel */
+                slotStcIdx = slotId + ((chIndex + ptrCommonCfg->channelOffset) * CY_CAPSENSE_SLOT_COUNT);
+                wdgtIdx = context->ptrScanSlots[slotStcIdx].wdId;
+            }
+            if ((0u == ((1u << (chIndex + context->ptrCommonConfig->channelOffset)) &
+                        context->ptrBistContext->skipChannelMask)) &&
+                ((CY_CAPSENSE_BIST_CAP_SHIELD_SCAN == context->ptrBistContext->eltdCapScanMode) ||
+                 (CY_CAPSENSE_SLOT_SHIELD_ONLY > wdgtIdx)))
+            {
+                cp = (uint64_t)CY_CAPSENSE_BIST_CAP_MEAS_CDAC_LSB_FF_DIV_1000 * context->ptrBistContext->eltdCapRefCdac;
+                cp *= rawCountTmp;
+                cp /= CY_CAPSENSE_CONVERSION_KILO;
+                cp /= context->ptrBistContext->eltdCapSubConvNum;
+                /* Divide the result by 2 for the FW CSX scanning method */
+                if ((CY_CAPSENSE_BIST_CAP_SHIELD_SCAN != context->ptrBistContext->eltdCapScanMode) &&
+                    (CY_CAPSENSE_CSX_GROUP == context->ptrActiveScanSns[0u].currentSenseMethod))
+                {
+                    cp /= CY_CAPSENSE_DIVIDER_TWO;
+                }
+            }
+            else
+            {
+                cp = 0u;
+            }
+            /* Store the Cp value in the appropriate structure */
+            if ((CY_CAPSENSE_BIST_CAP_SHIELD_SCAN != context->ptrBistContext->eltdCapScanMode) &&
+                (CY_CAPSENSE_SLOT_SHIELD_ONLY > wdgtIdx))
+            {
+                snsIdx = context->ptrScanSlots[slotStcIdx].snsId;
+                ptrSnsCap = &context->ptrWdConfig[wdgtIdx].ptrSnsCapacitance[snsIdx];
+                if (((uint64_t)CY_CAPSENSE_BIST_CP_MAX_VALUE) < cp)
+                {
+                    cp = (uint64_t)CY_CAPSENSE_BIST_CP_MAX_VALUE;
+                }
+                *ptrSnsCap = (uint32_t)cp;
+            }
+            else if (CY_CAPSENSE_BIST_CAP_SHIELD_SCAN == context->ptrBistContext->eltdCapScanMode)
+            {
+                ptrSnsCap = &context->ptrBistContext->ptrChShieldCap[chIndex];
+                if (((uint64_t)CY_CAPSENSE_BIST_CSH_MAX_VALUE) < cp)
+                {
+                    cp = (uint64_t)CY_CAPSENSE_BIST_CSH_MAX_VALUE;
+                }
+                *ptrSnsCap = (uint32_t)cp;
+            }
+            else
+            {
+                /* Do nothing */
+            }
+        }
+        else
+        {
+            break;
+        }
+    }
+
+    return (result);
+}
+#endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) || \
+          ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) && \
+           (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSensorRun
+****************************************************************************//**
+*
+* This internal function performs the scan initialization
+* and triggers the scan for the sensor or shield electrode capacitance measurement.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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 void Cy_CapSense_BistMeasureCapacitanceSensorRun(
+                cy_stc_capsense_context_t * context)
+{
+    const cy_stc_capsense_common_config_t * ptrCommonCfg = context->ptrCommonConfig;
+    MSC_Type * ptrMscHwBase;
+    uint32_t chIndex;
+    uint32_t sensorFrame[CY_MSC_6_SNS_REGS];
+
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+        /* Connect Cmods to the AMUX-BusA in the AMUX mode */
+        for (chIndex = 0u; chIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; chIndex++)
+        {
+            Cy_CapSense_SsConfigPinRegisters(
+            context->ptrCommonConfig->ptrMscChConfig[chIndex].portCmod1,
+            (uint32_t)context->ptrCommonConfig->ptrMscChConfig[chIndex].pinCmod1,
+            CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+
+            Cy_CapSense_SsConfigPinRegisters(
+            context->ptrCommonConfig->ptrMscChConfig[chIndex].portCmod2,
+            (uint32_t)context->ptrCommonConfig->ptrMscChConfig[chIndex].pinCmod2,
+            CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_AMUXA);
+        }
+    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+
+    /* Initiate the frame start for all channels */
+    for (chIndex = 0u; chIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; chIndex++)
+    {
+        /* Get the pointer to the MSC channel base register */
+        ptrMscHwBase = ptrCommonCfg->ptrMscChConfig[chIndex].ptrMscBase;
+        ptrMscHwBase->FRAME_CMD = MSC_FRAME_CMD_START_FRAME_Msk;
+    }
+    for (chIndex = 0u; chIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; chIndex++)
+    {
+        /* Get the pointer to the MSC channel base register */
+        ptrMscHwBase = ptrCommonCfg->ptrMscChConfig[chIndex].ptrMscBase;
+        /* Clear the sensor configuration structure */
+        (void)memset(&sensorFrame[0u], 0, sizeof(cy_stc_msc_sensor_config_t));
+        /* Get the sensor frame configuration and write it to the MSC HW block to start scan */
+        Cy_CapSense_BistGenerateSensorConfig(chIndex, &sensorFrame[0u], context);
+        Cy_MSC_ConfigureScan(ptrMscHwBase, CY_MSC_6_SNS_REGS, &sensorFrame[0u]);
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistGenerateBaseConfig
+****************************************************************************//**
+*
+* Changes the configuration for all registers that have to be changed
+* one-time to initialize the MSC block for BIST scan.
+*
+* \param chIndex
+* The channel index the base configuration is generated for.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the operation:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is performed successfully.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistGenerateBaseConfig(
+                uint32_t chIndex,
+                cy_stc_capsense_context_t * context)
+{
+    uint32_t i;
+    MSC_Type * ptrBaseCfg = context->ptrCommonConfig->ptrMscChConfig[chIndex].ptrMscBase;
+    MSC_MODE_Type * ptrBaseCfgMode;
+    const cy_stc_msc_channel_config_t * ptrMscChConfig = &context->ptrCommonConfig->ptrMscChConfig[chIndex];
+
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+        uint32_t cswFuncMode = 0uL;
+        const cy_stc_capsense_pin_config_t * ptrPinCfg = context->ptrPinConfig;
+    #endif
+
+    if((CY_CAPSENSE_MSC0_CMOD1PADD_PIN != ptrMscChConfig->pinCmod1) &&
+       (CY_CAPSENSE_MSC1_CMOD1PADD_PIN != ptrMscChConfig->pinCmod1))
+    {
+        ptrBaseCfg->SW_SEL_CMOD1 = 0u;
+        ptrBaseCfg->SW_SEL_CMOD2 = 0u;
+    }
+    else
+    {
+        ptrBaseCfg->SW_SEL_CMOD3 = 0u;
+        ptrBaseCfg->SW_SEL_CMOD4 = 0u;
+    }
+
+    /* Set the GPIO configuration for AMUX mode */
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+
+        ptrBaseCfg->SW_SEL_GPIO &= ~CY_CAPSENSE_CMOD_AMUX_MSK;
+        if ((CY_CAPSENSE_BIST_CAP_SLOT_SCAN == context->ptrBistContext->eltdCapScanMode) &&
+            (CY_CAPSENSE_CSX_GROUP == context->ptrActiveScanSns[0u].currentSenseMethod))
+        {
+            ptrBaseCfg->SW_SEL_GPIO |= CY_CAPSENSE_FW_CMOD_AMUX_CSX_REG_SW_SEL_GPIO_VALUE;
+        }
+        else
+        {
+            ptrBaseCfg->SW_SEL_GPIO |= CY_CAPSENSE_FW_CMOD_AMUX_CSD_REG_SW_SEL_GPIO_VALUE;
+        }
+
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+            /* The shield signal generation for BIST scans in AMUX mode */
+            if (CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->intrEltdCapCsdISC)
+            {
+                if (CY_CAPSENSE_SHIELD_ACTIVE == context->ptrCommonConfig->csdShieldMode)
+                {
+                    ptrBaseCfg->SW_SEL_GPIO |= CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_CSD_SHIELD_VALUE;
+                }
+                else if (CY_CAPSENSE_SHIELD_PASSIVE == context->ptrCommonConfig->csdShieldMode)
+                {
+                    ptrBaseCfg->SW_SEL_GPIO |= CY_CAPSENSE_FW_SHIELD_PASSIVE_AMUX_REG_SW_CSD_SHIELD_VALUE;
+                }
+                else
+                {
+                    /* Do nothing */
+                }
+            }
+        #endif
+    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+
+    /*
+     * MODE CONFIGURATION
+     * For the BIST electrode capacitance measurement the CSD FW is used, the mode #0)
+     * For the BIST slot sensor capacitance measurement the CSD FW (the mode #0) and CSX FW (the mode #1) are used
+     */
+    for (i = 0u; i < CY_CAPSENSE_BIST_SENSE_MODE_CONFIG_NUMBER; i++)
+    {
+        ptrBaseCfg->MODE[i].SW_SEL_SH &= (~MSC_MODE_SW_SEL_SH_C1SHG_Msk);
+        ptrBaseCfg->MODE[i].SW_SEL_SH &= (~MSC_MODE_SW_SEL_SH_C3SHG_Msk);
+
+        if((CY_CAPSENSE_MSC0_CMOD1PADD_PIN == ptrMscChConfig->pinCmod1) ||
+           (CY_CAPSENSE_MSC1_CMOD1PADD_PIN == ptrMscChConfig->pinCmod1))
+        {
+            ptrBaseCfg->MODE[i].SW_SEL_COMP |= MSC_MODE_SW_SEL_COMP_CPCS1_Msk;
+            ptrBaseCfg->MODE[i].SW_SEL_COMP |= MSC_MODE_SW_SEL_COMP_CMCS2_Msk;
+            ptrBaseCfg->MODE[i].SW_SEL_SH |= MSC_MODE_SW_SEL_SH_C1SHG_Msk;
+        }
+        else
+        {
+            ptrBaseCfg->MODE[i].SW_SEL_COMP |= MSC_MODE_SW_SEL_COMP_CPCS3_Msk;
+            ptrBaseCfg->MODE[i].SW_SEL_COMP |= MSC_MODE_SW_SEL_COMP_CMCS4_Msk;
+            ptrBaseCfg->MODE[i].SW_SEL_SH |= MSC_MODE_SW_SEL_SH_C3SHG_Msk;
+        }
+    }
+
+    /* Shielding is available in CSD only */
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) &&\
+         (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN))
+        /*
+         * PINS CONFIGURATION for the CTRL-MUX mode
+         */
+        #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+            ptrBaseCfg->SW_SEL_CSW_FUNC[CY_CAPSENSE_CTRLMUX_PIN_STATE_SHIELD] = CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_CSW_VALUE;
+            if (CY_CAPSENSE_SHIELD_PASSIVE == context->ptrCommonConfig->csdShieldMode)
+            {
+                ptrBaseCfg->SW_SEL_CSW_FUNC[CY_CAPSENSE_CTRLMUX_PIN_STATE_SHIELD] = CY_CAPSENSE_FW_SHIELD_PASSIVE_CTRLMUX_REG_SW_SEL_CSW_VALUE;
+            }
+        #endif
+
+        if(CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->currentISC)
+        {
+            ptrBaseCfgMode = &ptrBaseCfg->MODE[0u];
+            ptrBaseCfgMode->SENSE_DUTY_CTL &= ~(MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Msk |
+                                              MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Msk);
+            /* Active Shield mode */
+            if (CY_CAPSENSE_SHIELD_ACTIVE == context->ptrCommonConfig->csdShieldMode)
+            {
+                #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+                    ptrBaseCfgMode->SW_SEL_TOP &= ~CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_TOP_MASK;
+                    ptrBaseCfgMode->SW_SEL_SH  &= ~CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_SH_MASK;
+                    ptrBaseCfgMode->SW_SEL_TOP |= CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_TOP_VALUE;
+                    ptrBaseCfgMode->SW_SEL_SH  |= CY_CAPSENSE_FW_SHIELD_ACTIVE_CTRLMUX_REG_SW_SEL_SH_VALUE;
+                #else /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+                    /* Amux sensor_connection_method */
+                    ptrBaseCfgMode->SW_SEL_TOP &= ~CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_TOP_MASK;
+                    ptrBaseCfgMode->SW_SEL_SH  &= ~CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_SH_MASK;
+                    ptrBaseCfgMode->SW_SEL_TOP |= CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_TOP_VALUE;
+                    ptrBaseCfgMode->SW_SEL_SH  |= CY_CAPSENSE_FW_SHIELD_ACTIVE_AMUX_REG_SW_SEL_SH_VALUE;
+                #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+            }
+            /* Passive Shield mode */
+            else
+            {
+                #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+                    ptrBaseCfgMode->SW_SEL_TOP &= ~CY_CAPSENSE_FW_SHIELD_PASSIVE_CTRLMUX_REG_SW_SEL_TOP_MASK;
+                    ptrBaseCfgMode->SW_SEL_TOP |= CY_CAPSENSE_FW_SHIELD_PASSIVE_CTRLMUX_REG_SW_SEL_TOP_VALUE;
+                    ptrBaseCfgMode->SENSE_DUTY_CTL |= ((1u << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH0_EN_Pos) |
+                                                     (1u << MSC_MODE_SENSE_DUTY_CTL_PHASE_GAP_FS2_PH1_EN_Pos));
+                #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+            }
+        }
+    #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) &&\
+               (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+    /* For CSX mode (#1u) swSelTop values should be generated */
+    ptrBaseCfgMode = &ptrBaseCfg->MODE[1u];
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+        ptrBaseCfgMode->SW_SEL_TOP = CY_CAPSENSE_CSX_FW_AMUX_MODE_SW_SEL_TOP_VALUE;
+    #else /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+        ptrBaseCfgMode->SW_SEL_TOP = CY_CAPSENSE_CSX_FW_CTLMUX_MODE_SW_SEL_TOP_VALUE;
+    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+
+    /* Generating the common configuration for the control mux switch control */
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+        for (i = 0u; i < context->ptrCommonConfig->numPin; i++)
+        {
+            if ((chIndex + context->ptrCommonConfig->channelOffset) == ptrPinCfg->chId)
+            {
+                cswFuncMode |= (0x01uL << ptrPinCfg->padNumber);
+            }
+            ptrPinCfg++;
+        }
+        #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) &&\
+             (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN))
+            ptrPinCfg = context->ptrShieldPinConfig;
+            for (i = 0u; i < context->ptrCommonConfig->csdShieldNumPin; i++)
+            {
+                if ((chIndex + context->ptrCommonConfig->channelOffset) == ptrPinCfg->chId)
+                {
+                    cswFuncMode |= 0x01uL << ptrPinCfg->padNumber;
+                }
+                ptrPinCfg++;
+            }
+        #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) &&\
+                   (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)) */
+        ptrBaseCfg->CSW_CTL = cswFuncMode;
+    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+    /* Check for modClk divider value */
+    if (1u == context->ptrBistContext->eltdCapModClk)
+    {
+        ptrBaseCfg->CTL |= MSC_CTL_CLK_MSC_RATIO_Msk;
+    }
+    else
+    {
+        ptrBaseCfg->CTL &= ~MSC_CTL_CLK_MSC_RATIO_Msk;
+    }
+    /* Generating the multi-channel mode for each channel with updating the sensor control registers */
+    if (0u != context->ptrCommonConfig->syncMode)
+    {
+        ptrBaseCfg->SNS_CTL = ((uint32_t)context->ptrCommonConfig->syncMode << MSC_SNS_CTL_MULTI_CH_MODE_Pos);
+    }
+    /* Generating the common configuration for the BIST epilogue cycle number */
+    if (0u < context->ptrBistContext->eltdCapNumEpiCycles)
+    {
+        ptrBaseCfg->SCAN_CTL2 |= (uint32_t)context->ptrBistContext->eltdCapNumEpiCycles <<
+                                                                    MSC_SCAN_CTL2_NUM_EPI_CYCLES_Pos;
+    }
+    else
+    {
+        ptrBaseCfg->SCAN_CTL2 |= (uint32_t)(1uL << MSC_SCAN_CTL2_NUM_EPI_CYCLES_Pos);
+    }
+    /* Generating the common configuration for the coarse initialization and coarse short phase */
+    if((CY_CAPSENSE_MSC0_CMOD1PADD_PIN == ptrMscChConfig->pinCmod1) ||
+       (CY_CAPSENSE_MSC1_CMOD1PADD_PIN == ptrMscChConfig->pinCmod1))
+    {
+        ptrBaseCfg->INIT_CTL1 |= (uint32_t)context->ptrBistContext->eltdCapNumCoarseInitChargeCycles <<
+                                                                    MSC_INIT_CTL1_NUM_INIT_CMOD_12_RAIL_CYCLES_Pos;
+        ptrBaseCfg->INIT_CTL1 |= (uint32_t)context->ptrBistContext->eltdCapNumCoarseInitSettleCycles <<
+                                                                    MSC_INIT_CTL1_NUM_INIT_CMOD_12_SHORT_CYCLES_Pos;
+        ptrBaseCfg->INIT_CTL3 |= CY_CAPSENSE_CMOD12_PAIR_SELECTION << MSC_INIT_CTL3_CMOD_SEL_Pos;
+    }
+    else
+    {
+        ptrBaseCfg->INIT_CTL2 |= (uint32_t)context->ptrBistContext->eltdCapNumCoarseInitChargeCycles <<
+                                                                    MSC_INIT_CTL2_NUM_INIT_CMOD_34_RAIL_CYCLES_Pos;
+        ptrBaseCfg->INIT_CTL2 |= (uint32_t)context->ptrBistContext->eltdCapNumCoarseInitSettleCycles <<
+                                                                    MSC_INIT_CTL2_NUM_INIT_CMOD_34_SHORT_CYCLES_Pos;
+        ptrBaseCfg->INIT_CTL3 |= (uint32_t)CY_CAPSENSE_CMOD34_PAIR_SELECTION << MSC_INIT_CTL3_CMOD_SEL_Pos;
+    }
+    /*
+     * Generating the common configuration for the number of sub-conversions to be run during the PRO_DUMMY phase and
+     * the modClk period number during the PRO_WAIT phase.
+     */
+    ptrBaseCfg->INIT_CTL4 |= (((uint32_t)context->ptrBistContext->eltdCapNumFineInitCycles <<
+                                                                  MSC_INIT_CTL4_NUM_PRO_DUMMY_SUB_CONVS_Pos) |
+                              ((uint32_t)context->ptrBistContext->eltdCapNumFineInitWaitCycles <<
+                                                                  MSC_INIT_CTL4_NUM_PRO_WAIT_CYCLES_Pos));
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistGenerateSensorConfig
+****************************************************************************//**
+*
+* Generates the configuration for registers that have to be configured to start
+* a scan for a single sensor. It is used the next sensor configuration for BIST
+* scan:
+* - CIC2 filter is off
+* - is used mode structure 0u
+* - Multi-channel mode is off
+* - System level chopping is off
+* - Coarse Init Bypass is off
+*
+* \param chIndex
+* The channel index the sensor configuration is generated for.
+*
+* \param ptrSensorCfg
+* Specifies the pointer to the sensor configuration to be filled.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the status of the operation:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is performed successfully.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistGenerateSensorConfig(
+                uint32_t chIndex,
+                uint32_t * ptrSensorCfg,
+                cy_stc_capsense_context_t * context)
+{
+    uint16_t snsClkDividerVal;
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+        uint32_t i;
+        const cy_stc_capsense_electrode_config_t * ptrEltdCfg;
+        uint32_t padMask = 0u;
+        uint32_t cswFuncNum;
+        uint32_t slotStcWdgtIdx = context->ptrScanSlots[context->ptrBistContext->curBistSlotId +
+                ((chIndex + context->ptrCommonConfig->channelOffset) * CY_CAPSENSE_SLOT_COUNT)].wdId;
+    #else
+        (void) chIndex;
+    #endif
+
+    /* Set the synchronization mode */
+    if (0u != context->ptrCommonConfig->syncMode)
+    {
+        ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] = ((uint32_t)context->ptrCommonConfig->syncMode << MSC_SNS_CTL_MULTI_CH_MODE_Pos);
+    }
+    /* Getting the BIST sense clock divider */
+    snsClkDividerVal = context->ptrBistContext->eltdCapSnsClk;
+    if (CY_CAPSENSE_BIST_CAP_SHIELD_SCAN == context->ptrBistContext->eltdCapScanMode)
+    {
+        snsClkDividerVal = CY_CAPSENSE_BIST_SHIELD_CAP_SNSCLK_DIV_DEFAULT;
+    }
+    if (snsClkDividerVal > 0u)
+    {
+        snsClkDividerVal -= 1u;
+    }
+    /* Set snsClk and Valid, Start scan, and Last slot bits */
+    ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] |= ((((uint32_t)snsClkDividerVal) << MSC_SNS_CTL_SENSE_DIV_Pos) |
+                                                MSC_SNS_CTL_VALID_Msk |
+                                                MSC_SNS_CTL_START_SCAN_Msk |
+                                                MSC_SNS_CTL_LAST_Msk);
+    /*
+     * Set the sense mode selection.
+     * For the electrode capacitance measurement only the CSD mode is used (SENSE_MODE_SEL = 0u).
+     * For the slot sensor capacitance measurement the CSD mode can be used (SENSE_MODE_SEL = 0u) and
+     * the CSX mode can be used (SENSE_MODE_SEL = 1u) depending on the measured slot.
+     */
+    if ((CY_CAPSENSE_BIST_CAP_SLOT_SCAN == context->ptrBistContext->eltdCapScanMode) &&
+        (CY_CAPSENSE_CSX_GROUP == context->ptrActiveScanSns[0u].currentSenseMethod))
+    {
+        ptrSensorCfg[CY_CAPSENSE_SNS_CTL_INDEX] |= (1u << MSC_SNS_CTL_SENSE_MODE_SEL_Pos);
+    }
+    /*
+     * CapDAC configuration: CapDAC dithering is off for BIST,
+     * only the reference CDAC is used for BIST scans.
+     */
+    ptrSensorCfg[CY_CAPSENSE_SNS_CDAC_CTL_INDEX] =
+                (((uint32_t)context->ptrBistContext->eltdCapRefCdac) << MSC_SNS_CDAC_CTL_SEL_RE_Pos) |
+                MSC_SNS_CDAC_CTL_CLOCK_REF_RATE_Msk;
+    /* Compensation CDAC Divider set to BIST Sns clock divider */
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= (((uint32_t)snsClkDividerVal) << MSC_SNS_SCAN_CTL_COMP_DIV_Pos);
+    /* Number of sub-conversions */
+    ptrSensorCfg[CY_CAPSENSE_SNS_SCAN_CTL_INDEX] |= ((uint32_t)context->ptrBistContext->eltdCapSubConvNum - 1u) << MSC_SNS_SCAN_CTL_NUM_SUB_CONVS_Pos;
+
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+        /* Get mask for all channel pins */
+        padMask = context->ptrCommonConfig->ptrMscChConfig[chIndex].ptrMscBase->CSW_CTL;
+        /* Change the control switch function depending on the current inactive sensor connection */
+        cswFuncNum = CY_CAPSENSE_CTRLMUX_PIN_STATE_GND;
+        if (CY_CAPSENSE_BIST_IO_HIGHZA_E == context->ptrBistContext->currentISC)
+        {
+            cswFuncNum = CY_CAPSENSE_CTRLMUX_PIN_STATE_HIGH_Z;
+        }
+        else if (CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->currentISC)
+        {
+            cswFuncNum = CY_CAPSENSE_CTRLMUX_PIN_STATE_SHIELD;
+        }
+        else
+        {
+            /* Do nothing */
+        }
+        /* Set the control mux switch registers for inactive pins */
+        Cy_CapSense_CalculateMaskRegisters(padMask, cswFuncNum, ptrSensorCfg);
+        /* Check for active electrodes */
+        if (0u == ((1u << (chIndex + context->ptrCommonConfig->channelOffset)) &
+                    context->ptrBistContext->skipChannelMask))
+        {
+            if ((CY_CAPSENSE_BIST_CAP_ELTD_SCAN == context->ptrBistContext->eltdCapScanMode) ||
+                (CY_CAPSENSE_BIST_CAP_SHIELD_SCAN == context->ptrBistContext->eltdCapScanMode) ||
+                ((CY_CAPSENSE_BIST_CAP_SLOT_SCAN == context->ptrBistContext->eltdCapScanMode) &&
+                 ((CY_CAPSENSE_SLOT_EMPTY != slotStcWdgtIdx) && (CY_CAPSENSE_SLOT_SHIELD_ONLY != slotStcWdgtIdx))))
+            {
+                /* Initializes an active sensor (including ganged sensors) by SNS sensor state */
+                if (CY_CAPSENSE_BIST_CAP_SHIELD_SCAN == context->ptrBistContext->eltdCapScanMode)
+                {
+                    /* Generate CTRL_MUX masks for the electrode or CSD sensor connection */
+                    cswFuncNum = CY_CAPSENSE_CTRLMUX_PIN_STATE_SNS;
+                    if (CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->currentISC)
+                    {
+                        padMask = context->ptrCommonConfig->ptrMscChConfig[chIndex].ptrMscBase->CSW_CTL;
+                    }
+                    else
+                    {
+                        padMask = 0u;
+                        for (i = 0u; i < context->ptrCommonConfig->csdShieldNumPin; i++)
+                        {
+                            /* Proceed only if the shield electrode is connected belongs to the current channel */
+                            if ((chIndex + context->ptrCommonConfig->channelOffset) == context->ptrShieldPinConfig[i].chId)
+                            {
+                                padMask |= 0x01uL << context->ptrShieldPinConfig[i].padNumber;
+                            }
+                        }
+                    }
+                    Cy_CapSense_CalculateMaskRegisters(padMask, cswFuncNum, ptrSensorCfg);
+                }
+                else
+                {
+                    if ((CY_CAPSENSE_BIST_CAP_ELTD_SCAN == context->ptrBistContext->eltdCapScanMode) ||
+                        (CY_CAPSENSE_CSD_GROUP == context->ptrActiveScanSns[0u].currentSenseMethod))
+                    {
+                        /* Generate CTRL_MUX masks for the electrode or CSD sensor connection */
+                        if (CY_CAPSENSE_BIST_CAP_ELTD_SCAN == context->ptrBistContext->eltdCapScanMode)
+                        {
+                            ptrEltdCfg = context->ptrBistContext->curPtrEltdCfg;
+                        }
+                        else
+                        {
+                            ptrEltdCfg = context->ptrActiveScanSns[chIndex].ptrEltdConfig;
+                        }
+                        cswFuncNum = CY_CAPSENSE_CTRLMUX_PIN_STATE_SNS;
+                        /* Proceed only if electrode configuration belongs to selected channel */
+                        if ((chIndex + context->ptrCommonConfig->channelOffset) == ptrEltdCfg->chId)
+                        {
+                            Cy_CapSense_BistGenerateSnsCfgMaskReg(ptrEltdCfg, ptrSensorCfg, cswFuncNum);
+                        }
+                    }
+                    else
+                    {
+                        /* RX ELECTRODE */
+                        if (CY_CAPSENSE_SLOT_SHIELD_ONLY > slotStcWdgtIdx)
+                        {
+                            cswFuncNum = CY_CAPSENSE_CTRLMUX_PIN_STATE_RX;
+                            ptrEltdCfg = context->ptrActiveScanSns[chIndex].ptrRxConfig;
+                            if ((chIndex + context->ptrCommonConfig->channelOffset) == ptrEltdCfg->chId)
+                            {
+                                Cy_CapSense_BistGenerateSnsCfgMaskReg(ptrEltdCfg, ptrSensorCfg, cswFuncNum);
+                            }
+                        }
+                        /* TX ELECTRODE */
+                        cswFuncNum = CY_CAPSENSE_CTRLMUX_PIN_STATE_TX;
+                        ptrEltdCfg = context->ptrActiveScanSns[chIndex].ptrTxConfig;
+                        if ((chIndex + context->ptrCommonConfig->channelOffset) == ptrEltdCfg->chId)
+                        {
+                            Cy_CapSense_BistGenerateSnsCfgMaskReg(ptrEltdCfg, ptrSensorCfg, cswFuncNum);
+                        }
+                    }
+                }
+            }
+        }
+    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+}
+
+#if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD)
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistGenerateSnsCfgMaskReg
+****************************************************************************//**
+*
+* Calculates the configuration for all sensor configuration mask registers that
+* have to be changed to set the desired CTRL-MUX function
+* for the specified electrode for BIST scan.
+*
+* \param ptrEltdCfg
+* The pointer to the specified electrode configuration
+* \ref cy_stc_capsense_electrode_config_t structure.
+*
+* \param ptrSensorCfg
+* Specifies the pointer to the sensor configuration to be filled.
+*
+* \param cswFuncNum
+* The desired CTRL-MUX Switch Control Global function.
+*
+* \return
+* Returns the status of the operation:
+* - CY_CAPSENSE_STATUS_SUCCESS       - The operation is performed successfully.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistGenerateSnsCfgMaskReg(
+                const cy_stc_capsense_electrode_config_t * ptrEltdCfg,
+                uint32_t * ptrSensorCfg,
+                uint32_t cswFuncNum)
+{
+    uint32_t padMask = 0u;
+    uint32_t i;
+
+    /* Loop through all pads for this electrode (ganged sensor) */
+    for (i = 0u; i < ptrEltdCfg->numPins; i++)
+    {
+        padMask |= 0x01uL << ptrEltdCfg->ptrPin[i].padNumber;
+    }
+    Cy_CapSense_CalculateMaskRegisters(padMask, cswFuncNum, ptrSensorCfg);
+}
+#endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN) */
+
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) &&\
+        (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))
+/*******************************************************************************
+* Function Name: Cy_CapSense_MeasureCapacitanceShieldElectrode
+****************************************************************************//**
+*
+* Measures shield electrode capacitances in femtofarads.
+*
+* This function measures the capacitances of all shield electrodes for all
+* enabled MSCv3 channels and returns a status of this measurement.
+* The function checks if there is any CSD widget in the project and
+* if the shield is enabled.
+* The measurement results in femtofarads are stored
+* in the chShieldCap[CY_MSC_ENABLED_CH_NUMBER] array.
+* The pointer to the array is in the .ptrChShieldCap field
+* of the \ref cy_stc_capsense_bist_context_t structure,
+* the CY_MSC_ENABLED_CH_NUMBER define is in the cycfg_peripherals.h file.
+* If the any channel shield consists of several electrodes, the total
+* capacitance of all the shield electrodes is measured.
+*
+* This function uses an algorithm identical to the electrode capacitance
+* measurement. Refer to the Cy_CapSense_MeasureCapacitanceSensorElectrode()
+* function for more details.
+*
+* In addition to measuring shield capacitance, this function is used to
+* identify various fault conditions with shield electrodes such as an
+* electrically-open or -short shield electrodes, e.g. the PCB track is broken or
+* shorted to other nodes in the system - in all of these conditions,
+* this function returns changed capacitance that can be compared
+* against pre-determined capacitance for the shield electrode to
+* detect a hardware fault.
+*
+* By default, all CAPSENSE&trade; sensors (electrodes) that are not being
+* measured are set to the GND state.
+* The inactive state can be changed in run-time by using
+* the Cy_CapSense_SetInactiveElectrodeState() function.
+* When the inactive sensor (electrode) connection is set
+* to the CY_CAPSENSE_SNS_CONNECTION_SHIELD state,
+* all the CAPSENSE&trade; electrodes are connected to the shield and
+* the total capacitance are measured.
+*
+* By default, the both Cmod1 and Cmod2 capacitors are used for the measurement.
+*
+* This test can be executed using the CapSense_RunSelfTest()
+* function with the CY_CAPSENSE_BIST_SHIELD_CAP_MASK mask.
+*
+* \note
+* This function is available only for the fifth-generation CAPSENSE&trade;.
+*
+* \param skipChMask
+* Specifies the mask to skip some channels during the shield electrode
+* capacitance measurement. If the bit N in the skipChMask is set to 1,
+* the channel N will be excluded from measuring and all its shield pins will be
+* set to the shield inactive sensor connection state (see the .shieldCapISC
+* field of the \ref cy_stc_capsense_bist_context_t structure).
+*
+* \param context
+* The pointer to the CAPSENSE&trade; 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_BAD_CONFIG_E       - The shield is disabled.
+*
+*******************************************************************************/
+cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceShieldElectrode(
+                uint32_t skipChMask,
+                cy_stc_capsense_context_t * context)
+{
+    cy_en_capsense_bist_status_t result = CY_CAPSENSE_BIST_BAD_PARAM_E;
+
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+        uint32_t pinIndex;
+        const cy_stc_capsense_pin_config_t * ptrPinCfg;
+    #endif
+
+    if(NULL != context)
+    {
+    #if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) &&\
+         (CY_CAPSENSE_DISABLE != CY_CAPSENSE_CSD_SHIELD_EN))
+        if ((0u < context->ptrCommonConfig->csdShieldNumPin) ||
+            (CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->intrEltdCapShieldISC))
+        {
+            context->ptrBistContext->currentISC = context->ptrBistContext->intrEltdCapShieldISC;
+            if (CY_CAPSENSE_NOT_BUSY == Cy_CapSense_IsBusy(context))
+            {
+                /* Set the BUSY status */
+                context->ptrCommonContext->status = CY_CAPSENSE_BUSY | CY_CAPSENSE_MW_STATE_BIST_MASK;
+                (void)Cy_CapSense_SwitchHwConfiguration(CY_CAPSENSE_HW_CONFIG_BIST_FUNCTIONALITY, context);
+                /* Store the current slot and the skip channel mask for the BIST scan */
+                context->ptrBistContext->curBistSlotId = 0u;
+                context->ptrBistContext->skipChannelMask = (uint8_t)skipChMask;
+                /* Switch the HW resource configuration to the electrode capacitance measurement */
+                Cy_CapSense_BistSwitchHwConfig(CY_CAPSENSE_BIST_HW_ELTD_CAP_E,
+                                               CY_CAPSENSE_CSD_GROUP,
+                                               CY_CAPSENSE_BIST_CAP_SHIELD_SCAN,
+                                               context);
+                #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                    /* Connect all shield pins as sensors for CSD BIST scan */
+                    if (0u < context->ptrCommonConfig->csdShieldNumPin)
+                    {
+                        ptrPinCfg = context->ptrShieldPinConfig;
+                        for (pinIndex = 0u; pinIndex < context->ptrCommonConfig->csdShieldNumPin; pinIndex++)
+                        {
+                            if (((0x01uL << ptrPinCfg->chId) & skipChMask) == 0u)
+                            {
+                                Cy_CapSense_SsConfigPinRegisters(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber,
+                                                                 CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_CSD_SENSE);
+                            }
+                            ptrPinCfg++;
+                        }
+                    }
+                    if (CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->currentISC)
+                    {
+                        /* Connect all sensor pins for CSD BIST scan */
+                        ptrPinCfg = context->ptrPinConfig;
+                        for (pinIndex = 0u; pinIndex < context->ptrCommonConfig->numPin; pinIndex++)
+                        {
+                            if (((0x01uL << ptrPinCfg->chId) & skipChMask) == 0u)
+                            {
+                                Cy_CapSense_SsConfigPinRegisters(ptrPinCfg->pcPtr, (uint32_t)ptrPinCfg->pinNumber,
+                                                                 CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_CSD_SENSE);
+                            }
+                            ptrPinCfg++;
+                        }
+                    }
+                #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+                /* Perform the CSD BIST slot scan with connected all channel shields as active electrodes */
+                result = Cy_CapSense_BistMeasureCapacitanceSlot(0u, context);
+                #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                    /* Disconnect all shield pins by setting them to the current BIST ISC */
+                    if (0u < context->ptrCommonConfig->csdShieldNumPin)
+                    {
+                        ptrPinCfg = context->ptrShieldPinConfig;
+                        for (pinIndex = 0u; pinIndex < context->ptrCommonConfig->csdShieldNumPin; pinIndex++)
+                        {
+                            if (((0x01uL << ptrPinCfg->chId) & skipChMask) == 0u)
+                            {
+                                Cy_CapSense_SsConfigPinRegisters(ptrPinCfg->pcPtr,
+                                                                 (uint32_t)ptrPinCfg->pinNumber,
+                                                                 context->ptrBistContext->eltdInactiveDm,
+                                                                 context->ptrBistContext->eltdInactiveHsiom);
+                            }
+                            ptrPinCfg++;
+                        }
+                    }
+                    if (CY_CAPSENSE_BIST_IO_SHIELD_E == context->ptrBistContext->currentISC)
+                    {
+                        /* Disconnect all sensor pins by setting them to the current BIST ISC */
+                        ptrPinCfg = context->ptrPinConfig;
+                        for (pinIndex = 0u; pinIndex < context->ptrCommonConfig->numPin; pinIndex++)
+                        {
+                            if (((0x01uL << ptrPinCfg->chId) & skipChMask) == 0u)
+                            {
+                                Cy_CapSense_SsConfigPinRegisters(ptrPinCfg->pcPtr,
+                                                                 (uint32_t)ptrPinCfg->pinNumber,
+                                                                 context->ptrBistContext->eltdInactiveDm,
+                                                                 context->ptrBistContext->eltdInactiveHsiom);
+                            }
+                            ptrPinCfg++;
+                        }
+                    }
+                #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+                /* Clear the BUSY flag */
+                context->ptrCommonContext->status = CY_CAPSENSE_NOT_BUSY;
+            }
+            else
+            {
+                result = CY_CAPSENSE_BIST_HW_BUSY_E;
+            }
+        }
+    #endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) &&\
+               (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)) */
+    }
+
+    return (result);
+}
+#endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) &&\
+           (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN)) */
+
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN) && \
+     (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD))
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistConnectEltd
+****************************************************************************//**
+*
+* Connects a specified electrode as CSD sensor to the BIST active MSC HW block.
+*
+* The function connects all the electrode pins including ganged.
+* The BIST active MSC HW block is specified
+* in the \ref cy_stc_capsense_bist_context_t structure.
+*
+* \param ptrEltdConfig
+* The pointer to the specified electrode configuration
+* \ref cy_stc_capsense_electrode_config_t structure.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistConnectEltd(
+                const cy_stc_capsense_electrode_config_t * ptrEltdConfig,
+                const cy_stc_capsense_context_t * context)
+{
+    const cy_stc_capsense_pin_config_t * ptrActivePin = ptrEltdConfig->ptrPin;
+    uint32_t i;
+
+    if((context->ptrBistContext->curBistChId + context->ptrCommonConfig->channelOffset) == ptrEltdConfig->chId)
+    {
+        /* Connect all pins of current sensors */
+        for(i = 0u; i < ptrEltdConfig->numPins; i++)
+        {
+            Cy_CapSense_SsConfigPinRegisters(ptrActivePin->pcPtr, (uint32_t)ptrActivePin->pinNumber,
+                    CY_CAPSENSE_DM_GPIO_ANALOG, CY_CAPSENSE_HSIOM_SEL_CSD_SENSE);
+            ptrActivePin++;
+        }
+    }
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDisconnectEltd
+****************************************************************************//**
+*
+* The function disconnects all the electrode pins including ganged.
+* The BIST active MSC HW block is specified
+* in the \ref cy_stc_capsense_bist_context_t structure.
+*
+* \param ptrEltdConfig
+* The pointer to the specified electrode configuration
+* \ref cy_stc_capsense_electrode_config_t structure.
+*
+* \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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistDisconnectEltd(
+                const cy_stc_capsense_electrode_config_t * ptrEltdConfig,
+                cy_en_capsense_bist_io_state_t desiredPinState,
+                const cy_stc_capsense_context_t * context)
+{
+    const cy_stc_capsense_pin_config_t * ptrActivePin = ptrEltdConfig->ptrPin;
+    uint32_t i;
+    uint32_t desiredDriveMode = CY_CAPSENSE_DM_GPIO_ANALOG;
+    en_hsiom_sel_t desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+
+    if((context->ptrBistContext->curBistChId + context->ptrCommonConfig->channelOffset) == ptrEltdConfig->chId)
+    {
+        /* Change Drive mode and HSIOM depending on the current inactive sensor connection */
+        if (CY_CAPSENSE_BIST_IO_STRONG_E == desiredPinState)
+        {
+            desiredDriveMode = CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+            desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+        }
+        else if (CY_CAPSENSE_BIST_IO_HIGHZA_E == desiredPinState)
+        {
+            /* Do nothing */
+        }
+        else if (CY_CAPSENSE_BIST_IO_SHIELD_E == desiredPinState)
+        {
+            desiredDriveMode = CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+            desiredHsiom = CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD;
+        }
+        else
+        {
+            /* Do nothing */
+        }
+        /* Disconnect all pins of the current sensor */
+        for(i = 0u; i < ptrEltdConfig->numPins; i++)
+        {
+            Cy_CapSense_SsConfigPinRegisters(ptrActivePin->pcPtr, (uint32_t)ptrActivePin->pinNumber,
+                                             desiredDriveMode, desiredHsiom);
+            Cy_GPIO_Clr(ptrActivePin->pcPtr, (uint32_t)ptrActivePin->pinNumber);
+            ptrActivePin++;
+        }
+    }
+}
+#endif /* ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN) && \
+           (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)) */
+
+
+/*******************************************************************************
+* 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&trade; 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;
+    context->ptrBistContext->eltdCapSenseGroup = CY_CAPSENSE_UNDEFINED_GROUP;
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDsInitialize_V3
+****************************************************************************//**
+*
+* 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&trade; start and performs
+* the \ref cy_stc_capsense_bist_context_t structure initialization 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()
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistDsInitialize_V3(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++)
+    {
+        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+            Cy_CapSense_UpdateCrcWidget(wdIndex, context);
+        #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)) */
+        context->ptrWdContext[wdIndex].status |= (uint8_t)CY_CAPSENSE_WD_WORKING_MASK;
+    }
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN)
+        Cy_CapSense_BistMeasureCapacitanceSensorInit(context);
+    #endif
+
+    context->ptrBistContext->hwConfig = CY_CAPSENSE_BIST_HW_UNDEFINED_E;
+    context->ptrBistContext->currentISC = CY_CAPSENSE_BIST_IO_UNDEFINED_E;
+    context->ptrBistContext->eltdCapSenseGroup = CY_CAPSENSE_UNDEFINED_GROUP;
+    context->ptrBistContext->intrEltdCapCsdISC = context->ptrBistContext->eltdCapCsdISC;
+    context->ptrBistContext->intrEltdCapCsxISC = context->ptrBistContext->eltdCapCsxISC;
+    context->ptrBistContext->intrEltdCapShieldISC = context->ptrBistContext->shieldCapISC;
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistDisableMode
+****************************************************************************//**
+*
+* This internal function releases HW resources and pins captured by BIST
+* to be used by other CAPSENSE&trade; modes.
+*
+* This function releases the shared HW resources like connection
+* to the analog bus in the AMUX mode.
+* The function does not configure HW block registers to the default state.
+* It is used by the Cy_CapSense_SwitchHwConfiguration() function only at switching
+* to another sensing mode.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistDisableMode(cy_stc_capsense_context_t * context)
+{
+    Cy_CapSense_BistSwitchAllSnsPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        Cy_CapSense_BistSwitchAllShieldPinState(CY_CAPSENSE_BIST_IO_STRONG_E, context);
+    #endif
+    Cy_CapSense_BistSwitchAllExternalCapPinState(CY_CAPSENSE_BIST_IO_STRONG_E, 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 MSCv3 HW block configuration for
+* BIST operations.
+*
+* The function checks the current MSCv3 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 bistSenseGroup
+* Specifies the sense group to be scanned during the sensor or electrode
+* capacitance measurement scan.
+* The parameter does not matter for short tests.
+*
+* \param bistScanMode
+* Specifies the scanning mode (by electrodes or by slots) during the sensor
+* or electrode capacitance measurement scan.
+* The parameter does not matter for short tests.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistSwitchHwConfig(
+                cy_en_capsense_bist_hw_config_t hwCfg,
+                uint8_t bistSenseGroup,
+                uint8_t bistScanMode,
+                cy_stc_capsense_context_t * context)
+{
+    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) || (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+        uint32_t curChIndex;
+    #endif
+
+    if ((context->ptrBistContext->hwConfig != hwCfg) ||
+        (context->ptrBistContext->eltdCapSenseGroup != bistSenseGroup) ||
+        (context->ptrBistContext->eltdCapScanMode != bistScanMode))
+    {
+        context->ptrBistContext->hwConfig = hwCfg;
+        context->ptrBistContext->eltdCapSenseGroup = bistSenseGroup;
+        context->ptrBistContext->eltdCapScanMode = bistScanMode;
+        /* Enable the specified mode */
+        switch(hwCfg)
+        {
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+                case CY_CAPSENSE_BIST_HW_SHORT_E:
+                {
+                    /* Configure all the MSC channels to perform pin integrity tests */
+                    for(curChIndex = 0u; curChIndex < CY_CAPSENSE_TOTAL_CH_NUMBER; curChIndex++)
+                    {
+                        context->ptrCommonConfig->ptrMscChConfig[curChIndex].ptrMscBase->CSW_CTL = 0x00u;
+                    }
+                    break;
+                }
+            #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+            #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN)
+                case CY_CAPSENSE_BIST_HW_ELTD_CAP_E:
+                {
+                    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                        Cy_CapSense_BistSwitchAllSnsPinState(context->ptrBistContext->currentISC, context);
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                            Cy_CapSense_BistSwitchAllShieldPinState(context->ptrBistContext->currentISC, context);
+                        #endif
+                    #else /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+                        Cy_CapSense_SetIOsInDefaultState(context);
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                            Cy_CapSense_SetShieldPinsInDefaultState(context);
+                        #endif
+                        for (curChIndex = 0u; curChIndex < context->ptrCommonConfig->numChannels; curChIndex++)
+                        {
+                            Cy_CapSense_SetCmodInDefaultState(curChIndex, context);
+                        }
+                    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+
+                    (void)Cy_CapSense_BistMeasureCapacitanceSensorEnable(context);
+                    break;
+                }
+                case CY_CAPSENSE_BIST_HW_ELTD_CAP_SH_E:
+                {
+                    #if (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD)
+                        Cy_CapSense_BistSwitchAllSnsPinState(context->ptrBistContext->intrEltdCapShieldISC, context);
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                            Cy_CapSense_BistSwitchAllShieldPinState(context->ptrBistContext->intrEltdCapShieldISC, context);
+                        #endif
+                    #else /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_CTRLMUX_SENSOR_CONNECTION_METHOD) */
+                        Cy_CapSense_SetIOsInDefaultState(context);
+                        #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+                            Cy_CapSense_SetShieldPinsInDefaultState(context);
+                        #endif
+                        for (curChIndex = 0u; curChIndex < context->ptrCommonConfig->numChannels; curChIndex++)
+                        {
+                            Cy_CapSense_SetCmodInDefaultState(curChIndex, context);
+                        }
+                    #endif /* (CY_CAPSENSE_SENSOR_CONNECTION_MODE == CY_CAPSENSE_AMUX_SENSOR_CONNECTION_METHOD) */
+
+                    (void)Cy_CapSense_BistMeasureCapacitanceSensorEnable(context);
+
+                    break;
+                }
+            #endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN) */
+
+            default:
+            {
+                /* Nothing to do */
+                break;
+            }
+        }
+    }
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistMeasureCapacitanceSensorInit
+****************************************************************************//**
+*
+* This internal function calculates the parameters for sensor, shield or
+* electrode capacitance measurements.
+*
+* It is called by Cy_CapSense_BistDsInitialize() once at the CAPSENSE&trade; MW start.
+*
+* The following parameters of cy_stc_capsense_bist_context_t are used as
+* an input for the calculation:
+* * .eltdCapModClk
+* * .eltdCapSnsClk
+*
+* 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
+* * .eltdCapSubConvNum
+*
+* Restarting CAPSENSE&trade; MW or calling of the Cy_CapSense_BistDsInitialize()
+* function overwrites the output parameters.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+void Cy_CapSense_BistMeasureCapacitanceSensorInit(
+                cy_stc_capsense_context_t * context)
+{
+    cy_stc_capsense_bist_context_t * ptrBistCxt = context->ptrBistContext;
+
+    /* ModClk */
+    if (0u == ptrBistCxt->eltdCapModClk)
+    {
+        ptrBistCxt->eltdCapModClk = (uint16_t)CY_CAPSENSE_BIST_ELTD_CAP_MODCLK_DIV_DEFAULT;
+    }
+    if (CY_CAPSENSE_BIST_ELTD_CAP_MAX_MODCLK < (context->ptrCommonConfig->periClkHz / ptrBistCxt->eltdCapModClk))
+    {
+        ptrBistCxt->eltdCapModClk <<= 1u;
+    }
+
+    /* SnsClk */
+    if (0u == ptrBistCxt->eltdCapSnsClk)
+    {
+        ptrBistCxt->eltdCapSnsClk = (uint16_t)CY_CAPSENSE_BIST_ELTD_CAP_SNSCLK_DIV_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;
+    }
+    /* NumSubConv */
+    ptrBistCxt->eltdCapSubConvNum = (uint16_t)CY_CAPSENSE_BIST_ELTD_CAP_SUBCONV_NUM_DEFAULT;
+    /* NumEpiCycles and NumProWaitCycles depends on SnsClk divider */
+    ptrBistCxt->eltdCapNumEpiCycles = ptrBistCxt->eltdCapSnsClk / CY_CAPSENSE_DIVIDER_TWO;
+    ptrBistCxt->eltdCapNumFineInitWaitCycles = ptrBistCxt->eltdCapNumEpiCycles;
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+/*******************************************************************************
+* 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&trade; 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 desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+
+    Cy_CapSense_BistSetDmHsiomPinState(desiredPinState, context);
+    if (CY_CAPSENSE_BIST_IO_STRONG_HIGH_E == desiredPinState)
+    {
+        desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2VDD;
+    }
+    Cy_CapSense_BistSetAllSnsPinsState(context->ptrBistContext->eltdInactiveDm, desiredPinOutput,
+                                       context->ptrBistContext->eltdInactiveHsiom, context);
+}
+
+
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistSetDmHsiomPinState
+****************************************************************************//**
+*
+* This internal function changes the port control (PC) and HSIOM
+* register values needed to set pins to the desired state.
+*
+* The function changes the .eltdInactiveDm and .eltdInactiveHsiom field values
+* of the \ref cy_stc_capsense_bist_context_t structure on ones needed to set
+* pins to the desired pin state (Drive Mode 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&trade; context structure \ref cy_stc_capsense_context_t.
+*
+*******************************************************************************/
+static void Cy_CapSense_BistSetDmHsiomPinState(
+                cy_en_capsense_bist_io_state_t desiredPinState,
+                const cy_stc_capsense_context_t * context)
+{
+    context->ptrBistContext->eltdInactiveDm = CY_CAPSENSE_DM_GPIO_ANALOG;
+    context->ptrBistContext->eltdInactiveHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+
+    /* Change Drive mode and HSIOM depending on the current inactive sensor connection */
+    if ((CY_CAPSENSE_BIST_IO_STRONG_E == desiredPinState) ||
+        (CY_CAPSENSE_BIST_IO_STRONG_HIGH_E == desiredPinState))
+    {
+        context->ptrBistContext->eltdInactiveDm = CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+    }
+
+    #if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+        if (CY_CAPSENSE_BIST_IO_SHIELD_E == desiredPinState)
+        {
+            context->ptrBistContext->eltdInactiveHsiom = CY_CAPSENSE_HSIOM_SEL_CSD_SHIELD;
+            if (CY_CAPSENSE_SHIELD_PASSIVE == context->ptrCommonConfig->csdShieldMode)
+            {
+                context->ptrBistContext->eltdInactiveDm = CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+            }
+        }
+    #endif
+}
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN)
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN)
+/*******************************************************************************
+* 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&trade; 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 desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+
+    if (0u < context->ptrCommonConfig->csdShieldNumPin)
+    {
+        Cy_CapSense_BistSetDmHsiomPinState(desiredPinState, context);
+        if (CY_CAPSENSE_BIST_IO_STRONG_HIGH_E == desiredPinState)
+        {
+            desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2VDD;
+        }
+        Cy_CapSense_BistSetAllShieldPinsState(context->ptrBistContext->eltdInactiveDm, desiredPinOutput,
+                                              context->ptrBistContext->eltdInactiveHsiom, context);
+    }
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) */
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_EN) */
+
+
+/*******************************************************************************
+* 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&trade; 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)
+{
+    uint32_t desiredDriveMode = CY_CAPSENSE_DM_GPIO_ANALOG;
+    en_hsiom_sel_t desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+    uint32_t desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+
+    /* Change Drive mode and HSIOM depending on the current inactive sensor connection */
+    if (CY_CAPSENSE_BIST_IO_STRONG_E == desiredPinState)
+    {
+        desiredDriveMode = CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+        desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+        desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2GND;
+    }
+    else if (CY_CAPSENSE_BIST_IO_STRONG_HIGH_E == desiredPinState)
+    {
+        desiredDriveMode = CY_CAPSENSE_DM_GPIO_STRONG_IN_OFF;
+        desiredHsiom = CY_CAPSENSE_HSIOM_SEL_GPIO;
+        desiredPinOutput = CY_CAPSENSE_BIST_DR_PIN2VDD;
+    }
+    else
+    {
+        /* Do nothing */
+    }
+    Cy_CapSense_BistSetAllCmodPinsState(desiredDriveMode, desiredPinOutput, desiredHsiom, context);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN) */
+
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN)
+/*******************************************************************************
+* Function Name: Cy_CapSense_BistWatchdogPeriodCalc
+****************************************************************************//**
+*
+* The internal function calculates the watch-dog period for BIST sensor
+* capacity measurement scans in CPU cycles.
+*
+* \param context
+* The pointer to the CAPSENSE&trade; context structure \ref cy_stc_capsense_context_t.
+*
+* \return
+* Returns the calculated watch-dog period for BIST sensor capacity measurement
+* scans in CPU cycles:
+*******************************************************************************/
+static uint32_t Cy_CapSense_BistWatchdogPeriodCalc(
+                const cy_stc_capsense_context_t * context)
+{
+    uint64_t isBusyWatchdogTimeUs;
+    uint32_t modClkDivider;
+    uint32_t watchdogPeriod;
+
+    modClkDivider = context->ptrBistContext->eltdCapModClk;
+    if(0u == modClkDivider)
+    {
+        modClkDivider = 1u;
+    }
+
+    isBusyWatchdogTimeUs  = ((uint64_t)context->ptrBistContext->eltdCapSnsClk) *
+                            ((uint64_t)context->ptrBistContext->eltdCapSubConvNum);
+    isBusyWatchdogTimeUs *= (uint64_t)modClkDivider * CY_CAPSENSE_CONVERSION_MEGA;
+    isBusyWatchdogTimeUs /= context->ptrCommonConfig->periClkHz;
+    if(0u == isBusyWatchdogTimeUs)
+    {
+        isBusyWatchdogTimeUs = 1u;
+    }
+    isBusyWatchdogTimeUs *= CY_CAPSENSE_BIST_WATCHDOG_MARGIN_COEFF;
+    watchdogPeriod = Cy_CapSense_WatchdogCyclesNum((uint32_t)isBusyWatchdogTimeUs,
+                                                   context->ptrCommonConfig->cpuClkHz / CY_CAPSENSE_CONVERSION_MEGA,
+                                                   CY_CAPSENSE_BIST_CAP_MEAS_WDT_CYCLES_PER_LOOP);
+    return (watchdogPeriod);
+}
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN) */
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) */
+
+#endif /* (defined(CY_IP_M0S8MSCV3)) */
+
+
+/* [] END OF FILE */

+ 145 - 0
project_0/libraries/IFX_PSOC6_HAL/capsense/cy_capsense_selftest_v3.h

@@ -0,0 +1,145 @@
+/***************************************************************************//**
+* \file cy_capsense_selftest.h
+* \version 3.0
+*
+* \brief
+* This file provides the function prototypes of the BIST module.
+*
+********************************************************************************
+* \copyright
+* Copyright 2021, Cypress Semiconductor Corporation (an Infineon company)
+* or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
+* You may use this file only in accordance with the license, terms, conditions,
+* disclaimers, and limitations in the end user license agreement accompanying
+* the software package with which this file was provided.
+*******************************************************************************/
+
+
+#if !defined(CY_CAPSENSE_SELFTEST_V3_H)
+#define CY_CAPSENSE_SELFTEST_V3_H
+
+#include "cy_syslib.h"
+#include "cycfg_capsense_defines.h"
+#include "cy_capsense_common.h"
+#include "cy_capsense_structure.h"
+
+#if (defined(CY_IP_M0S8MSCV3))
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN)
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/*******************************************************************************
+* Function Prototypes
+*******************************************************************************/
+
+
+/******************************************************************************/
+/** \addtogroup group_capsense_low_level *//** \{ */
+/******************************************************************************/
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSensorElectrode(
+                    uint32_t widgetId,
+                    uint32_t eltdId,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_ELTD_CAP_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceSlotSensors(
+                    uint32_t slotId,
+                    uint32_t skipChMask,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_CAP_EN) */
+
+#if ((CY_CAPSENSE_ENABLE == CY_CAPSENSE_CSD_SHIELD_EN) &&\
+     (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SH_CAP_EN))
+    cy_en_capsense_bist_status_t Cy_CapSense_MeasureCapacitanceShieldElectrode(
+                    uint32_t skipChMask,
+                    cy_stc_capsense_context_t * context);
+#endif
+
+/** \} */
+
+/******************************************************************************/
+/** \cond SECTION_CAPSENSE_INTERNAL */
+/** \addtogroup group_capsense_internal *//** \{ */
+/******************************************************************************/
+
+cy_en_capsense_bist_status_t Cy_CapSense_RunSelfTest_V3(
+                uint32_t testEnMask,
+                cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_CheckCRCWidget_V3(
+                    uint32_t widgetId,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorRawcount_V3(
+                    uint32_t widgetId,
+                    uint32_t sensorId,
+                    uint16_t rawcountHighLimit,
+                    uint16_t rawcountLowLimit,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_RAW_INTEGRITY_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorBaseline_V3(
+                    uint32_t widgetId,
+                    uint32_t sensorId,
+                    uint16_t baselineHighLimit,
+                    uint16_t baselineLowLimit,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_BSLN_INTEGRITY_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN)
+    cy_en_capsense_bist_status_t Cy_CapSense_CheckIntegritySensorPins_V3(
+                    uint32_t widgetId,
+                    uint32_t sensorId,
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_SNS_SHORT_EN) */
+
+void Cy_CapSense_BistInitialize(
+                cy_stc_capsense_context_t * context);
+void Cy_CapSense_BistDsInitialize_V3(
+                cy_stc_capsense_context_t * context);
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_HW_GROUP_EN)
+    void Cy_CapSense_BistDisableMode(
+                    cy_stc_capsense_context_t * context);
+#endif
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN)
+    void Cy_CapSense_BistMeasureCapacitanceSensorInit(
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_MEASUREMENT_GROUP_EN) */
+
+#if (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN)
+    void Cy_CapSense_UpdateCrcWidget(
+                    uint32_t widgetId,
+                    cy_stc_capsense_context_t * context);
+    void Cy_CapSense_UpdateAllWidgetCrc(
+                    cy_stc_capsense_context_t * context);
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_TST_WDGT_CRC_EN) */
+
+
+/** \} \endcond */
+
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* (CY_CAPSENSE_ENABLE == CY_CAPSENSE_BIST_EN) */
+
+#endif /* (defined(CY_IP_M0S8MSCV3)) */
+
+#endif /* CY_CAPSENSE_SELFTEST_V3_H */
+
+
+/* [] END OF FILE */

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio