driver(touchpad): improve touchpad filter mode and update examples.

This commit is contained in:
Wangjialin
2018-05-18 15:56:45 +08:00
committed by fuzhibo
parent 993b8b7bf6
commit 09181b7d94
6 changed files with 221 additions and 131 deletions

View File

@@ -11,69 +11,37 @@
#include "freertos/task.h"
#include "driver/touch_pad.h"
#define TOUCH_TEST_LOOP_NUM (10)
#define TOUCH_PAD_NO_CHANGE (-1)
#define TOUCH_THRESH_NO_USE (0)
#define TOUCH_FILTER_MODE_EN (1)
#define TOUCHPAD_FILTER_TOUCH_PERIOD (10)
/*
Read values sensed at all available touch pads.
Print out values in a loop on a serial monitor.
*/
static void tp_example_read_task(void *pvParameter)
{
uint16_t touch_value;
uint16_t touch_filter_value;
#if TOUCH_FILTER_MODE_EN
printf("Touch Sensor filter mode read, the output format is: \nTouchpad num:[raw data, filtered data]\n\n");
#else
printf("Touch Sensor normal mode read, the output format is: \nTouchpad num:[raw data]\n\n");
#endif
while (1) {
uint16_t touch_value;
//set reference voltage for charging/discharging
// In this case, the high reference valtage will be 2.7V - 0V = 2.7V
// The low reference voltage will be 0.5
// So the charing/discharging time would be longer, so the counter value would be smaller.
touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V);
vTaskDelay(100 / portTICK_PERIOD_MS);
printf("Case[1], set default measure time\n");
for (int j = 0; j < TOUCH_TEST_LOOP_NUM; j++) {
for (int i = 0; i < TOUCH_PAD_MAX; i++) {
ESP_ERROR_CHECK(touch_pad_read(i, &touch_value));
printf("T%d:%5d ", i, touch_value);
}
printf("\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
printf("Case[2], set max measure time\n");
//set reference voltage for charging/discharging
// In this case, the high reference valtage will be 2.4V - 1.5V = 0.9V
// The low reference voltage will be 0.8
// So the charing/discharging time would be shorter, so the counter value would be larger.
touch_pad_set_voltage(TOUCH_HVOLT_2V4, TOUCH_LVOLT_0V8, TOUCH_HVOLT_ATTEN_1V5);
vTaskDelay(100 / portTICK_PERIOD_MS);
for (int j = 0; j < TOUCH_TEST_LOOP_NUM; j++) {
for (int i = 0; i < TOUCH_PAD_MAX; i++) {
ESP_ERROR_CHECK(touch_pad_read(i, &touch_value));
printf("T%d:%5d ", i, touch_value);
}
printf("\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V);
vTaskDelay(100/portTICK_PERIOD_MS);
printf("Case[3], set differen slope for each channel\n");
for (int i = 0;i<TOUCH_PAD_MAX;i++) {
touch_pad_set_cnt_mode(i, (i % TOUCH_PAD_SLOPE_7) + 1, TOUCH_PAD_TIE_OPT_HIGH);
}
for (int j = 0; j < TOUCH_TEST_LOOP_NUM; j++) {
for (int i = 0; i < TOUCH_PAD_MAX; i++) {
ESP_ERROR_CHECK(touch_pad_read(i, &touch_value));
printf("T%d:%5d ", i, touch_value);
}
printf("\n");
vTaskDelay(500 / portTICK_PERIOD_MS);
}
for (int i = 0;i<TOUCH_PAD_MAX;i++) {
touch_pad_set_cnt_mode(i, TOUCH_PAD_SLOPE_7, TOUCH_PAD_TIE_OPT_HIGH);
for (int i = 0; i < TOUCH_PAD_MAX; i++) {
#if TOUCH_FILTER_MODE_EN
// If open the filter mode, please use this API to get the touch pad count.
ESP_ERROR_CHECK(touch_pad_read_raw_data(i, &touch_value));
ESP_ERROR_CHECK(touch_pad_read_filtered(i, &touch_filter_value));
printf("T%d:[%4d,%4d] ", i, touch_value, touch_filter_value);
#else
ESP_ERROR_CHECK(touch_pad_read(i, &touch_value));
printf("T%d:[%4d] ", i, touch_value);
#endif
}
printf("\n");
vTaskDelay(200 / portTICK_PERIOD_MS);
}
}
@@ -86,11 +54,18 @@ static void tp_example_touch_pad_init()
void app_main()
{
// Initialize touch pad peripheral
// Initialize touch pad peripheral.
// The default fsm mode is software trigger mode.
touch_pad_init();
// Set reference voltage for charging/discharging
// In this case, the high reference valtage will be 2.7V - 1V = 1.7V
// The low reference voltage will be 0.5
// The larger the range, the larger the pulse count value.
touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V);
#if TOUCH_FILTER_MODE_EN
touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD);
#endif
tp_example_touch_pad_init();
// Start task to read values sensed by pads
xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL);
}