MCUXpresso SDK API Reference Manual  Rev. 0
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
CAPT: Capacitive Touch

Overview

The MCUXpresso SDK provides a peripheral driver for the Capacitive Touch (CAPT) module of MCUXpresso SDK devices.

The Capacitive Touch module measures the change in capacitance of an electrode plate when an earth-ground connected object (for example, the finger or stylus) is brought within close proximity. Simply stated, the module delivers a small charge to an X capacitor (a mutual capacitance touch sensor), then transfers that charge to a larger Y capacitor (the measurement capacitor), and counts the number of iterations necessary for the voltage across the Y capacitor to cross a predetermined threshold.

Typical use case

Normal Configuration

See the driver examples codes located at <SDK_ROOT>/boards/<BOARD>/driver_examples/capt/capt_basic.

Files

file  fsl_capt.h
 

Data Structures

struct  capt_config_t
 The structure for CAPT basic configuration. More...
 
struct  capt_touch_data_t
 The structure for storing touch data. More...
 

Enumerations

enum  _capt_xpins {
  kCAPT_X0Pin = 1U << 0U,
  kCAPT_X1Pin = 1U << 1U,
  kCAPT_X2Pin = 1U << 2U,
  kCAPT_X3Pin = 1U << 3U,
  kCAPT_X4Pin = 1U << 4U,
  kCAPT_X5Pin = 1U << 5U,
  kCAPT_X6Pin = 1U << 6U,
  kCAPT_X7Pin = 1U << 7U,
  kCAPT_X8Pin = 1U << 8U,
  kCAPT_X9Pin = 1U << 9U,
  kCAPT_X10Pin = 1U << 10U,
  kCAPT_X11Pin = 1U << 11U,
  kCAPT_X12Pin = 1U << 12U,
  kCAPT_X13Pin = 1U << 13U,
  kCAPT_X14Pin = 1U << 14U,
  kCAPT_X15Pin = 1U << 15U
}
 The enumeration for X pins. More...
 
enum  _capt_interrupt_enable {
  kCAPT_InterruptOfYesTouchEnable,
  kCAPT_InterruptOfNoTouchEnable,
  kCAPT_InterruptOfPollDoneEnable = CAPT_INTENSET_POLLDONE_MASK,
  kCAPT_InterruptOfTimeOutEnable = CAPT_INTENSET_TIMEOUT_MASK,
  kCAPT_InterruptOfOverRunEnable = CAPT_INTENSET_OVERUN_MASK
}
 The enumeration for enabling/disabling interrupts. More...
 
enum  _capt_interrupt_status_flags {
  kCAPT_InterruptOfYesTouchStatusFlag = CAPT_INTSTAT_YESTOUCH_MASK,
  kCAPT_InterruptOfNoTouchStatusFlag = CAPT_INTSTAT_NOTOUCH_MASK,
  kCAPT_InterruptOfPollDoneStatusFlag = CAPT_INTSTAT_POLLDONE_MASK,
  kCAPT_InterruptOfTimeOutStatusFlag = CAPT_INTSTAT_TIMEOUT_MASK,
  kCAPT_InterruptOfOverRunStatusFlag = CAPT_INTSTAT_OVERUN_MASK
}
 The enumeration for interrupt status flags. More...
 
enum  _capt_status_flags {
  kCAPT_BusyStatusFlag = CAPT_STATUS_BUSY_MASK,
  kCAPT_XMAXStatusFlag = CAPT_STATUS_XMAX_MASK
}
 The enumeration for CAPT status flags. More...
 
enum  capt_trigger_mode_t {
  kCAPT_YHPortTriggerMode = 0U,
  kCAPT_ComparatorTriggerMode = 1U
}
 The enumeration for CAPT trigger mode. More...
 
enum  capt_inactive_xpins_mode_t {
  kCAPT_InactiveXpinsHighZMode,
  kCAPT_InactiveXpinsDrivenLowMode
}
 The enumeration for the inactive X pins mode. More...
 
enum  capt_measurement_delay_t {
  kCAPT_MeasureDelayNoWait = 0U,
  kCAPT_MeasureDelayWait3FCLKs = 1U,
  kCAPT_MeasureDelayWait5FCLKs = 2U,
  kCAPT_MeasureDelayWait9FCLKs = 3U
}
 The enumeration for the delay of measuring voltage state. More...
 
enum  capt_reset_delay_t {
  kCAPT_ResetDelayNoWait = 0U,
  kCAPT_ResetDelayWait3FCLKs = 1U,
  kCAPT_ResetDelayWait5FCLKs = 2U,
  kCAPT_ResetDelayWait9FCLKs = 3U
}
 The enumeration for the delay of reseting or draining Cap. More...
 
enum  capt_polling_mode_t {
  kCAPT_PollInactiveMode,
  kCAPT_PollNowMode = 1U,
  kCAPT_PollContinuousMode
}
 The enumeration of CAPT polling mode. More...
 
enum  capt_dma_mode_t {
  kCAPT_DMATriggerOnTouchMode = 1U,
  kCAPT_DMATriggerOnBothMode = 2U,
  kCAPT_DMATriggerOnAllMode = 3U
}
 The enumeration of CAPT DMA trigger mode. More...
 

Variables

bool capt_config_t::enableWaitMode
 If enable the wait mode, when the touch event occurs, the module will wait until the TOUCH register is read before starting the next measurement. More...
 
bool capt_config_t::enableTouchLower
 enableTouchLower = true: Trigger at count < TCNT is a touch. More...
 
uint8_t capt_config_t::clockDivider
 Function clock divider. More...
 
uint8_t capt_config_t::timeOutCount
 Sets the count value at which a time-out event occurs if a measurement has not triggered. More...
 
uint8_t capt_config_t::pollCount
 Sets the time delay between polling rounds (successive sets of X measurements). More...
 
uint16_t capt_config_t::enableXpins
 Selects which of the available X pins are enabled. More...
 
capt_trigger_mode_t capt_config_t::triggerMode
 Select the menthods of measuring the voltage across the measurement capacitor. More...
 
capt_inactive_xpins_mode_t capt_config_t::XpinsMode
 Determines how X pins enabled in the XPINSEL field are controlled when not active. More...
 
capt_measurement_delay_t capt_config_t::mDelay
 
       Set the time delay after entering step 3 (measure voltage state), before

sampling the YH port pin or analog comarator output. More...

 
capt_reset_delay_t capt_config_t::rDelay
 Set the number of divided FCLKs the module will remain in Reset or Draining Cap. More...
 
bool capt_touch_data_t::yesTimeOut
 'true': if the measurement resulted in a time-out event, 'false': otherwise. More...
 
bool capt_touch_data_t::yesTouch
 'true': if the trigger is due to a touch even, 'false': if the trigger is due to a no-touch event. More...
 
uint8_t capt_touch_data_t::XpinsIndex
 Contains the index of the X pin for the current measurement, or lowest X for a multiple-pin poll now measurement. More...
 
uint8_t capt_touch_data_t::sequenceNumber
 Contains the 4-bit(0-7) sequence number, which increments at the end of each polling round. More...
 
uint16_t capt_touch_data_t::count
 Contains the count value reached at trigger or time-out. More...
 

Driver version

#define FSL_CAPT_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))
 CAPT driver version 2.0.1. More...
 

Initialization

void CAPT_Init (CAPT_Type *base, const capt_config_t *config)
 Initialize the CAPT module. More...
 
void CAPT_Deinit (CAPT_Type *base)
 De-initialize the CAPT module. More...
 
void CAPT_GetDefaultConfig (capt_config_t *config)
 Gets an available pre-defined settings for the CAPT's configuration. More...
 
static void CAPT_SetThreshold (CAPT_Type *base, uint32_t count)
 Set Sets the count threshold in divided FCLKs between touch and no-touch. More...
 
void CAPT_SetPollMode (CAPT_Type *base, capt_polling_mode_t mode)
 Set the CAPT polling mode. More...
 
static void CAPT_EnableInterrupts (CAPT_Type *base, uint32_t mask)
 Enable interrupt features. More...
 
static void CAPT_DisableInterrupts (CAPT_Type *base, uint32_t mask)
 Disable interrupt features. More...
 
static uint32_t CAPT_GetInterruptStatusFlags (CAPT_Type *base)
 Get CAPT interrupts' status flags. More...
 
static void CAPT_ClearInterruptStatusFlags (CAPT_Type *base, uint32_t mask)
 Clear the interrupts' status flags. More...
 
static uint32_t CAPT_GetStatusFlags (CAPT_Type *base)
 Get CAPT status flags. More...
 
bool CAPT_GetTouchData (CAPT_Type *base, capt_touch_data_t *data)
 Get CAPT touch data. More...
 

Data Structure Documentation

struct capt_config_t

Data Fields

bool enableWaitMode
 If enable the wait mode, when the touch event occurs, the module will wait until the TOUCH register is read before starting the next measurement. More...
 
bool enableTouchLower
 enableTouchLower = true: Trigger at count < TCNT is a touch. More...
 
uint8_t clockDivider
 Function clock divider. More...
 
uint8_t timeOutCount
 Sets the count value at which a time-out event occurs if a measurement has not triggered. More...
 
uint8_t pollCount
 Sets the time delay between polling rounds (successive sets of X measurements). More...
 
uint16_t enableXpins
 Selects which of the available X pins are enabled. More...
 
capt_trigger_mode_t triggerMode
 Select the menthods of measuring the voltage across the measurement capacitor. More...
 
capt_inactive_xpins_mode_t XpinsMode
 Determines how X pins enabled in the XPINSEL field are controlled when not active. More...
 
capt_measurement_delay_t mDelay
 
       Set the time delay after entering step 3 (measure voltage state), before

sampling the YH port pin or analog comarator output. More...

 
capt_reset_delay_t rDelay
 Set the number of divided FCLKs the module will remain in Reset or Draining Cap. More...
 
struct capt_touch_data_t

Data Fields

bool yesTimeOut
 'true': if the measurement resulted in a time-out event, 'false': otherwise. More...
 
bool yesTouch
 'true': if the trigger is due to a touch even, 'false': if the trigger is due to a no-touch event. More...
 
uint8_t XpinsIndex
 Contains the index of the X pin for the current measurement, or lowest X for a multiple-pin poll now measurement. More...
 
uint8_t sequenceNumber
 Contains the 4-bit(0-7) sequence number, which increments at the end of each polling round. More...
 
uint16_t count
 Contains the count value reached at trigger or time-out. More...
 

Macro Definition Documentation

#define FSL_CAPT_DRIVER_VERSION   (MAKE_VERSION(2, 0, 1))

Enumeration Type Documentation

Enumerator
kCAPT_X0Pin 

CAPT_X0 pin.

kCAPT_X1Pin 

CAPT_X1 pin.

kCAPT_X2Pin 

CAPT_X2 pin.

kCAPT_X3Pin 

CAPT_X3 pin.

kCAPT_X4Pin 

CAPT_X4 pin.

kCAPT_X5Pin 

CAPT_X5 pin.

kCAPT_X6Pin 

CAPT_X6 pin.

kCAPT_X7Pin 

CAPT_X7 pin.

kCAPT_X8Pin 

CAPT_X8 pin.

kCAPT_X9Pin 

CAPT_X9 pin.

kCAPT_X10Pin 

CAPT_X10 pin.

kCAPT_X11Pin 

CAPT_X11 pin.

kCAPT_X12Pin 

CAPT_X12 pin.

kCAPT_X13Pin 

CAPT_X13 pin.

kCAPT_X14Pin 

CAPT_X14 pin.

kCAPT_X15Pin 

CAPT_X15 pin.

Enumerator
kCAPT_InterruptOfYesTouchEnable 

Generate interrupt when a touch has been detected.

kCAPT_InterruptOfNoTouchEnable 

Generate interrupt when a no-touch has been detected.

kCAPT_InterruptOfPollDoneEnable 

Genarate interrupt at the end of a polling round, or when a POLLNOW completes.

kCAPT_InterruptOfTimeOutEnable 

Generate interrupt when the count reaches the time-out count value before a trigger occurs.

kCAPT_InterruptOfOverRunEnable 

Generate interrupt when the Touch Data register has been up-dated before software has read the previous data, and the touch has been detected.

Enumerator
kCAPT_InterruptOfYesTouchStatusFlag 

YESTOUCH interrupt status flag.

kCAPT_InterruptOfNoTouchStatusFlag 

NOTOUCH interrupt status flag.

kCAPT_InterruptOfPollDoneStatusFlag 

POLLDONE interrupt status flag.

kCAPT_InterruptOfTimeOutStatusFlag 

TIMEOUT interrupt status flag.

kCAPT_InterruptOfOverRunStatusFlag 

OVERRUN interrupt status flag.

Enumerator
kCAPT_BusyStatusFlag 

Set while a poll is currently in progress, otherwise cleared.

kCAPT_XMAXStatusFlag 

The maximum number of X pins available for a given device is equal to XMAX+1.

Enumerator
kCAPT_YHPortTriggerMode 

YH port pin trigger mode.

kCAPT_ComparatorTriggerMode 

Analog comparator trigger mode.

Enumerator
kCAPT_InactiveXpinsHighZMode 

Xpins enabled in the XPINSEL field are controlled to HIGH-Z mode when not active.

kCAPT_InactiveXpinsDrivenLowMode 

Xpins enabled in the XPINSEL field are controlled to be driven low mode when not active.

Enumerator
kCAPT_MeasureDelayNoWait 

Don’t wait.

kCAPT_MeasureDelayWait3FCLKs 

Wait 3 divided FCLKs.

kCAPT_MeasureDelayWait5FCLKs 

Wait 5 divided FCLKs.

kCAPT_MeasureDelayWait9FCLKs 

Wait 9 divided FCLKs.

Enumerator
kCAPT_ResetDelayNoWait 

Don’t wait.

kCAPT_ResetDelayWait3FCLKs 

Wait 3 divided FCLKs.

kCAPT_ResetDelayWait5FCLKs 

Wait 5 divided FCLKs.

kCAPT_ResetDelayWait9FCLKs 

Wait 9 divided FCLKs.

Enumerator
kCAPT_PollInactiveMode 

No measurements are taken, no polls are performed.

The module remains in the Reset Cap.

kCAPT_PollNowMode 

Immediately launches (ignoring Poll Delay) a one-time-only, simultaneous poll of all X pins that are enabled in the XPINSEL field of the Control register, then stops, returning to Reset/Draining Cap.

kCAPT_PollContinuousMode 

Polling rounds are continuously performed, by walking through the enabled X pins.

Enumerator
kCAPT_DMATriggerOnTouchMode 

Trigger on touch.

kCAPT_DMATriggerOnBothMode 

Trigger on both touch and no-touch.

kCAPT_DMATriggerOnAllMode 

Trigger on all touch, no-touch and time-out.

Function Documentation

void CAPT_Init ( CAPT_Type *  base,
const capt_config_t config 
)
Parameters
baseCAPT peripheral base address.
configPointer to "capt_config_t" structure.
void CAPT_Deinit ( CAPT_Type *  base)
Parameters
baseCAPT peripheral base address.
void CAPT_GetDefaultConfig ( capt_config_t config)

This function initializes the converter configuration structure with available settings. The default values are:

* config->enableWaitMode = false;
* config->enableTouchLower = true;
* config->clockDivider = 15U;
* config->timeOutCount = 12U;
* config->pollCount = 0U;
* config->enableXpins = 0U;
* config->triggerMode = kCAPT_YHPortTriggerMode;
* config->XpinsMode = kCAPT_InactiveXpinsDrivenLowMode;
* config->mDelay = kCAPT_MeasureDelayNoWait;
* config->rDelay = kCAPT_ResetDelayWait9FCLKs;
*
Parameters
baseCAPT peripheral base address.
configPointer to the configuration structure.
static void CAPT_SetThreshold ( CAPT_Type *  base,
uint32_t  count 
)
inlinestatic
Parameters
baseCAPT peripheral base address.
countThe count threshold.
void CAPT_SetPollMode ( CAPT_Type *  base,
capt_polling_mode_t  mode 
)
Parameters
baseCAPT peripheral base address.
modeThe selection of polling mode.
static void CAPT_EnableInterrupts ( CAPT_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseCAPT peripheral base address.
maskThe mask of enabling interrupt features. Please refer to "_capt_interrupt_enable".
static void CAPT_DisableInterrupts ( CAPT_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseCAPT peripheral base address.
maskThe mask of disabling interrupt features. Please refer to "_capt_interrupt_enable".
static uint32_t CAPT_GetInterruptStatusFlags ( CAPT_Type *  base)
inlinestatic
Parameters
baseCAPT peripheral base address.
Returns
The mask of interrupts' status flags. please refer to "_capt_interrupt_status_flags".
static void CAPT_ClearInterruptStatusFlags ( CAPT_Type *  base,
uint32_t  mask 
)
inlinestatic
Parameters
baseCAPT peripheral base address.
maskThe mask of clearing the interrupts' status flags, please refer to "_capt_interrupt_status_flags".
static uint32_t CAPT_GetStatusFlags ( CAPT_Type *  base)
inlinestatic
Parameters
baseCAPT peripheral base address.
Returns
The mask of CAPT status flags. Please refer to "_capt_status_flags" Or use CAPT_GET_XMAX_NUMBER(mask) to get XMAX number.
bool CAPT_GetTouchData ( CAPT_Type *  base,
capt_touch_data_t data 
)
Parameters
baseCAPT peripheral base address.
dataThe structure to store touch data.
Returns
If return 'true', which means get valid data. if return 'false', which means get invalid data.

Variable Documentation

bool capt_config_t::enableWaitMode

Other-wise, measurements continue.

bool capt_config_t::enableTouchLower

Trigger at count > TCNT is a no-touch. enableTouchLower = false: Trigger at count > TCNT is a touch. Trigger at count < TCNT is a no-touch. Notice: TCNT will be set by "CAPT_DoCalibration" API.

uint8_t capt_config_t::clockDivider

The function clock is divided by clockDivider+1 to produce the divided FCLK for the module. The available range is 0-15.

uint8_t capt_config_t::timeOutCount

The time-out count value is calculated as 2^timeOutCount. The available range is 0-12.

uint8_t capt_config_t::pollCount

After each polling round completes, the module will wait 4096 x PollCount divided FCLKs before starting the next polling round. The available range is 0-255.

uint16_t capt_config_t::enableXpins

Please refer to '_capt_xpins'. For example, if want to enable X0, X2 and X3 pins, you can set "enableXpins = kCAPT_X0Pin | kCAPT_X2Pin | kCAPT_X3Pin".

capt_trigger_mode_t capt_config_t::triggerMode
capt_inactive_xpins_mode_t capt_config_t::XpinsMode
capt_measurement_delay_t capt_config_t::mDelay
capt_reset_delay_t capt_config_t::rDelay
bool capt_touch_data_t::yesTimeOut
bool capt_touch_data_t::yesTouch
uint8_t capt_touch_data_t::XpinsIndex
uint8_t capt_touch_data_t::sequenceNumber
uint16_t capt_touch_data_t::count