High-level functions represent the highest abstraction layer of the CAPSENSE™ 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. The only exception is the functions for low power widget scanning, they are available only for the fifth-generation low power CAPSENSE™.
All the tasks required to implement a sensing system can be fulfilled by the high-level functions. But, there is a set of Low-level Functions 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.
Functions | |
cy_capsense_status_t | Cy_CapSense_Init (cy_stc_capsense_context_t *context) |
Captures HW blocks (one or more) for CAPSENSE™ operations and configures them to the default state. More... | |
cy_capsense_status_t | Cy_CapSense_DeInit (cy_stc_capsense_context_t *context) |
Stops the middleware operation and releases the CAPSENSE™ captured HW blocks. More... | |
cy_capsense_status_t | Cy_CapSense_Enable (cy_stc_capsense_context_t *context) |
Initializes the CAPSENSE™ firmware modules. More... | |
cy_capsense_status_t | Cy_CapSense_Save (cy_stc_capsense_context_t *context) |
Saves the state of CAPSENSE™ so the functionality can be restored using the Cy_CapSense_Restore() function. More... | |
cy_capsense_status_t | Cy_CapSense_Restore (cy_stc_capsense_context_t *context) |
Resumes the middleware operation if the Cy_CapSense_Save() function was called previously. More... | |
cy_capsense_status_t | Cy_CapSense_ProcessAllWidgets (cy_stc_capsense_context_t *context) |
Performs full data processing of all enabled widgets. More... | |
cy_capsense_status_t | Cy_CapSense_ProcessWidget (uint32_t widgetId, cy_stc_capsense_context_t *context) |
Performs full data processing of the specified widget if it is enabled. More... | |
void | Cy_CapSense_IncrementGestureTimestamp (cy_stc_capsense_context_t *context) |
Increments the timestamp register for the predefined timestamp interval. More... | |
void | Cy_CapSense_SetGestureTimestamp (uint32_t value, cy_stc_capsense_context_t *context) |
Rewrites the timestamp register by the specified value. More... | |
void | Cy_CapSense_Wakeup (const cy_stc_capsense_context_t *context) |
Resumes the middleware after System Deep Sleep. More... | |
cy_en_syspm_status_t | Cy_CapSense_DeepSleepCallback (cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode) |
Handles CPU active to System Deep Sleep power mode transition for the CAPSENSE™ middleware. More... | |
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) |
Registers a ures's callback function. More... | |
cy_capsense_status_t | Cy_CapSense_UnRegisterCallback (cy_en_capsense_callback_event_t callbackType, cy_stc_capsense_context_t *context) |
This function unregisters a previously registered user's callback function in the CAPSENSE™ middleware. More... | |
uint32_t | Cy_CapSense_DecodeWidgetGestures (uint32_t widgetId, const cy_stc_capsense_context_t *context) |
Performs decoding of all gestures for the specified widget. More... | |
cy_en_capsense_bist_status_t | Cy_CapSense_RunSelfTest (uint32_t testEnMask, cy_stc_capsense_context_t *context) |
Runs built-in self-tests specified by the test enable mask. More... | |
cy_capsense_status_t | Cy_CapSense_ScanAllSlots (cy_stc_capsense_context_t *context) |
Initiates the non-blocking scan of all Active slots and then exits. More... | |
cy_capsense_status_t | Cy_CapSense_ScanSlots (uint32_t startSlotId, uint32_t numberSlots, cy_stc_capsense_context_t *context) |
Initiates the non-blocking scan of a specified regular slots set named "frame" and then exits. More... | |
cy_capsense_mw_state_t | Cy_CapSense_MwState (const cy_stc_capsense_context_t *context) |
Returns a detailed state of the CAPSENSE™ middleware and MSC and MSCLP HW blocks in Single- or Multi-channel mode. More... | |
cy_capsense_status_t | Cy_CapSense_ScanAllWidgets (cy_stc_capsense_context_t *context) |
Initiates scanning of all enabled widgets (and sensors) in the project. More... | |
cy_capsense_status_t | Cy_CapSense_ScanWidget (uint32_t widgetId, cy_stc_capsense_context_t *context) |
Performs the initialization required to scan the specified widget and triggers the scanning of all sensors in the widget. More... | |
uint32_t | Cy_CapSense_IsBusy (const cy_stc_capsense_context_t *context) |
This function returns a status whether MW executes HW scanning at a particular moment. More... | |
void | Cy_CapSense_InterruptHandler (void *base, cy_stc_capsense_context_t *context) |
Implements interrupt service routine for CAPSENSE™ middleware. More... | |
cy_capsense_status_t | Cy_CapSense_ScanLpSlots (uint32_t startLpSlotId, uint32_t numberLpSlots, cy_stc_capsense_context_t *context) |
Initiates a non-blocking scan for specified low power slots and exits. More... | |
cy_capsense_status_t | Cy_CapSense_ScanAllLpSlots (cy_stc_capsense_context_t *context) |
Initiates a non-blocking scan of all low power slots and then exits. More... | |
cy_capsense_status_t | Cy_CapSense_ScanAllLpWidgets (cy_stc_capsense_context_t *context) |
Initiates a non-blocking scan for all low power widgets/sensors. More... | |
cy_capsense_status_t | Cy_CapSense_ConfigureMsclpWotTimer (uint32_t wakeupTimer, cy_stc_capsense_context_t *context) |
Configures the wakeup timer value for Wake-On-Touch mode. More... | |
cy_capsense_status_t | Cy_CapSense_ConfigureMsclpTimer (uint32_t wakeupTimer, cy_stc_capsense_context_t *context) |
Configures the wakeup timer value for Active mode. More... | |
cy_capsense_status_t | Cy_CapSense_IloCompensate (cy_stc_capsense_context_t *context) |
Measures the actual ILO frequency and calculates the compensation factor for MSCLP Active and Wake-On-Touch mode timers. More... | |
cy_capsense_status_t | Cy_CapSense_SetupWidget (uint32_t widgetId, cy_stc_capsense_context_t *context) |
Performs the initialization required to scan the specified widget. More... | |
cy_capsense_status_t | Cy_CapSense_Scan (cy_stc_capsense_context_t *context) |
Initiates scanning of all the sensors in the widget initialized by Cy_CapSense_SetupWidget(), if no scan is in progress. More... | |
uint32_t | Cy_CapSense_IsAnyWidgetActive (const cy_stc_capsense_context_t *context) |
Reports whether any widget has detected touch. More... | |
uint32_t | Cy_CapSense_IsAnyLpWidgetActive (const cy_stc_capsense_context_t *context) |
Reports whether any low power widget has detected a touch at the previous low power scan. More... | |
uint32_t | Cy_CapSense_IsWidgetActive (uint32_t widgetId, const cy_stc_capsense_context_t *context) |
Reports whether the specified widget detected touch on any of its sensors. More... | |
uint32_t | Cy_CapSense_IsSensorActive (uint32_t widgetId, uint32_t sensorId, const cy_stc_capsense_context_t *context) |
Reports whether the specified sensor in the widget is sensor detects a touch. More... | |
uint32_t | Cy_CapSense_IsProximitySensorActive (uint32_t widgetId, uint32_t sensorId, const cy_stc_capsense_context_t *context) |
Reports the status of the specified proximity widget/sensor. More... | |
cy_stc_capsense_touch_t * | Cy_CapSense_GetTouchInfo (uint32_t widgetId, const cy_stc_capsense_context_t *context) |
Reports the details of touch position detected on the specified touchpad, matrix buttons or slider widgets. More... | |
uint32_t | Cy_CapSense_RunTuner (cy_stc_capsense_context_t *context) |
Establishes synchronized operation between the CAPSENSE™ Middleware and the CAPSENSE™ Tuner tool. More... | |
uint32_t | Cy_CapSense_CheckTunerCmdIntegrity (const uint8_t *commandPacket) |
Checks command format, header, tail, CRC, etc. More... | |
cy_capsense_status_t Cy_CapSense_Init | ( | cy_stc_capsense_context_t * | context | ) |
Captures HW blocks (one or more) for CAPSENSE™ operations and configures them to the default state.
Call this function with the application program prior to calling any other function of the middleware.
The following tasks are executed:
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.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t generated by the CAPSENSE™ Configurator tool. The structure contains both, CAPSENSE™ configuration and internal data and it is used during whole CAPSENSE™ operation. |
The 'cy_capsense_context' variable that is used as the parameter of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions is declared in the cycfg_capsense.h file.
The CapSense_ISR_cfg variable should be declared by the application program according to the examples below:
For PSoC™ 4 CPU or for PSoC™ 6 CM0+ core:
For CM4 core:
The CAPSENSE™ interrupt handler should be declared by the application program according to the example below:
The CapSense_HW is the pointer to the base register address of the CAPSENSE™ HW block. A macro for the pointer is in the cycfg_peripherals.h file defined as <Personality_Name>_HW. If no name is specified, the following default names are used:
cy_capsense_status_t Cy_CapSense_DeInit | ( | cy_stc_capsense_context_t * | context | ) |
Stops the middleware operation and releases the CAPSENSE™ captured HW blocks.
No sensor scanning can be executed when the middleware is stopped. This function should be called only when no scanning is in progress. I.e. Cy_CapSense_IsBusy() returns a non-busy status.
After the middleware stops, the CAPSENSE™ HW block(s) may be reconfigured with the application program or other middleware for any other usage.
When the middleware operation is stopped by the Cy_CapSense_DeInit() function, subsequent call of the Cy_CapSense_Init() function repeats the initialization process, so a subsequent call of the Cy_CapSense_Enable() function is not required. However, to implement Time-multiplexed mode (sharing the CAPSENSE™ HW block(s) between multiple middleware) the Cy_CapSense_Save() and Cy_CapSense_Restore() functions should be used instead of the Cy_CapSense_DeInit() and Cy_CapSense_Init() functions for further compatibility.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_Enable | ( | cy_stc_capsense_context_t * | context | ) |
Initializes the CAPSENSE™ firmware modules.
Call the Cy_CapSense_Init() function and configure CAPSENSE™ HW block interrupts prior to calling this function. See the function usage example below for details on usage.
The following are executed as part of the function:
Any subsequent call of this function repeats the initialization process. Therefore, it is possible to change the middleware configuration from the application program by writing registers to the data structure and calling this function again.
The repeated call of this function is also done inside the Cy_CapSense_RunTuner() function when a restart command is received.
The function calls the Cy_CapSense_ScanAllWidgets() function to proper baseline setup.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
The 'cy_capsense_context' variable that is used as the parameter of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions is declared in the cycfg_capsense.h file.
The CapSense_ISR_cfg variable should be declared by the application program according to the examples below:
For CM0+ core:
For CM4 core:
The CAPSENSE™ interrupt handler should be declared by the application program according to the example below:
The CapSense_HW is the pointer to the base register address of the CAPSENSE™ HW block. A macro for the pointer is in the cycfg_peripherals.h file defined as <Personality_Name>_HW. If no name is specified, the following default names are used:
cy_capsense_status_t Cy_CapSense_Save | ( | cy_stc_capsense_context_t * | context | ) |
Saves the state of CAPSENSE™ 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™ HW block among multiple middleware. When the CAPSENSE™ HW block is shared by multiple middleware, this function can be used to save the current state of the CAPSENSE™ HW block and CAPSENSE™ Middleware prior to releasing the CAPSENSE™ 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:
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
An example of sharing the CAPSENSE™ HW block by the CAPSENSE™ and CSDADC middleware.
Declares the CapSense_ISR_cfg variable:
Declares the CSDADC_ISR_cfg variable:
Defines the CapSense interrupt handler:
Defines the CSDADC interrupt handler:
The part of the main.c FW flow:
cy_capsense_status_t Cy_CapSense_Restore | ( | cy_stc_capsense_context_t * | context | ) |
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™ HW block among multiple middleware. When the CAPSENSE™ HW blocks are shared by multiple middleware, this function can be used to restore the previous state of the CAPSENSE™ HW block(s) and CAPSENSE™ 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.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
An example of sharing the CAPSENSE™ HW block by CAPSENSE™ and CSDADC middleware:
cy_capsense_status_t Cy_CapSense_ProcessAllWidgets | ( | cy_stc_capsense_context_t * | context | ) |
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:
This function is called by the application program only after all the enabled widgets (and sensors) in the middleware are scanned. Calling this function multiple times without sensor scanning causes unexpected behavior.
Disabled and/or non-working widgets are not processed by this function.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_ProcessWidget | ( | uint32_t | widgetId, |
cy_stc_capsense_context_t * | context | ||
) |
Performs full data processing of the specified widget if it is enabled.
This function performs exactly the same tasks as Cy_CapSense_ProcessAllWidgets(), but only for a specified widget. This function can be used along with the Cy_CapSense_ScanWidget() function (4th Generation) to scan and process data for a specific widget or with the Cy_CapSense_ScanSlots() function (5th Generation). This function is called only after all the sensors in the widgets are scanned.
The disabled and/or non-working widgets are not processed by this function.
The pipeline scan method, which during scanning a current widget (N), performs the processing of the previously scanned widget (N-1)) can be implemented using this function and it may reduce the total execution time, increase the refresh rate, and decrease the average power consumption. See the function usage example below for details on usage.
For the Fifth generation CAPSENSE™ if the specified widget has the enabled multi-frequency scan feature then the function does the following:
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. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
An example of pipeline implementation:
void Cy_CapSense_IncrementGestureTimestamp | ( | cy_stc_capsense_context_t * | context | ) |
Increments the timestamp register for the predefined timestamp interval.
A timestamp is required for the operation of the Gesture and Ballistic multiplier feature. Hence, this function and timestamp are required only if the Gesture detection or Ballistic multiplier feature is enabled.
This function increments the timestamp by the interval specified 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:
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 to be set in the register at an interval.
If a timestamp is available from another source, the application program may choose to periodically update the timestamp by using the Cy_CapSense_SetGestureTimestamp() function instead of registering a callback.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
An example of timestamp updating:
void Cy_CapSense_SetGestureTimestamp | ( | uint32_t | value, |
cy_stc_capsense_context_t * | context | ||
) |
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.
value | Specifies the timestamp value (in ms). |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
void Cy_CapSense_Wakeup | ( | const cy_stc_capsense_context_t * | context | ) |
Resumes the middleware after System Deep Sleep.
This function is used to resume the middleware operation after exiting System Deep Sleep. After the CAPSENSE™ HW block is powered on, an extra delay is required to establish the correct operation of the CAPSENSE™ HW block. No need for the Cy_CapSense_Wakeup() function call for the fifth-generation low power CAPSENSE™ because all needed delays are managed automatically in scan start functions.
This function is called by the Cy_CapSense_DeepSleepCallback() function after exiting System Deep Sleep if the CAPSENSE™ Deep Sleep callback is registered.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_en_syspm_status_t Cy_CapSense_DeepSleepCallback | ( | cy_stc_syspm_callback_params_t * | callbackParams, |
cy_en_syspm_callback_mode_t | mode | ||
) |
Handles CPU active to System Deep Sleep power mode transition for the CAPSENSE™ middleware.
Calling this function directly from the application program is not recommended. Instead, Cy_SysPm_CpuEnterDeepSleep() should be used for the CPU active to System Deep Sleep power mode transition of the device.
For proper operation of the CAPSENSE™ middleware during the CPU active to System Deep Sleep mode transition, a callback to this function should be registered using the Cy_SysPm_RegisterCallback() function with CY_SYSPM_DEEPSLEEP type. After the callback is registered, this function is called by the Cy_SysPm_CpuEnterDeepSleep() function to prepare the middleware to the device power mode transition.
When this function is called with CY_SYSPM_CHECK_READY as 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™ 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™ captured HW blocks, no need for the Cy_CapSense_Wakeup() function call and restoring CAPSENSE™ 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.
callbackParams | Refer to the description of the cy_stc_syspm_callback_params_t type in the Peripheral Driver Library documentation. |
mode | Specifies mode cy_en_syspm_callback_mode_t. |
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 | ||
) |
Registers a ures's callback function.
The registered function will be called by the CAPSENSE™ middleware when the specified event cy_en_capsense_callback_event_t has occurred in the CAPSENSE™ middleware.
callbackType | The event on which the registered user's function is called by the CAPSENSE™ middleware. Refer to cy_en_capsense_callback_event_t for the list of supported events. |
callbackFunction | The pointer to the user's callback function to be called by the middleware. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_UnRegisterCallback | ( | cy_en_capsense_callback_event_t | callbackType, |
cy_stc_capsense_context_t * | context | ||
) |
This function unregisters a previously registered user's callback function in the CAPSENSE™ middleware.
callbackType | The event on which the callback function should be unregistered. Refer to cy_en_capsense_callback_event_t for the list of supported events. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
uint32_t Cy_CapSense_DecodeWidgetGestures | ( | uint32_t | widgetId, |
const cy_stc_capsense_context_t * | context | ||
) |
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.
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. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
An example of gesture decoding:
An example of gesture status parsing:
cy_en_capsense_bist_status_t Cy_CapSense_RunSelfTest | ( | uint32_t | testEnMask, |
cy_stc_capsense_context_t * | context | ||
) |
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.
This function does not execute two tests: sensor raw count and baseline integrity.
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™:
For the fifth-generation CAPSENSE™:
For the fifth-generation low power CAPSENSE™:
Refer to these functions descriptions for detail information on the corresponding test.
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.
|
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_ScanAllSlots | ( | cy_stc_capsense_context_t * | context | ) |
Initiates the non-blocking scan of all Active slots and then exits.
Scanning is initiated only if no scan is in progress. To initiate all Low Power slot scan use the Cy_CapSense_ScanAllLpSlots() function.
If the middleware is busy, do not initiate a new scan or set up widgets. Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. Use the Cy_CapSense_MwState() function to verify if MW executes any firmware tasks related to initialization, scanning, and processing at a particular moment.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_ScanSlots | ( | uint32_t | startSlotId, |
uint32_t | numberSlots, | ||
cy_stc_capsense_context_t * | context | ||
) |
Initiates the non-blocking scan of a specified regular slots set named "frame" and then exits.
Scanning is initiated only if no scan is in progress. Check the status of the current scan using the Cy_CapSense_IsBusy() function. The application program should wait until the current frame scan is finished prior to start a next scan by using the function.
If the middleware is busy, do not initiate a new scan or set up widgets. Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. Use the Cy_CapSense_MwState() function to verify if MW executes any firmware tasks related to initialization, scanning, and processing at a particular moment.
startSlotId | The slot ID the scan of the specified frame will be started from. |
numberSlots | The number of slots in the specified frame will be scanned. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_mw_state_t Cy_CapSense_MwState | ( | const cy_stc_capsense_context_t * | context | ) |
Returns a detailed state of the CAPSENSE™ middleware and MSC and MSCLP HW blocks in Single- or Multi-channel mode.
This feature is useful in multi-thread applications or in ISR. Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. Use the Cy_CapSense_MwState() function to verify if MW executes any firmware tasks related to initialization, scanning, and processing at a particular moment. If the middleware is busy, a new scan, setup widgets, any kind of reconfiguration, or parameter change should not be initiated.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_ScanAllWidgets | ( | cy_stc_capsense_context_t * | context | ) |
Initiates scanning of all enabled widgets (and sensors) in the project.
For fifth-generation low power CAPSENSE™ the function initiates only Active widget scans. The initiation of a Low Power widget scan uses the Cy_CapSense_ScanAllLpWidgets() function.
This function initiates a scan only for the first sensor in the first widget for the fourth-generation CAPSENSE™ or a scan for the first slot for the fifth-generation CAPSENSE™ and fifth-generation low power CAPSENSE™ and then exits the function. The scan for the remaining sensors(slots) are initiated in the interrupt-driven mode in the interrupt service routine (part of middleware) triggered at the end of each scan completion or by DMA controllers in the DMA mode for the fifth-generation CAPSENSE™. For the fifth-generation low power CAPSENSE™ the remaining sensor scans depend on the ACTIVE sensor quantity, for details see the Cy_CapSense_ScanAllSlots() function description.
If the middleware is busy, do not initiate a new scan or set up widgets. Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. Use the Cy_CapSense_MwState() function to verify if MW executes any firmware tasks related to initialization, scanning, and processing at a particular moment. The application program should wait until the current frame scan is finished prior to start a next scan by using the function.
To get widget enable/working status the Cy_CapSense_IsWidgetEnabled() and Cy_CapSense_IsSlotEnabled() functions should be used. This status can be configured with Cy_CapSense_SetWidgetStatus() function.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_ScanWidget | ( | uint32_t | widgetId, |
cy_stc_capsense_context_t * | context | ||
) |
Performs the initialization required to scan the specified widget and triggers the scanning of all sensors in the widget.
If the middleware is busy, do not initiate a new scan or set up widgets. Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. Use the Cy_CapSense_MwState() function to verify if MW executes any firmware tasks related to initialization, scanning, and processing at a particular moment.
For fifth-generation low power CAPSENSE™ the function initiates only Active widget scans. To initiate Low Power widget scan use the Cy_CapSense_ScanLpWidget() function.
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. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
uint32_t Cy_CapSense_IsBusy | ( | const cy_stc_capsense_context_t * | context | ) |
This function returns a status whether MW executes HW scanning at a particular moment.
If the middleware is busy, do not initiate a new scan or set up widgets. Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. Use the Cy_CapSense_MwState() function to verify if MW executes any firmware tasks related to initialization, scanning, and processing at a particular moment. If the middleware is busy, a new scan, setup widgets, any kind of reconfiguration, or parameter change should not be initiated.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
void Cy_CapSense_InterruptHandler | ( | void * | base, |
cy_stc_capsense_context_t * | context | ||
) |
Implements interrupt service routine for CAPSENSE™ middleware.
The CAPSENSE™ middleware uses this interrupt to implement a non-blocking sensor scan method, in which only the first sensor scan is initiated by the application program. Subsequent sensor scans are initiated in the interrupt service routine as soon as the current scan or current sub-frame is completed.
The CAPSENSE™ middleware does not initialize or modify the priority of interrupts. For the proper middleware operation, the application program must configure CAPSENSE™ block interrupt and assign the interrupt vector to the Cy_CapSense_InterruptHandler() function. Refer to function usage example for details.
The calls of the Start Sample and End Of Scan callbacks (see the Callbacks section for details) are the part of the Cy_CapSense_InterruptHandler() routine and they lengthen its execution. These callbacks should not lengthen the ISR execution too much to prevent different interrupt overlaps.
base | The pointer to the base register address of the CAPSENSE™ HW block. This argument is kept for uniformity and backward compatibility and is not used. The function can be called with value NULL. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
An example of the ISR initialization:
The CapSense_ISR_cfg variable should be declared by the application program according to the examples below:
For Core CM0+:
For Core CM4:
The CAPSENSE™ interrupt handler should be defined by the application program according to the example below:
Then, the application program should configure and enable the CSD block interrupt between calls of the Cy_CapSense_Init() and Cy_CapSense_Enable() functions:
The CapSense_HW is the pointer to the base register address of the CAPSENSE™ HW block. A macro for the pointer is in the cycfg_peripherals.h file defined as <Personality_Name>_HW. If no name is specified, the following default names are used:
An example of sharing the CSD HW block (fourth-generation CAPSENSE™) by the CAPSENSE™ middleware and CSDADC middleware.
Declares the CapSense_ISR_cfg variable:
Declares the CSDADC_ISR_cfg variable:
Defines the CAPSENSE™ interrupt handler:
Defines the CSDADC interrupt handler:
The part of the main.c FW flow:
cy_capsense_status_t Cy_CapSense_ScanLpSlots | ( | uint32_t | startLpSlotId, |
uint32_t | numberLpSlots, | ||
cy_stc_capsense_context_t * | context | ||
) |
Initiates a non-blocking scan for specified low power slots and exits.
Scanning is initiated only if no scan is in progress. Scans initiated by this function can be performed in different system power modes such as Active, Sleep or Deep Sleep. After all specified number of frames are scanned or if a touch is detected during the scan, the interrupt is fired, the CPU switches Power mode to Active and the interrupt service routine (part of middleware) transfers the last frame raw counts and clears the busy status. If the middleware is busy, do not initiate a new scan or set up widgets. Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. Use the Cy_CapSense_MwState() function to verify if MW executes any firmware tasks related to initialization, scanning, and processing at a particular moment. The function clears the CY_CAPSENSE_MW_STATE_LP_ACTIVE_MASK status bit. It is set when a touch detection occurs during the low power slot scans and will remain set until the next Cy_CapSense_ScanLpSlots() function call.
startLpSlotId | The slot ID to start a scan from. |
numberLpSlots | The number of slots to be scanned. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_ScanAllLpSlots | ( | cy_stc_capsense_context_t * | context | ) |
Initiates a non-blocking scan of all low power slots and then exits.
Scanning is initiated only if no scan is in progress. A scan initiated by this function can be performed in different power modes such as Active, Sleep or Deep Sleep. After all specified number of frames are scanned or if a touch is detected during the scan, the interrupt is fired, the CPU switches Power mode to Active and the interrupt service routine (part of middleware) updates the busy status. If the middleware is busy, do not initiate a new scan or set up widgets. Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. Use the Cy_CapSense_MwState() function to verify if MW executes any firmware tasks related to initialization, scanning, and processing at a particular moment.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_ScanAllLpWidgets | ( | cy_stc_capsense_context_t * | context | ) |
Initiates a non-blocking scan for all low power widgets/sensors.
If the middleware is busy, do not initiate a new scan or set up widgets. Use the Cy_CapSense_IsBusy() function to check HW busyness at a particular moment. Use the Cy_CapSense_MwState() function to verify if MW executes any firmware tasks related to initialization, scanning, and processing at a particular moment.
The function is the wrapper for the Cy_CapSense_ScanAllLpSlots() function.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_ConfigureMsclpWotTimer | ( | uint32_t | wakeupTimer, |
cy_stc_capsense_context_t * | context | ||
) |
Configures the wakeup timer value for Wake-On-Touch mode.
The wakeup time is introduced before each scan frame.
The minimum wakeup time value is corresponding to one ILO cycle (25us for 40KHz ILO). The maximum wakeup time value depends on actual ILO frequency and can be set to a value, corresponding to 2^16 ILO cycles (1638400us for 40KHz ILO). If the timer value exceeds 2^16 ILO cycles, it would be set to the maximum possible value. The real wakeup time interval depends on ILO frequency which have a big tolerance (above +/- 50 %), see device datasheets. In order to improve the timer accuracy, use Cy_CapSense_IloCompensate() function.
wakeupTimer | The desired wakeup timer value in microseconds. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_ConfigureMsclpTimer | ( | uint32_t | wakeupTimer, |
cy_stc_capsense_context_t * | context | ||
) |
Configures the wakeup timer value for Active mode.
The wakeup timer interval is introduced before each scan frame start. Use the function to implement different Active scan refresh rates (for instance an Active mode with the 128 Hz refresh rate and an Active Low Refresh Rate mode with the 32 Hz refresh rate).
The minimum wakeup time value is corresponding to one ILO cycle (25us for 40KHz ILO). The maximum wakeup time value depends on actual ILO frequency and can be set to a value, corresponding to 2^16 ILO cycles (1638400us for 40KHz ILO). If the timer value exceeds 2^16 ILO cycles, it would be set to the maximum possible value. The real wakeup time interval depends on ILO frequency which have a big tolerance (above +/- 50 %), see device datasheets. In order to improve the timer accuracy, use Cy_CapSense_IloCompensate() function.
wakeupTimer | The desired wakeup timer value in microseconds. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_IloCompensate | ( | cy_stc_capsense_context_t * | context | ) |
Measures the actual ILO frequency and calculates the compensation factor for MSCLP Active and Wake-On-Touch mode timers.
In order to keep timer intervals accurate, call this function periodically. To set Active and Wake-On-Touch mode timers, use Cy_CapSense_ConfigureMsclpTimer() and Cy_CapSense_ConfigureMsclpWotTimer() functions correspondingly.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_SetupWidget | ( | uint32_t | widgetId, |
cy_stc_capsense_context_t * | context | ||
) |
Performs the initialization required to scan the specified widget.
This function prepares the middleware to scan all the sensors in the specified widget by executing the following tasks:
This function does not start sensor scanning. The Cy_CapSense_Scan() function must be called to start the scan sensors in the widget. If this function is called more than once, it does not break the middleware operation, but only the last initialized widget is in effect.
The status of a sensor scan must be checked using the Cy_CapSense_IsBusy() function prior to starting a next scan or setting up another widget.
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. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_capsense_status_t Cy_CapSense_Scan | ( | cy_stc_capsense_context_t * | context | ) |
Initiates scanning of all the sensors in the widget initialized by Cy_CapSense_SetupWidget(), if no scan is in progress.
Prior to calling this function to scan sensors, the widget required to be scanned must be initialized using Cy_CapSense_SetupWidget() function.
This function initiates scan only for the first sensor in the widget and then exits the function. The scan for the remaining sensors in the widget is initiated in the interrupt service routine (part of middleware) triggered at the end of each scan completion. Hence, check the status of the current scan using the Cy_CapSense_IsBusy() function and wait until all scans in the current widget are finished prior to starting the next scan or initializing another widget.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
uint32_t Cy_CapSense_IsAnyWidgetActive | ( | const cy_stc_capsense_context_t * | context | ) |
Reports whether any widget has detected touch.
This function reports whether any widget has detected a touch by extracting information from the widget status registers. This function does not process widget data but extracts previously processed results from the Structures.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
uint32_t Cy_CapSense_IsAnyLpWidgetActive | ( | const cy_stc_capsense_context_t * | context | ) |
Reports whether any low power widget has detected a touch at the previous low power scan.
This function reports whether any low power widget has detected a touch by extracting information from the common status register. The function does not process the widget data but extracts the result obtained at the previous low power widget scan. The result remains set up to the next low power widget scan and is reset with the low power scan start.
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
uint32_t Cy_CapSense_IsWidgetActive | ( | uint32_t | widgetId, |
const cy_stc_capsense_context_t * | context | ||
) |
Reports whether the specified widget detected touch on any of its sensors.
This function reports whether the specified widget has detected a touch by extracting information from the widget status register. This function does not process widget data but extracts previously processed results from the Structures.
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. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
uint32_t Cy_CapSense_IsSensorActive | ( | uint32_t | widgetId, |
uint32_t | sensorId, | ||
const cy_stc_capsense_context_t * | context | ||
) |
Reports whether the specified sensor in the widget is sensor detects a touch.
This function reports whether the specified sensor in the widget has detected a touch by extracting information from the widget status register. This function does not process widget or sensor data but extracts previously processed results from the Structures.
For proximity sensors, this function returns the proximity detection status. To get the touch status of proximity sensors, use the Cy_CapSense_IsProximitySensorActive() function.
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. |
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. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
uint32_t Cy_CapSense_IsProximitySensorActive | ( | uint32_t | widgetId, |
uint32_t | sensorId, | ||
const cy_stc_capsense_context_t * | context | ||
) |
Reports the status of the specified proximity widget/sensor.
This function reports whether the specified proximity sensor has detected a touch or proximity event by extracting information from the widget status register. This function is used only with proximity widgets. This function does not process widget data but extracts previously processed results from the Structures.
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. |
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. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
cy_stc_capsense_touch_t* Cy_CapSense_GetTouchInfo | ( | uint32_t | widgetId, |
const cy_stc_capsense_context_t * | context | ||
) |
Reports the details of touch position detected on the specified touchpad, matrix buttons or slider widgets.
This function does not process widget data but extracts previously processed results from the Structures.
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. |
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
uint32_t Cy_CapSense_RunTuner | ( | cy_stc_capsense_context_t * | context | ) |
Establishes synchronized operation between the CAPSENSE™ Middleware and the CAPSENSE™ Tuner tool.
This function is called periodically in the application program. It serves the CAPSENSE™ Tuner tool requests and commands to synchronize the operation. Mostly, the best place to call this function is between processing and next scanning. If the user changes some parameters in the Tuner tool, the middleware is re-started - the Tuner issues a restart command to be executed by this function.
The Tuner interface supports two communication protocol: EZI2C and UART.
To use an EZI2C-based tuner interface, only initialization of the EZI2C driver and interface is required in the application program. Refer to the I2C driver documentation for details of the protocol implementation and data package format by the EZI2C interface.
To use a UART-based tuner interface, the user must:
The application program must:
The transmission packet includes a CAPSENSE™ context structure sandwiched between a header (0x0D0A) and a tail (0x00FFFF), hence the package size is dependent on CAPSENSE™ context information. The receiver packet is 16-byte (fixed length) data explained under the Cy_CapSense_CheckTunerCmdIntegrity() function. The Cy_CapSense_CheckTunerCmdIntegrity() function is used to validate the received data package prior to passing it to the CAPSENSE™ middleware.
Periodical calling the Cy_CapSense_RunTuner() function is:
If the Cy_CapSense_RunTuner() function is not periodically called by the application program, the middleware operation is asynchronous to the Tuner tool and the following disadvantages are applicable:
context | The pointer to the CAPSENSE™ context structure cy_stc_capsense_context_t. |
An example of synchronization with the Tuner tool using EzI2C interface:
An example of synchronization with the Tuner tool using UART interface:
uint32_t Cy_CapSense_CheckTunerCmdIntegrity | ( | const uint8_t * | commandPacket | ) |
Checks command format, header, tail, CRC, etc.
This function checks whether the specified packet with the size CY_CAPSENSE_COMMAND_PACKET_SIZE could be represented as a command received from the CAPSENSE™ Tuner tool. The verification includes the following items:
Command format is the following:
commandPacket | The pointer to the data packet that should be verified. |