Touch Sensor
Introduction
The touch sensor system consists of a protective cover layer, touch electrodes, an insulating substrate, and wiring. The protective cover layer is at the topmost layer, with electrodes and wiring on the insulating substrate. Touching the cover layer causes capacitance changes. Based on these changes, it can be determined whether the touch is a valid touch action.
Function List
Initialize - Initialize the touch sensor driver.
Set Threshold - Set the threshold for the touch sensor.
Get Threshold - Get the threshold of the touch sensor.
Read Count - Read the count value of the touch sensor.
Start Sensor - Start the touch sensor.
Stop Sensor - Stop the touch sensor.
Register Callback - Register a callback function for the touch sensor.
Feature Overview
W803 integrates a touch sensor module that scans the status of each touch button in sequence at regular intervals when working. It counts and records the status of each button within the set time window. If it exceeds the set threshold, the button is considered to be touched, and application processing is done through polling or interrupts.
The current software adjustable parameter is only the touch threshold (adjustable range: 0-127). It can be adjusted to a most suitable value according to the actual environment.
W803 has a total of 10 available TOUCH touch pins and two control pins. The relationship of the touch sensor pins is shown in the table below.
Touch Sensor Number (Name) |
Pin Number |
Pin Name |
Pin Multiplex Function |
Pin Attribute |
TOUCH3 |
PIN_NUM_16 |
PB0 |
OPT7 |
float/input |
TOUCH4 |
PIN_NUM_17 |
PB1 |
OPT7 |
float/input |
TOUCH5 |
PIN_NUM_18 |
PB2 |
OPT7 |
float/input |
TOUCH6 |
PIN_NUM_19 |
PB3 |
OPT7 |
float/input |
TOUCH7 |
PIN_NUM_20 |
PB4 |
OPT7 |
float/input |
TOUCH8 |
PIN_NUM_21 |
PB5 |
OPT7 |
float/input |
TOUCH9 |
PIN_NUM_22 |
PB6 |
OPT7 |
float/input |
TOUCH10 |
PIN_NUM_23 |
PB7 |
OPT7 |
float/input |
TOUCH11 |
PIN_NUM_24 |
PB8 |
OPT7 |
float/input |
TOUCH12 |
PIN_NUM_25 |
PB9 |
OPT7 |
float/input |
CMOD |
PIN_NUM_12 |
PA12 |
OPT7 |
float/input |
CDC |
PIN_NUM_14 |
PA14 |
OPT7 |
float/input |
The touch sensor circuit design reference is shown in the table below.
The touch sensor can be combined in matrix or slider formats to cover larger touch areas and more touch points.
Main Features
Initialize Touch Sensor
To use the touch sensor, you need to call the
wm_drv_touch_sensor_init()
function to initialize the driver. Example:wm_device_t *touch_dev; touch_dev = wm_drv_touch_sensor_init("touch_sensor");
Set Threshold
To set the threshold of the touch sensor, you can call the
wm_drv_touch_sensor_set_threshold()
function. Example:wm_device_t *touch_dev; touch_dev = wm_drv_touch_sensor_init("touch_sensor"); wm_drv_touch_sensor_set_threshold(touch_dev, WM_TOUCH_SENSOR_NUM_1, 100);
Get Threshold
To get the threshold of the touch sensor, you can call the
wm_drv_touch_sensor_get_threshold()
function. Example:wm_device_t *touch_dev; touch_dev = wm_drv_touch_sensor_init("touch_sensor"); uint32_t threshold; wm_drv_touch_sensor_get_threshold(touch_dev, WM_TOUCH_SENSOR_NUM_1, &threshold);
Read Count
To read the count value of the touch sensor, you can call the
wm_drv_touch_sensor_read_countnum()
function. Example:wm_device_t *touch_dev; touch_dev = wm_drv_touch_sensor_init("touch_sensor"); uint32_t countnum; wm_drv_touch_sensor_read_countnum(touch_dev, 0, &countnum);
Start Sensor
To start the touch sensor, you can call the
wm_drv_touch_sensor_start()
function. Example:wm_device_t *touch_dev; touch_dev = wm_drv_touch_sensor_init("touch_sensor"); wm_drv_touch_sensor_start(touch_dev, WM_TOUCH_SENSOR_NUM_1);
Stop Sensor
To stop the touch sensor, you can call the
wm_drv_touch_sensor_stop()
function. Example:wm_device_t *touch_dev; touch_dev = wm_drv_touch_sensor_init("touch_sensor"); wm_drv_touch_sensor_stop(touch_dev, WM_TOUCH_SENSOR_NUM_1);
Register Callback
To register a callback function for the touch sensor, you can call the
wm_drv_touch_sensor_register_callback()
function. Example:wm_device_t *touch_dev; touch_dev = wm_drv_touch_sensor_init("touch_sensor"); void touch_callback(wm_touch_sensor_num_t touch_num, void *priv) { } wm_drv_touch_sensor_register_callback(touch_dev, WM_TOUCH_SENSOR_NUM_1, touch_callback, NULL);
Deinitialize Touch Sensor
When the touch sensor is no longer needed, you can call the
wm_drv_touch_sensor_deinit()
function to deinitialize the driver and release resources. Example:wm_device_t *touch_dev; touch_dev = wm_drv_touch_sensor_init("touch_sensor"); wm_drv_touch_sensor_deinit(touch_dev);
Application Examples
For basic examples of using the touch sensor, please refer to: examples/peripheral/touch_sensor
API Reference
Touch Button touch button
Touch Slider (Not yet implemented)
Touch Matrix Button (Not yet implemented)