/* Touch Pad Interrupt 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 #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" #include "driver/touch_pad.h" #include "soc/rtc_cntl_reg.h" #include "soc/sens_reg.h" static const char* TAG = "Touch pad"; #define TOUCH_THRESH_NO_USE (0) #define TOUCH_THRESH_PERCENT (99) static bool s_pad_activated[TOUCH_PAD_MAX]; static uint32_t s_pad_init_val[TOUCH_PAD_MAX]; /* Read values sensed at all available touch pads. Use 2 / 3 of read value as the threshold to trigger interrupt when the pad is touched. Note: this routine demonstrates a simple way to configure activation threshold for the touch pads. Do not touch any pads when this routine is running (on application start). */ static void tp_example_set_thresholds(void) { uint16_t touch_value; //delay some time in order to make the filter work and get a initial value vTaskDelay(500/portTICK_PERIOD_MS); for (int i = 0; i> i) & 0x01) { s_pad_activated[i] = true; } } } /* * Before reading touch pad, we need to initialize the RTC IO. */ static void tp_example_touch_pad_init() { for (int i = 0;i< TOUCH_PAD_MAX;i++) { //init RTC IO and mode for touch pad. touch_pad_config(i, TOUCH_THRESH_NO_USE); } } void app_main() { // Initialize touch pad peripheral, it will start a timer to run a filter ESP_LOGI(TAG, "Initializing touch pad"); touch_pad_init(); // Initialize and start a software filter to detect slight change of capacitance. touch_pad_filter_start(10); // Set measuring time and sleep time // In this case, measurement will sustain 0xffff / 8Mhz = 8.19ms // Meanwhile, sleep time between two measurement will be 0x1000 / 150Khz = 27.3 ms touch_pad_set_meas_time(0x1000, 0xffff); //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.8V, so that the procedure of charging // and discharging would be very fast. touch_pad_set_voltage(TOUCH_HVOLT_2V4, TOUCH_LVOLT_0V8, TOUCH_HVOLT_ATTEN_1V5); // Init touch pad IO tp_example_touch_pad_init(); // Set thresh hold tp_example_set_thresholds(); // Register touch interrupt ISR touch_pad_isr_register(tp_example_rtc_intr, NULL); // Start a task to show what pads have been touched xTaskCreate(&tp_example_read_task, "touch_pad_read_task", 2048, NULL, 5, NULL); }