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.
|
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...
|
|
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...
|
|
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.
|
void CAPT_Init |
( |
CAPT_Type * |
base, |
|
|
const capt_config_t * |
config |
|
) |
| |
- Parameters
-
base | CAPT peripheral base address. |
config | Pointer to "capt_config_t" structure. |
void CAPT_Deinit |
( |
CAPT_Type * |
base | ) |
|
- Parameters
-
base | CAPT peripheral base address. |
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;
*
- Parameters
-
base | CAPT peripheral base address. |
config | Pointer to the configuration structure. |
static void CAPT_SetThreshold |
( |
CAPT_Type * |
base, |
|
|
uint32_t |
count |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | CAPT peripheral base address. |
count | The count threshold. |
- Parameters
-
base | CAPT peripheral base address. |
mode | The selection of polling mode. |
static void CAPT_EnableInterrupts |
( |
CAPT_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | CAPT peripheral base address. |
mask | The mask of enabling interrupt features. Please refer to "_capt_interrupt_enable". |
static void CAPT_DisableInterrupts |
( |
CAPT_Type * |
base, |
|
|
uint32_t |
mask |
|
) |
| |
|
inlinestatic |
- Parameters
-
base | CAPT peripheral base address. |
mask | The mask of disabling interrupt features. Please refer to "_capt_interrupt_enable". |
static uint32_t CAPT_GetInterruptStatusFlags |
( |
CAPT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | CAPT 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
-
base | CAPT peripheral base address. |
mask | The mask of clearing the interrupts' status flags, please refer to "_capt_interrupt_status_flags". |
static uint32_t CAPT_GetStatusFlags |
( |
CAPT_Type * |
base | ) |
|
|
inlinestatic |
- Parameters
-
base | CAPT 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.
- Parameters
-
base | CAPT peripheral base address. |
data | The structure to store touch data. |
- Returns
- If return 'true', which means get valid data. if return 'false', which means get invalid data.
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".
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 |