mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
842caaab21
1. add sens_struct.h 2. add definition of RTCCNTL and RTCIO 3. modify touch pad examples 4. update example code. 5. add comments add option in menuconfig 6. fix issue that pad index 8 and 9 are mismatched 7. add touch_pad_read_filtered() api to get value filtered by iir filter 8. modify touch pad isr func 9. Make the items in perihperal.ld in the sequence of address 10. delete Kconfig for touch pad 11. add touchpad filter APIs to adjust the filter 12. add touch_pad into index.rst 13. add touch_pad in Doxyfile 14. add touch_pad.rst
97 lines
3.5 KiB
C
97 lines
3.5 KiB
C
/* Touch Pad Read Example
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
*/
|
|
#include <stdio.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#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)
|
|
/*
|
|
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)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void tp_example_touch_pad_init()
|
|
{
|
|
for (int i = 0;i< TOUCH_PAD_MAX;i++) {
|
|
touch_pad_config(i, TOUCH_THRESH_NO_USE);
|
|
}
|
|
}
|
|
|
|
void app_main()
|
|
{
|
|
// Initialize touch pad peripheral
|
|
touch_pad_init();
|
|
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);
|
|
|
|
}
|