Skip to content

Commit c576811

Browse files
committed
Merge branch 'feat/touch_slider' into 'master'
feat: add touch slider component See merge request ae_group/esp-iot-solution!1277
2 parents 654e690 + bec4003 commit c576811

32 files changed

+2010
-3
lines changed

.github/workflows/upload_component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ jobs:
8787
components/touch/touch_button;
8888
components/touch/touch_button_sensor;
8989
components/touch/touch_proximity_sensor;
90+
components/touch/touch_slider_sensor;
9091
components/usb/esp_msc_ota;
9192
components/usb/esp_tinyuf2;
9293
components/usb/iot_usbh;

.gitlab/ci/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,18 @@ build_example_touch_button_sensor:
736736
variables:
737737
EXAMPLE_DIR: examples/touch/touch_button_sensor
738738

739+
build_example_touch_slider_sensor:
740+
extends:
741+
- .build_examples_template
742+
- .rules:build:example_touch_touch_slider_sensor
743+
parallel:
744+
matrix:
745+
- IMAGE: espressif/idf:release-v4.4
746+
- IMAGE: espressif/idf:release-v5.1
747+
- IMAGE: espressif/idf:release-v5.4
748+
variables:
749+
EXAMPLE_DIR: examples/touch/touch_slider_sensor
750+
739751
build_example_touch_touch_proximity:
740752
extends:
741753
- .build_examples_template
@@ -1567,6 +1579,16 @@ build_components_touch_touch_button_sensor_test_apps:
15671579
variables:
15681580
EXAMPLE_DIR: components/touch/touch_button_sensor/test_apps
15691581

1582+
build_components_touch_touch_slider_sensor_test_apps:
1583+
extends:
1584+
- .build_examples_template
1585+
- .rules:build:components_touch_touch_slider_sensor_test_apps
1586+
parallel:
1587+
matrix:
1588+
- IMAGE: espressif/idf:release-v5.3
1589+
variables:
1590+
EXAMPLE_DIR: components/touch/touch_slider_sensor/test_apps
1591+
15701592
build_components_usb_esp_msc_ota_test_apps:
15711593
extends:
15721594
- .build_examples_template

.gitlab/ci/rules.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@
295295
- "components/touch/touch_button_sensor/**/*"
296296
- "tools/cmake_utilities/package_manager.cmake"
297297

298+
.patterns-components_touch_touch_slider_sensor: &patterns-components_touch_touch_slider_sensor
299+
- "components/touch/touch_slider_sensor/**/*"
300+
- "tools/cmake_utilities/package_manager.cmake"
301+
298302
.patterns-components_usb_esp_msc_ota: &patterns-components_usb_esp_msc_ota
299303
- "components/usb/esp_msc_ota/**/*"
300304
- "tools/cmake_utilities/package_manager.cmake"
@@ -560,6 +564,9 @@
560564
.patterns-example_touch_touch_proximity: &patterns-example_touch_touch_proximity
561565
- "examples/touch/touch_proximity/**/*"
562566

567+
.patterns-example_touch_touch_slider: &patterns-example_touch_touch_slider
568+
- "examples/touch/touch_slider_sensor/**/*"
569+
563570
.patterns-example_ulp_lp_cpu_lp_environment_sensor: &patterns-example_ulp_lp_cpu_lp_environment_sensor
564571
- "examples/ulp/lp_cpu/lp_environment_sensor/**/*"
565572

@@ -1344,6 +1351,17 @@
13441351
- <<: *if-dev-push
13451352
changes: *patterns-components_touch_touch_proximity_sensor
13461353

1354+
.rules:build:example_touch_touch_slider_sensor:
1355+
rules:
1356+
- <<: *if-protected
1357+
- <<: *if-label-build
1358+
- <<: *if-dev-push
1359+
changes: *patterns-build_system
1360+
- <<: *if-dev-push
1361+
changes: *patterns-example_touch_touch_slider
1362+
- <<: *if-dev-push
1363+
changes: *patterns-components_touch_touch_slider_sensor
1364+
13471365
.rules:build:example_ulp_lp_cpu_lp_environment_sensor:
13481366
rules:
13491367
- <<: *if-protected
@@ -2422,6 +2440,17 @@
24222440
- <<: *if-dev-push
24232441
changes: *patterns-components_touch_touch_button_sensor
24242442

2443+
.rules:build:components_touch_touch_slider_sensor_test_apps:
2444+
rules:
2445+
- <<: *if-protected
2446+
- <<: *if-label-build
2447+
- <<: *if-label-target_test
2448+
- <<: *if-trigger-job
2449+
- <<: *if-dev-push
2450+
changes: *patterns-build_system
2451+
- <<: *if-dev-push
2452+
changes: *patterns-components_touch_touch_slider_sensor
2453+
24252454
.rules:build:components_usb_esp_msc_ota_test_apps:
24262455
rules:
24272456
- <<: *if-protected

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ The registered components in ESP-IoT-Solution are listed below:
132132
| [touch_button](https://components.espressif.com/components/espressif/touch_button) | [![Component Registry](https://components.espressif.com/components/espressif/touch_button/badge.svg)](https://components.espressif.com/components/espressif/touch_button) |
133133
| [touch_button_sensor](https://components.espressif.com/components/espressif/touch_button_sensor) | [![Component Registry](https://components.espressif.com/components/espressif/touch_button_sensor/badge.svg)](https://components.espressif.com/components/espressif/touch_button_sensor) |
134134
| [touch_proximity_sensor](https://components.espressif.com/components/espressif/touch_proximity_sensor) | [![Component Registry](https://components.espressif.com/components/espressif/touch_proximity_sensor/badge.svg)](https://components.espressif.com/components/espressif/touch_proximity_sensor) |
135+
| [touch_slider_sensor](https://components.espressif.com/components/espressif/touch_slider_sensor) | [![Component Registry](https://components.espressif.com/components/espressif/touch_slider_sensor/badge.svg)](https://components.espressif.com/components/espressif/touch_slider_sensor) |
135136
| [usb_device_uac](https://components.espressif.com/components/espressif/usb_device_uac) | [![Component Registry](https://components.espressif.com/components/espressif/usb_device_uac/badge.svg)](https://components.espressif.com/components/espressif/usb_device_uac) |
136137
| [usb_device_uvc](https://components.espressif.com/components/espressif/usb_device_uvc) | [![Component Registry](https://components.espressif.com/components/espressif/usb_device_uvc/badge.svg)](https://components.espressif.com/components/espressif/usb_device_uvc) |
137138
| [usb_stream](https://components.espressif.com/components/espressif/usb_stream) | [![Component Registry](https://components.espressif.com/components/espressif/usb_stream/badge.svg)](https://components.espressif.com/components/espressif/usb_stream) |

README_CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ ESP-IoT-Solution 中注册的组件如下:
132132
| [touch_button](https://components.espressif.com/components/espressif/touch_button) | [![Component Registry](https://components.espressif.com/components/espressif/touch_button/badge.svg)](https://components.espressif.com/components/espressif/touch_button) |
133133
| [touch_button_sensor](https://components.espressif.com/components/espressif/touch_button_sensor) | [![Component Registry](https://components.espressif.com/components/espressif/touch_button_sensor/badge.svg)](https://components.espressif.com/components/espressif/touch_button_sensor) |
134134
| [touch_proximity_sensor](https://components.espressif.com/components/espressif/touch_proximity_sensor) | [![Component Registry](https://components.espressif.com/components/espressif/touch_proximity_sensor/badge.svg)](https://components.espressif.com/components/espressif/touch_proximity_sensor) |
135+
| [touch_slider_sensor](https://components.espressif.com/components/espressif/touch_slider_sensor) | [![Component Registry](https://components.espressif.com/components/espressif/touch_slider_sensor/badge.svg)](https://components.espressif.com/components/espressif/touch_slider_sensor) |
135136
| [usb_device_uac](https://components.espressif.com/components/espressif/usb_device_uac) | [![Component Registry](https://components.espressif.com/components/espressif/usb_device_uac/badge.svg)](https://components.espressif.com/components/espressif/usb_device_uac) |
136137
| [usb_device_uvc](https://components.espressif.com/components/espressif/usb_device_uvc) | [![Component Registry](https://components.espressif.com/components/espressif/usb_device_uvc/badge.svg)](https://components.espressif.com/components/espressif/usb_device_uvc) |
137138
| [usb_stream](https://components.espressif.com/components/espressif/usb_stream) | [![Component Registry](https://components.espressif.com/components/espressif/usb_stream/badge.svg)](https://components.espressif.com/components/espressif/usb_stream) |

components/.build-rules.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ components/touch/touch_proximity_sensor/test_apps:
2525
enable:
2626
- if: IDF_TARGET in ["esp32s3"]
2727

28+
components/touch/touch_slider_sensor/test_apps:
29+
enable:
30+
- if: IDF_TARGET in ["esp32", "esp32s2", "esp32s3", "esp32p4"] and (IDF_VERSION_MAJOR == 5 and IDF_VERSION_MINOR == 3)
31+
2832
components/usb/esp_msc_ota/test_apps:
2933
enable:
3034
- if: IDF_TARGET in ["esp32s3"]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ChangeLog
2+
3+
## v0.1.0 - 2025-04-27
4+
5+
* Add Initial version
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
idf_component_register(SRC_DIRS "."
2+
INCLUDE_DIRS "include")
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
menu "Touch Slider Sensor Configuration"
2+
3+
config TOUCH_SLIDER_SENSOR_DEBUG
4+
bool "Enable touch slider sensor debug mode"
5+
default n
6+
help
7+
Enable touch slider sensor debug mode.
8+
9+
config TOUCH_SLIDER_SENSOR_CALIBRATION_TIMES
10+
int "Calibration times"
11+
default 50 if !IDF_TARGET_ESP32
12+
default 20
13+
range 10 1000
14+
help
15+
Number of readings used for initial calibration.
16+
17+
config TOUCH_SLIDER_SENSOR_DEBOUNCE_INACTIVE
18+
int "Debounce inactive count"
19+
default 3 if !IDF_TARGET_ESP32
20+
default 1
21+
range 1 50
22+
help
23+
Number of consecutive readings below threshold needed to confirm inactive state.
24+
25+
config TOUCH_SLIDER_SENSOR_POLLING_INTERVAL
26+
int "Polling interval (ms)"
27+
default 10
28+
range 5 100
29+
depends on IDF_TARGET_ESP32
30+
help
31+
Interval between polling touch readings in milliseconds (for ESP32 only).
32+
33+
config TOUCH_SLIDER_SENSOR_SMOOTH_COEF_X1000
34+
int "Smooth coefficient (/1000)"
35+
default 200 if IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32S2
36+
default 300 if IDF_TARGET_ESP32
37+
default 600 if IDF_TARGET_ESP32P4
38+
default 500
39+
range 0 1000
40+
help
41+
Coefficient for smooth filter, multiplied by 1000.
42+
For example, 200 means 0.2
43+
44+
config TOUCH_SLIDER_SENSOR_BASELINE_COEF_X1000
45+
int "Baseline coefficient (/1000)"
46+
default 100 if IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32S2
47+
default 150 if IDF_TARGET_ESP32
48+
default 200 if IDF_TARGET_ESP32P4
49+
default 100
50+
range 0 1000
51+
help
52+
Coefficient for baseline filter, multiplied by 1000.
53+
For example, 100 means 0.1
54+
55+
config TOUCH_SLIDER_SENSOR_MAX_P_X1000
56+
int "Maximum positive change ratio (/1000)"
57+
default 200
58+
range 0 1000
59+
help
60+
Maximum positive change ratio from baseline, multiplied by 1000.
61+
For example, 200 means 0.2. 0 means no limit.
62+
63+
config TOUCH_SLIDER_SENSOR_MIN_N_X1000
64+
int "Minimum negative change ratio (/1000)"
65+
default 200
66+
range 0 1000
67+
help
68+
Minimum negative change ratio from baseline, multiplied by 1000.
69+
For example, 200 means 0.2. 0 means no limit.
70+
71+
config TOUCH_SLIDER_SENSOR_NEGATIVE_LOGIC
72+
bool "Using negative logic to detect touch"
73+
default n
74+
help
75+
Using both positive and negative threshold to detect touch.
76+
77+
config TOUCH_SLIDER_SENSOR_NOISE_P_SNR
78+
int "Positive noise SNR"
79+
default 4
80+
range 3 100
81+
help
82+
Signal-to-noise for positive Noise
83+
84+
config TOUCH_SLIDER_SENSOR_NOISE_N_SNR
85+
int "Negative noise SNR"
86+
default 4
87+
range 2 100
88+
help
89+
Signal-to-noise for negative Noise
90+
91+
config TOUCH_SLIDER_SENSOR_RESET_COVER
92+
int "Reset count from cover"
93+
default 1000 if !IDF_TARGET_ESP32
94+
default 300
95+
range 0 5000
96+
help
97+
Reset count if cover is detected. 0 means no reset.
98+
99+
config TOUCH_SLIDER_SENSOR_RESET_CALIBRATION
100+
int "Reset count from calibration error"
101+
default 3
102+
range 0 100
103+
help
104+
Reset count for negative threshold. 0 means no reset.
105+
106+
config TOUCH_SLIDER_SENSOR_RAW_BUF_SIZE
107+
int "Raw buffer size"
108+
default 40 if !IDF_TARGET_ESP32
109+
default 10
110+
range 10 100
111+
help
112+
Size of raw data buffer.
113+
114+
config TOUCH_SLIDER_SENSOR_SCALE_FACTOR
115+
int "Scale factor"
116+
default 100 if !IDF_TARGET_ESP32
117+
default 1000
118+
range 10 1000
119+
help
120+
Scale factor for threshold calculation.
121+
122+
config TOUCH_SLIDER_SENSOR_QUANTIFY_LOWER_THRESHOLD_X1000
123+
int "Quantify lower threshold (/1000)"
124+
default 300
125+
range 0 10000
126+
help
127+
Ratio of activation to quantify as 0.
128+
129+
config TOUCH_SLIDER_SENSOR_BENCHMARK_UPDATE_TIME
130+
int "Benchmark update time"
131+
default 500
132+
range 100 10000
133+
help
134+
Delay after sensor is released before benchmark is updated.
135+
136+
config TOUCH_SLIDER_SENSOR_POS_FILTER_SIZE
137+
int "Position filter size"
138+
default 10
139+
range 1 100
140+
help
141+
Window size of slider position IIR filter.
142+
143+
config TOUCH_SLIDER_SENSOR_POS_FILTER_FACTOR
144+
int "Position filter factor"
145+
default 2
146+
range 1 10
147+
help
148+
Divisor of slider position IIR filter.
149+
150+
config TOUCH_SLIDER_SENSOR_CALCULATE_CHANNEL
151+
int "Position calculation window"
152+
default 3
153+
range 1 10
154+
help
155+
Number of channels in position calculation
156+
endmenu
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Touch Slider Sensor
2+
3+
**Note:** This component is for developers testing only. It is not intended for production use.
4+
5+
A component providing enhanced touch slider detection functionality for ESP32 series chips.
6+
7+
## Features
8+
9+
- FSM-based touch detection with configurable thresholds
10+
- Support for slider gesture detection
11+
- Callback-based event notification
12+
13+
## Dependencies
14+
15+
- [touch_sensor_fsm](https://components.espressif.com/components/espressif/touch_sensor_fsm)
16+
- [touch_sensor_lowlevel](https://components.espressif.com/components/espressif/touch_sensor_lowlevel)
17+
18+
19+
## Example
20+
21+
```c
22+
#include <stdio.h>
23+
#include <inttypes.h>
24+
#include "freertos/FreeRTOS.h"
25+
#include "freertos/task.h"
26+
#include "touch_slider_sensor.h"
27+
28+
static uint32_t channel_list[] = {2, 4, 6, 12, 10, 8};
29+
static float threshold[] = {0.005f, 0.005f, 0.005f, 0.005f, 0.005f, 0.005f};
30+
static int channel_num = 6;
31+
static int slider_range = 10000;
32+
33+
static void touch_slider_event_callback(touch_slider_handle_t handle, touch_slider_event_t event, int32_t data, void *cb_arg)
34+
{
35+
if (event == TOUCH_SLIDER_EVENT_RIGHT_SWIPE) {
36+
printf("Right swipe (speed)\n");
37+
} else if (event == TOUCH_SLIDER_EVENT_LEFT_SWIPE) {
38+
printf("Left swipe (speed)\n");
39+
} else if (event == TOUCH_SLIDER_EVENT_RELEASE) {
40+
printf("Slide %" PRId32 "\n", data);
41+
if (data > slider_range / 10) {
42+
printf("Right swipe (displacement)\n");
43+
} else if (data < -slider_range / 10) {
44+
printf("Left swipe (displacement)\n");
45+
}
46+
} else if (event == TOUCH_SLIDER_EVENT_POSITION) {
47+
printf("pos,%" PRId32 "\n", data);
48+
}
49+
}
50+
/* Task function to handle touch slider events */
51+
static void touch_slider_task(void *pvParameters)
52+
{
53+
touch_slider_handle_t handle = (touch_slider_handle_t)pvParameters;
54+
while (1) {
55+
touch_slider_sensor_handle_events(handle);
56+
vTaskDelay(pdMS_TO_TICKS(20));
57+
}
58+
}
59+
60+
void app_main(void)
61+
{
62+
touch_slider_config_t config = {
63+
.channel_num = channel_num,
64+
.channel_list = channel_list,
65+
.channel_threshold = threshold,
66+
.filter_reset_times = 5,
67+
.position_range = 10000,
68+
.swipe_alpha = 0.9,
69+
.swipe_threshold = 50,
70+
.swipe_hysterisis = 40,
71+
.channel_gold_value = NULL,
72+
.debounce_times = 0,
73+
.skip_lowlevel_init = false
74+
};
75+
76+
touch_slider_handle_t handle;
77+
ESP_ERROR_CHECK(touch_slider_sensor_create(&config, &handle, touch_slider_event_callback, NULL));
78+
79+
// Create a task to handle touch slider events
80+
xTaskCreate(touch_slider_task, "touch_slider_sensor", 3072, handle, 2, NULL);
81+
82+
// Main loop can do other things now
83+
while (1) {
84+
vTaskDelay(pdMS_TO_TICKS(1000)); // Main task can do other work or just idle
85+
}
86+
}
87+
```

0 commit comments

Comments
 (0)