/***************************************************************************//**
* \file cy_capsense.h
* \version 3.0
*
* \brief
* This file includes all the header files of the CAPSENSE™ 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™ Middleware Library 3.0
********************************************************************************
*
* 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, and automotive, IoT, and industrial applications. CAPSENSE™
* supports multiple interfaces (widgets) using both CSX and CSD 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
*
********************************************************************************
* \section section_capsense_general General Description
********************************************************************************
*
* The CAPSENSE™ middleware Library supports operation with fourth-generation and
* fifth-generation of CAPSENSE™ HW. CAPSENSE™ HW enables multiple sensing
* capabilities on PSoC™ 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™ HW block through the corresponding
* peripheral Driver:
* - CSD (CAPSENSE™ Sigma-Delta) driver for the forth-generation of the
* CAPSENSE™ HW;
* - MSC (Multi-Sensor Converter) driver for the fifth-generation of the
* CAPSENSE™ HW;
*
* The CAPSENSE™ peripheral driver does not provide any system-level functions.
* It only implements the interface to the CAPSENSE™ HW resource.
*
* The supported CAPSENSE™ HW blocks can perform only one function at a time.
* However, all supported functionality (like CAPSENSE™, CSDADC, etc.) can be
* time-multiplexed in a design. I.e. you can save the existing state of
* the CAPSENSE™ middleware, restore the state of the the CSDADC middleware, perform
* CSDADC measurements, and then switch back to the CAPSENSE™ 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™ Solution" width=800px
* \image latex capsense_solution.png
*
* This section describes only the CAPSENSE™ middleware. Refer to the corresponding
* sections of documentation for other middleware supported by the CAPSENSE™ HW.
*
* A CAPSENSE™ solution includes:
* * The CAPSENSE™ Configurator to create
* and configure CAPSENSE™ widgets. It can be launched in ModusToolbox™
* from the CAPSENSE™ 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™ 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™ CAPSENSE™ 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™ 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™ is using code examples.
* Infineon Technologies continuously extends their portfolio of code examples
* at the Infineon Technologies
* and at the
* Infineon Technologies GitHub. The following are the links
* to code examples for different PSoC™ families presented on GitHub.
*
* \subsection group_capsense_quick_start_psoc4_csd_ces Code Examples for PSoC™ 4 Devices with fourth-generation CAPSENSE™
*
* *
* CSD Button Manual Tuning
*
* *
* CSX Button Manual Tuning
*
* *
* CSD Slider Manual Tuning
*
* \subsection group_capsense_quick_start_psoc4_msc_ces Code Examples for PSoC™ 4 Devices with fifth-generation CAPSENSE™
*
* *
* CSD Button Manual Tuning
*
* *
* CSX Button Manual Tuning
*
* *
* CSD Slider Manual Tuning
*
* *
* CSD Touchpad Manual Tuning
*
* *
* CSX Touchpad Manual Tuning
*
* \subsection group_capsense_quick_start_psoc6_csd_ces Code Examples for PSoC™ 6 Devices with fourth-generation CAPSENSE™
*
* *
* Two Buttons and Slider with CAPSENSE™ Tuner
*
* *
* Low-Power Slider and Ganged Sensors with FreeRTOS
*
* *
* Custom Scan
*
* *
* BLE Client for CAPSENSE™ Tuning
*
* *
* BLE Server for CAPSENSE™ Tuning
*
* The CAPSENSE™ middleware can be used in various development environments
* such as ModusToolbox™, 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™ Configuration Considerations
*
* This quick start guide assumes that the environment is configured:
* * The
* CAT1 Peripheral Driver Library (PDL) is included in the project
* in case if the PSoC™ 6 device is used.
* * The
* CAT2 Peripheral Driver Library (PDL) is included in the project
* in case if the PSoC™ 4 device is used.
* *
* ModusToolbox™ Device Configurator Tool,
*
* ModusToolbox™ CAPSENSE™ Configurator Tool, and
*
* ModusToolbox™ CAPSENSE™ Tuner Tool
* are installed on the machine.
*
* \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
* Cypress Semiconductor GitHub:
* *
* CAPSENSE™ buttons and slider for PSoC™ 6 MCU with Mbed OS
*
* 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™ 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™
* 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™ middleware. The CAPSENSE™ 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™ middleware was validated for compatibility
* with the following Software and Tools:
*
*
* Rule ID |
* Rule Description |
* Description of Deviation(s) |
*
*
* Directive 4.8 |
* If a pointer to a structure or union is never dereferenced within a translation
* unit, then the implementation of the object should be hidden.
* |
* 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.
* |
*
*
* Rule 2.3 |
* A project should not contain unused type declarations.
* |
* Advisory. The middleware library provides API to the hardware. The type
* is part of API, which is defined for application-level only.
* |
*
*
* Rule 2.5 |
* A project should not contain unused macro declarations.
* |
* Advisory. The middleware library provides API to the hardware. The macro
* is part of API, which is defined for application-level only.
* |
*
*
* Rule 5.1 |
* External identifiers shall be distinct.
* |
* Toolchains from Supported Software and Tools documentation section
* are verified to work with functions, names of which have similar first 31 symbols.
* |
*
*
* Rule 5.4 |
* Macro identifiers shall be distinct.
* |
* Toolchains from Supported Software and Tools documentation section
* are verified to work with macros, names of which have similar first 31 symbols.
* |
*
*
* Rule 5.6 |
* A typedef name shall be a unique identifier.
* |
* 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.
* |
*
*
* Rule 5.8 |
* Identifiers that define objects or functions with external linkage shall be unique.
* |
* 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.
* |
*
*
* Rule 5.9 |
* Identifiers that define objects or functions with internal linkage should be unique.
* |
* 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.
* |
*
*
* Rule 8.3 |
* All declarations of an object or function shall use the same names and type qualifiers.
* |
* 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.
* |
*
*
* Rule 8.5 |
* An external object or function shall be declared once in one and only one file.
* |
* 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.
* |
*
*
* Rule 8.6 |
* An identifier with external linkage shall have exactly one external definition.
* |
* 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.
* |
*
*
* Rule 8.7 |
* Functions and objects should not be defined with external linkage if they
* are referenced in only one translation unit.
* |
* 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.
* |
*
*
* Rule 8.13 |
* A pointer should point to const-qualified type whenever possible.
* |
* 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.
* |
*
*
* Rule 11.5 |
* A conversion should not be performed from pointer to void into pointer to object.
* |
* 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.
* |
*
*
* Rule 14.2 |
* A for loop shall be well-formed.
* |
* The third clause of the for loop is empty to improve execution time.
* |
*
*
* Rule 18.4 |
* The +, -, += and -= operators should not be applied to an expression of pointer type.
* |
* Advisory. There are several instances of pointer arithmetic in drivers. They cannot be avoided,
* so are manually checked and reviewed to be safe.
* |
*
*
*
* \subsection subsection_capsense_misra-cfg CAPSENSE™ Configurator Generated Sources Deviation
*
*
* Version | Changes | Reason for Change |
*
* 3.0 |
*
* 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™ middleware v3.0.
*
* Also, if you use the CAPSENSE™ middleware v3.0 version then
* you must use the CAPSENSE™ Configurator v4.0 tool or later.
* This MW version is not compatible with the previous Configurator tool
* versions.
* |
*
*
*
* Added fifth-generation CAPSENSE™ 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
* |
* New CAPSENSE™ MSC platform covering |
*
*
* The following rows show changes related to fourth-generation CAPSENSE™ |
*
*
* Removed usage of deprecated return error and status codes,
* cy_status enum was replaced with the cy_capsense_status_t variable |
* Defect fixing |
*
*
* Removed usage of deprecated types, such as uint32 and uint16 |
* Defect fixing |
*
*
* Changed the default IDAC gain index for the CSX auto-calibration to the configured one |
* Defect fixing |
*
*
* 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()
* |
* User experience improvement |
*
*
* For fourth-generation CAPSENSE™ devices callbacks were moved from ptrCommonContext
* to ptrInternalContext structure |
* User experience improvement |
*
*
* Updated the description of the Cy_CapSense_RunSelfTest() function |
* Documentation defect fixing |
*
*
* Specified measurement units in the following function descriptions:
* * Cy_CapSense_MeasureCapacitanceSensor()
* * Cy_CapSense_MeasureCapacitanceShield()
* * Cy_CapSense_MeasureCapacitanceCap()
* |
* Documentation defect fixing |
*
* Added call of the Cy_CapSense_Wakeup() function to the registered
* callback in the Cy_CapSense_DeepSleepCallback() function |
* Improved robustness of a sensing module |
*
*
* Added a possibility to enable / disable independent features of
* BIST module |
* Expanded flexibility |
*
*
* 2.10 |
* Added Built-in Self-test (BIST) library |
* Support Class B (IEC-60730), safety integrity-level compliant design |
*
*
* Improved the Csh and Cmod coarse initialization functionality. |
* Feature enhancement |
*
*
* Improved the shield performance when Csh is enabled |
* Feature enhancement |
*
*
* Fixed Cy_CapSense_ScanExt() operation |
* Defect fixing |
*
*
* Fixed the bug in the Cy_CapSense_SetPinState() function |
* Defect fixing |
*
*
* Optimized software watch-dog values used in monitoring CAPSENSE™
* scanning duration |
* User experience improvement |
*
*
* Improved IDAC auto-calibration |
* Operation accuracy increasing |
*
*
* Added the following functions:
* * Cy_CapSense_GetParam()
* * Cy_CapSense_SetParam()
* * Cy_CapSense_GetCRC()
* |
* Feature enhancement |
*
*
* Changed the type of context argument to const in the following
* functions:
* * Cy_CapSense_CSDConnectSns()
* * Cy_CapSense_CSXConnectRx()
* * Cy_CapSense_CSXConnectTx()
* * Cy_CapSense_CSXDisconnectRx()
* * Cy_CapSense_CSXDisconnectTx()
* * Cy_CapSense_SetPinState()
* |
* Defect fixing |
*
*
* 2.0 |
* Added memory usage section to the CAPSENSE™ API Ref Guide |
* User experience improvement |
*
*
* Updated documentation |
* User experience improvement |
*
*
* Added the errata section to the CAPSENSE™ API Ref Guide |
* User experience improvement |
*
*
* CAPSENSE™ MW sources are enclosed with the conditional compilation to
* ensure a successful compilation for non-CAPSENSE™-capable devices |
* Fixing a compilation error for non CAPSENSE™-capable devices |
*
*
* Optimized flash memory consumption based on user's configuration |
* Flash foot-print optimization |
*
*
* Renamed function Cy_CapSense_CheckCommandIntegrity() to
* Cy_CapSense_CheckTunerCmdIntegrity() |
* User experience improvement |
*
*
* 1.20 |
* Added Arm Compiler 6 support |
* Feature enhancement |
*
*
* Changed the hierarchy of the binary files folders |
* MBED OS compatibility |
*
*
* 1.1 |
*
* 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()
* |
* User experience improvement |
*
*
* Fixed the shield operation when Csh is disabled |
* Defect fixing |
*
*
* Fixed the implementation of the position filtering for the Radial Slider widget |
* Defect fixing |
*
*
* Added restoring hardware to its default state in the Cy_CapSense_DeInit() implementation |
* Defect fixing |
*
*
* Added the capability to enable the shield electrode without dedicated electrodes |
* Feature enhancement |
*
*
* Added support of a protocol-agnostic tuner interface (UART, SPI, etc.) |
* Feature enhancement |
*
*
* 1.0 |
*
* The initial version
* |
* |
*
*
*
********************************************************************************
* \section section_capsense_more_information More Information
********************************************************************************
*
* Important information about the CAPSENSE™-technology overview, appropriate
* CYPRESS™ device from Infineon for the design, CAPSENSE™ system and sensor
* design guidelines, different interfaces and tuning guidelines necessary
* for a successful design of a CAPSENSE™ system is available in the Getting
* Started with CAPSENSE™ document and the product-specific CAPSENSE™ design guide.
* CYPRESS™ highly recommends starting with these documents. They can be
* found on the CYPRESS™ web site at www.cypress.com.
*
* For more information, refer to the following documents:
*
* * CAPSENSE™ Overview:
*
* *
*
* # |
* Callback Name |
* Associated Register |
* Callback Function Prototype |
* Description |
*
*
* 1 |
* Start Sample |
* ptrSSCallback |
* \ref cy_capsense_callback_t |
* 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™ 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. |
*
*
* 2 |
* End Of Scan |
* ptrEOSCallback |
* \ref cy_capsense_callback_t |
* This is called after sensor scan completion and there is no other
* sensor in the queue to be scanned.
* For the fifth-generation CAPSENSE™ in CS-DMA mode this callback is called
* with NULL passed as a parameter. |
*
*
* 3 |
* Tuner Send Callback |
* ptrTunerSendCallback |
* \ref cy_capsense_tuner_send_callback_t |
* This is called by the Cy_CapSense_RunTuner() function to establish
* synchronous communication with the Tuner tool. |
*
*
* 4 |
* Tuner Receive Callback |
* ptrTunerReceiveCallback |
* \ref cy_capsense_tuner_receive_callback_t |
* This is called by the Cy_CapSense_RunTuner() function to establish
* synchronous communication with the Tuner tool. |
*
*
* 5 |
* CAPSENSE™ Data Structure Initialization Callback |
* ptrEODsInitCallback |
* \ref cy_capsense_ds_init_callback_t |
* This is called by the Cy_CapSense_Enable() function after CAPSENSE™
* 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™
* default configuration). The callback is available for Fifth
* Generation CAPSENSE™ devices. |
*
*
*
* \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™ Data Structure field after call of
* the Cy_CapSense_Init() function as follows:
* *
*