CapTouch Interrupt Mode

This sample code guide is designed to help users easily and comprehensively understand CapTouch sample. This sample code demonstrates CapTouch how to detect finger touch and proximity by interrupt mode. In CapTouch interrupt handler, 4 channels can be detected, whether there is finger press/release/false touch/over noise threshold.

Requirements

For hardware requirements, please refer to the Requirements.

Wiring

Connect P0_0 to channel 0 of touch buttons, connect P0_1 to channel 1 of touch buttons, connect P0_2 to channel 2 of touch buttons, and connect P0_3 to channel 3 of touch buttons.

The hardware connection of CapTouch sample code is shown in the figure below.

../../../_images/CapTouch_Demo_Hardware_Connection_Diagram.png

CapTouch Sample Code Hardware Connection Diagram

Configurations

The entry function is as follows, call this function in main() to run this sample code. For more details, please refer to the Initialization.

cap_touch_demo();

Building and Downloading

For building and downloading, please refer to the Building and Downloading.

Experimental Verification

Press the Reset button on the EVB board. When the touch buttons are pressed/released, the interrupt status will be printed in Debug Analyzer.

Code Overview

This section introduces the code and process description for initialization and corresponding function implementation in the sample.

Source Code Directory

  • For project directory, please refer to Source Code Directory.

  • Source code directory: sdk\src\sample\io_demo\captouch\cap_touch_demo.c.

Initialization

The initialization flow for peripherals can refer to Initialization Flow.

CapTouch initialization flow is shown in the following figure.

../../../_images/CapTouch_Initialization_Flow.png

CapTouch Initialization Flow

  1. Call CapTouch_SystemEnable() to enable CapTouch function.

  2. Call CapTouch_SysReset() to reset CapTouch system.

  3. Call CapTouch_ChCmd() to enable specified channel.

  4. Call CapTouch_ChINTConfig() to enable press interrupt and release interrupt and false touch interrupt.

  5. Call CapTouch_NoiseINTConfig() to enable noise interrupt.

  6. Call CapTouch_SetScanInterval() to set scan interval.

  7. Call CapTouch_ChWakeupCmd() to enable CapTouch wakeup from DLPS mode or power down mode.

  8. If enable wakeup from power down mode, call pmu_set_clk_32k_power_in_powerdown to keep 32k clock.

  9. Call CapTouch_Cmd() to enable CapTouch.

Functional Implementation

Interrupt Handle

CapTouch interrupt handle flow is shown in the following figure.

../../../_images/CapTouch_interrupt_handle_flow.png

CapTouch Interrupt Handle Flow

  1. Call CapTouch_GetINTStatus() to get interrupt status.

  2. Call CapTouch_IsChINTTriggered() or CapTouch_IsNoiseINTTriggered() to check corresponding interrupt status.

  3. Call CapTouch_ChINTClearPendingBit() or CapTouch_NoiseINTClearPendingBit() to clear corresponding interrupt.