CSLIB Capacitive Sensing Library#

Capacitive sensing firmware library for Silicon Labs MCUs.

Introduction#

The capacitive sensing library provides pre-compiled code set that performs touch qualification, filtering, and state maintanence for capacitive sensing-enabled Silicon Laboratories MCUs.

The library functions using calls into a device layer that interfaces with hardware peripherals.

Modules#

SI_UU32_t

SensorStruct_t

Enumerations#

enum
low = 1
mid = 2
high = 3
}

Defines all noise characterization states the CSLIB will use for characterization.

Variables#

uint8_t

Global counter incremented by the system timer.

uint8_t

Stores interference characterization level, 0 being lowest and 3 being highest.

Sensor node data structure.

uint8_t

Bit that can be set to disable entrance to sleep, overriding timers.

uint8_t

Size of the sensor node struct, should only be changed at compile time by editing DEF_NUM_SENSORS.

uint8_t

Size of raw data buffers within sensor node struct elements, should not be changed.

uint8_t

Sets the number of consecutive values above/below threshold before button is qualified/disqualified.

uint16_t

Sets the scan period in ms for active mode scanning. Defaults to DEF_ACTIVE_MODE_PERIOD.

uint16_t

Describes average interference seen as a percentage of the average touch delta.

uint16_t

Sets the scan period in ms for sleep mode scanning. Defaults to DEF_ACTIVE_MODE_PERIOD.

uint16_t

Sets the number of consecutive scans without a single qualified touch before entering sleep mode.

uint8_t

Configures whether system goes to sleep between scans in active mode.

uint8_t

Sets whether the system is allowed to ever use sleep mode scanning.

const uint8_t

Array storring percentages within touch deltas below which touch release events are qualified.

const uint8_t

Array storring percentages within touch deltas below which touch events are qualified.

const uint8_t

Array of expected conversion output codes between inactive and active sensor states.

Functions#

uint8_t

Checks to see if any enabled sensor is single active.

uint8_t

Checks if a sensor is single active.

uint8_t

Checks to see if any enabled sensor is debounce active.

uint8_t

Checks if a sensor is debounce active.

void
CSLIB_nodePushRaw(uint8_t index, uint32_t newValue)

Pushes new sensor sample into sensor node buffer.

uint16_t
CSLIB_nodeGetRaw(uint8_t sensorIndex, uint8_t bufferIndex)

Reads a node structure sensor's raw buffer value.

int16_t

Read touch delta from sensor node struct and expand from 8-bit value.

void
CSLIB_resetSensorStruct(uint8_t sensorIndex, uint16_t fillValue)

Resets an element of the sensor node struct back to defaults.

void

Initializes capacitive sensing-related peripherals.

void

Initializes capacitive sensing state variables.

void

Scans capacitive sensing inputs, processes and updates state variables.

uint32_t
CSLIB_scanSensorCB(uint8_t index)

Performs capacitive sensing conversion on a sensor.

void

Checks timing and possibly enters low power mode.

void

Checks timing and possibly enters low power mode.

void

Exits low power state for CSLIB.

uint16_t

Returns raw or filtered sensor data, based on characterized interference.

uint16_t
CSLIB_getNormalizedDelta(uint8_t sensor_index, uint16_t flood_level)

Get baseline-adjusted, noise-adjusted touch delta.

void

Callback to configure sensors for sleep mode.

void

Callback to confiure sensors for active mode.

void

Configure timer for sleep mode.

void

Callback to configure timer for active mode scanning.

void

Callback to enter low power mode.

void

Check wake sources.

void

Modify capacitive sense config for baseline initialization.

void

Restore capacitive sensing config to operational state.

Macros#

#define

Defines the depth of the raw buffer. Note: this value should not be changed.

#define

Bit that is set when sensor is qualified active.

#define

Bit that is set when sensor is candidate active.

Enumeration Documentation#

CSLIB_noiseLevels#

CSLIB_noiseLevels

Defines all noise characterization states the CSLIB will use for characterization.

Enumerator
low

Interference should have negligible impact on sensing.

mid

Interference forces system to qualify touches conservatively.

high

Interference forces entrance into no confidence mode if enabled.


Definition at line 448 of file platform/middleware/cslib/inc/cslib.h

Variable Documentation#

timerTick#

uint8_t timerTick

Global counter incremented by the system timer.


Definition at line 391 of file platform/middleware/cslib/inc/cslib.h

noise_level#

uint8_t noise_level

Stores interference characterization level, 0 being lowest and 3 being highest.


Definition at line 394 of file platform/middleware/cslib/inc/cslib.h

CSLIB_node#

SensorStruct_t CSLIB_node[]

Sensor node data structure.


Definition at line 397 of file platform/middleware/cslib/inc/cslib.h

disable_sleep_and_stall#

uint8_t disable_sleep_and_stall

Bit that can be set to disable entrance to sleep, overriding timers.


Definition at line 400 of file platform/middleware/cslib/inc/cslib.h

CSLIB_numSensors#

uint8_t CSLIB_numSensors

Size of the sensor node struct, should only be changed at compile time by editing DEF_NUM_SENSORS.


Definition at line 403 of file platform/middleware/cslib/inc/cslib.h

CSLIB_sensorBufferSize#

uint8_t CSLIB_sensorBufferSize

Size of raw data buffers within sensor node struct elements, should not be changed.


Definition at line 406 of file platform/middleware/cslib/inc/cslib.h

CSLIB_buttonDebounce#

uint8_t CSLIB_buttonDebounce

Sets the number of consecutive values above/below threshold before button is qualified/disqualified.

Defaults to DEF_BUTTON_DEBOUNCE


Definition at line 410 of file platform/middleware/cslib/inc/cslib.h

CSLIB_activeModePeriod#

uint16_t CSLIB_activeModePeriod

Sets the scan period in ms for active mode scanning. Defaults to DEF_ACTIVE_MODE_PERIOD.


Definition at line 413 of file platform/middleware/cslib/inc/cslib.h

CSLIB_systemNoiseAverage#

uint16_t CSLIB_systemNoiseAverage

Describes average interference seen as a percentage of the average touch delta.

100 would mean that average sample to sample interference is equal to the average touch delta configured in the system.


Definition at line 418 of file platform/middleware/cslib/inc/cslib.h

CSLIB_sleepModePeriod#

uint16_t CSLIB_sleepModePeriod

Sets the scan period in ms for sleep mode scanning. Defaults to DEF_ACTIVE_MODE_PERIOD.


Definition at line 421 of file platform/middleware/cslib/inc/cslib.h

CSLIB_countsBeforeSleep#

uint16_t CSLIB_countsBeforeSleep

Sets the number of consecutive scans without a single qualified touch before entering sleep mode.


Definition at line 424 of file platform/middleware/cslib/inc/cslib.h

CSLIB_freeRunSetting#

uint8_t CSLIB_freeRunSetting

Configures whether system goes to sleep between scans in active mode.

1 means that the system is in free run mode and will not go to sleep. 0 means that the system will take a single scan within an active mode scan period and will then enter sleep once CSLIB_lowPowerUpdate() is called. The system will stay asleep until the next active mode scan period begins.


Definition at line 431 of file platform/middleware/cslib/inc/cslib.h

CSLIB_sleepModeEnable#

uint8_t CSLIB_sleepModeEnable

Sets whether the system is allowed to ever use sleep mode scanning.

If set to 0, the system will always remain in active mode. If set to 1, the system is allowed to perform sleep mode scanning when conditions permit it.


Definition at line 436 of file platform/middleware/cslib/inc/cslib.h

CSLIB_inactiveThreshold#

const uint8_t CSLIB_inactiveThreshold[]

Array storring percentages within touch deltas below which touch release events are qualified.


Definition at line 439 of file platform/middleware/cslib/inc/cslib.h

CSLIB_activeThreshold#

const uint8_t CSLIB_activeThreshold[]

Array storring percentages within touch deltas below which touch events are qualified.


Definition at line 442 of file platform/middleware/cslib/inc/cslib.h

CSLIB_averageTouchDelta#

const uint8_t CSLIB_averageTouchDelta[]

Array of expected conversion output codes between inactive and active sensor states.


Definition at line 445 of file platform/middleware/cslib/inc/cslib.h

Function Documentation#

CSLIB_anySensorSingleActive#

uint8_t CSLIB_anySensorSingleActive (void )

Checks to see if any enabled sensor is single active.

Parameters
N/A

This function checks the SINGLE_ACTIVE_MASK in the sensor node structure for all enabled sensors. If any sensor's SINGLE_ACTIVE_MASK is set, meaning that the sensor is a candidate active sensor, the the function returns TRUE. Otherwise it returns FALSE.

Returns

  • 1 if any sensor is active, 0 otherwise


Definition at line 112 of file platform/middleware/cslib/inc/cslib.h

CSLIB_isSensorSingleActive#

uint8_t CSLIB_isSensorSingleActive (uint8_t index)

Checks if a sensor is single active.

Parameters
N/Aindex

into sensor node element to be checked

This checks to see if any enabled sensor is a candidate active sensor.

Returns

  • 1 if element selected by index is single active, 0 otherwise


Definition at line 122 of file platform/middleware/cslib/inc/cslib.h

CSLIB_anySensorDebounceActive#

uint8_t CSLIB_anySensorDebounceActive (void )

Checks to see if any enabled sensor is debounce active.

Parameters
N/A

Checks to see if any enabled sensor is qualified active, meaning that the data from the sensor on this input has risen above the active threshold for a consecutive number of samples equaling at least the value defined by DEF_DEBOUNCE_COUNTS.

Returns

  • 1 if any enabled sensor is debounce active, 0 otherwise


Definition at line 134 of file platform/middleware/cslib/inc/cslib.h

CSLIB_isSensorDebounceActive#

uint8_t CSLIB_isSensorDebounceActive (uint8_t index)

Checks if a sensor is debounce active.

Parameters
N/Aindex

into sensor node element to be checked

This checks to see if any enabled sensor is a qualified active sensor.

Returns

  • 1 if element selected by index is debounce active, 0 otherwise


Definition at line 144 of file platform/middleware/cslib/inc/cslib.h

CSLIB_nodePushRaw#

void CSLIB_nodePushRaw (uint8_t index, uint32_t newValue)

Pushes new sensor sample into sensor node buffer.

Parameters
N/Aindex

index into sensor node array

N/AnewValue

value to be pushed at index

This function is used by the device layer of code that interfaces with capacitive sensing hardware. When CSLIB_update() calls into the device layer to convert a new sample set using CSLIB_scanSensorCB(), the device layer implementation of CSLIB_scanSensorCB should use this routine to push newly converted samples into the sensor node structure for processing within the library.


Definition at line 159 of file platform/middleware/cslib/inc/cslib.h

CSLIB_nodeGetRaw#

uint16_t CSLIB_nodeGetRaw (uint8_t sensorIndex, uint8_t bufferIndex)

Reads a node structure sensor's raw buffer value.

Parameters
N/AsensorIndex

The element of the sensor node structure

N/AbufferIndex

The element inside the sensor node element's raw data buffer

This function can be used to read values in the raw data buffer at bufferIndex of an enabled sensor specified by sensorIndex.

Note

Returns

  • the value in the raw data buffer


Definition at line 174 of file platform/middleware/cslib/inc/cslib.h

CSLIB_getUnpackedTouchDelta#

int16_t CSLIB_getUnpackedTouchDelta (uint8_t index)

Read touch delta from sensor node struct and expand from 8-bit value.

Parameters
N/Aindex

Designates the sensor touch delta to be read

This function returns the 8-bit compressed touch delta as an uncompressed 16 bit value.

Returns

  • 16-bit signed touch delta value of a sensor defined by index


Definition at line 185 of file platform/middleware/cslib/inc/cslib.h

CSLIB_resetSensorStruct#

void CSLIB_resetSensorStruct (uint8_t sensorIndex, uint16_t fillValue)

Resets an element of the sensor node struct back to defaults.

Parameters
N/AsensorIndex

index of sensor node struct to reset

N/AfillValue

value to be used when filling raw data buffer

This function is called during initialization to reset the sensor at node sensorIndex back to back to its power-on state.


Definition at line 196 of file platform/middleware/cslib/inc/cslib.h

CSLIB_initHardware#

void CSLIB_initHardware (void )

Initializes capacitive sensing-related peripherals.

Parameters
N/A

This function calls into the library, which in turn calls into the device layer functions initializing the sensing and timing hardware used during capacitive sensing conversions.


Definition at line 206 of file platform/middleware/cslib/inc/cslib.h

CSLIB_initLibrary#

void CSLIB_initLibrary (void )

Initializes capacitive sensing state variables.

Parameters
N/A

This function resets all state variables in the sensor node struct and library-internal state variables to default.


Definition at line 215 of file platform/middleware/cslib/inc/cslib.h

CSLIB_update#

void CSLIB_update (void )

Scans capacitive sensing inputs, processes and updates state variables.

Parameters
N/A

This function should be called in a firmware project's main() loop. The function will execute a capacitive sensing scan sequence, filter samples, examine samples for qualified touches, and update other state variables.


Definition at line 225 of file platform/middleware/cslib/inc/cslib.h

CSLIB_scanSensorCB#

uint32_t CSLIB_scanSensorCB (uint8_t index)

Performs capacitive sensing conversion on a sensor.

Parameters
N/Aindex

The sensor to be scanned, corresponds to sensor node struct

This device layer function is called from within library code after CSLIB_update() is called in the main loop. The function is responsible for any configuration of the capacitive sensing block necessary to perform the scan.

Returns

  • the newly converted capacitive sensing output


Definition at line 238 of file platform/middleware/cslib/inc/cslib.h

CSLIB_lowPowerUpdate#

void CSLIB_lowPowerUpdate (void )

Checks timing and possibly enters low power mode.

Parameters
N/A

This function checks the time in the system relative to active mode scan period timing. It should be called in the firmware project's main() while(1) loop.

If FREE_RUN_SETTING is set to 0, the function will enter low power until the next active mode scan period.

If FREE_RUN_SETTING is set to 1, the function will exit, allowing for another iteration in the main() loop.

If CSLIB_lowPowerUpdate() finds that no qualified touches have been found in a time specified by COUNTS_BEFORE_SLEEP multiplied by ACTIVE_MODE_SCAN_PERIOD, the function initializes the system to run in its sleep scanning mode and enters a low power state.


Definition at line 259 of file platform/middleware/cslib/inc/cslib.h

CSLIB_lowPowerUpdateCheckAppBuilder#

void CSLIB_lowPowerUpdateCheckAppBuilder (void )

Checks timing and possibly enters low power mode.

Parameters
N/A

This function checks the time in the system relative to active mode scan period timing.

If CSLIB_lowPowerUpdate() finds that no qualified touches have been found in a time specified by COUNTS_BEFORE_SLEEP multiplied by ACTIVE_MODE_SCAN_PERIOD, the function initializes the system to run in its sleep scanning mode. The calling system stack will intiate low power entry.


Definition at line 274 of file platform/middleware/cslib/inc/cslib.h

CSLIB_lowPowerUpdateExitAppBuilder#

void CSLIB_lowPowerUpdateExitAppBuilder (void )

Exits low power state for CSLIB.

Parameters
N/A

This function is called by the interface layer when it detects a threshold crossing interrupt. The function will return to normal CSLIB operation.


Definition at line 283 of file platform/middleware/cslib/inc/cslib.h

CSLIB_getNoiseAdjustedSensorData#

uint16_t CSLIB_getNoiseAdjustedSensorData (uint8_t index)

Returns raw or filtered sensor data, based on characterized interference.

Parameters
N/Aindex

Sensor node element whose data is to be read

This function either returns the newest raw data for a sensor, or the newest filtered data for a sensor, depending on which data type the interference characterization algorithm determines to be necessary to show current sensor state. In low interference environments, raw data will be returned. In higher interference states, filtered data will be returned.

Returns

  • sensor data from sensor node struct defined index


Definition at line 298 of file platform/middleware/cslib/inc/cslib.h

CSLIB_getNormalizedDelta#

uint16_t CSLIB_getNormalizedDelta (uint8_t sensor_index, uint16_t flood_level)

Get baseline-adjusted, noise-adjusted touch delta.

Parameters
N/Asensor_index

Index into sensor node struct

N/Aflood_level

additional value that can be subtracted in addition to baseline

Returns value that is raw or filtered data minus the sensor's baseline. flood_level can be used to remove additional margin along with baseline.

Returns

  • Absolute delta between baseline and raw/filtered data


Definition at line 312 of file platform/middleware/cslib/inc/cslib.h

CSLIB_configureSensorForSleepModeCB#

void CSLIB_configureSensorForSleepModeCB (void )

Callback to configure sensors for sleep mode.

Parameters
N/A

Callback routine used if low power mode is included in build, this function configures the capacitive sensing block and inputs for sleep mode.


Definition at line 321 of file platform/middleware/cslib/inc/cslib.h

CSLIB_configureSensorForActiveModeCB#

void CSLIB_configureSensorForActiveModeCB (void )

Callback to confiure sensors for active mode.

Parameters
N/A

Callback routine to configure sensors for active mode scanning.


Definition at line 329 of file platform/middleware/cslib/inc/cslib.h

CSLIB_configureTimerForSleepModeCB#

void CSLIB_configureTimerForSleepModeCB (void )

Configure timer for sleep mode.

Parameters
N/A

If low power mode is included in build, this function sets the wake-up event to the sleep mode scan period.


Definition at line 338 of file platform/middleware/cslib/inc/cslib.h

CSLIB_configureTimerForActiveModeCB#

void CSLIB_configureTimerForActiveModeCB (void )

Callback to configure timer for active mode scanning.

Parameters
N/A

Configures the timer to initiate a scan as defined by active mode scan period.


Definition at line 346 of file platform/middleware/cslib/inc/cslib.h

CSLIB_enterLowPowerStateCB#

void CSLIB_enterLowPowerStateCB (void )

Callback to enter low power mode.

Parameters
N/A

If low power mode is included in build, this function mode-switches the core to a low power state.


Definition at line 355 of file platform/middleware/cslib/inc/cslib.h

CSLIB_checkTimerCB#

void CSLIB_checkTimerCB (void )

Check wake sources.

Parameters
N/A

This function examines the system timer to check for wake events.

This callback function examines the system timer to check for wake events.


Definition at line 363 of file platform/middleware/cslib/inc/cslib.h

CSLIB_baselineInitEnableCB#

void CSLIB_baselineInitEnableCB (void )

Modify capacitive sense config for baseline initialization.

Parameters
N/A

Saves configuration state and makes device-level modifications appropriate to baseline initialization using the CSLIB_scanSensorCB() function.


Definition at line 372 of file platform/middleware/cslib/inc/cslib.h

CSLIB_baselineInitDisableCB#

void CSLIB_baselineInitDisableCB (void )

Restore capacitive sensing config to operational state.

Parameters
N/A

This function reverts any baseline-related capactive sensing config.


Definition at line 380 of file platform/middleware/cslib/inc/cslib.h

Macro Definition Documentation#

DEF_SENSOR_BUFFER_SIZE#

#define DEF_SENSOR_BUFFER_SIZE
Value:
2

Defines the depth of the raw buffer. Note: this value should not be changed.


Definition at line 65 of file platform/middleware/cslib/inc/cslib.h

DEBOUNCE_ACTIVE_MASK#

#define DEBOUNCE_ACTIVE_MASK
Value:
0x80

Bit that is set when sensor is qualified active.


Definition at line 68 of file platform/middleware/cslib/inc/cslib.h

SINGLE_ACTIVE_MASK#

#define SINGLE_ACTIVE_MASK
Value:
0x40

Bit that is set when sensor is candidate active.


Definition at line 71 of file platform/middleware/cslib/inc/cslib.h