#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" #include "Arduino.h" #include "keyboard.h" using namespace std; Keyboard::Keyboard() { } /* Handle an interrupt triggered when a pad is touched. Recognize what pad has been touched and save it in a table. https://github.com/espressif/esp-idf/blob/master/examples/peripherals/touch_pad_interrupt/main/tp_interrupt_main.c */ static void tp_example_rtc_intr(void *arg) { uint32_t pad_intr = READ_PERI_REG(SENS_SAR_TOUCH_CTRL2_REG) & 0x3ff; uint32_t rtc_intr = READ_PERI_REG(RTC_CNTL_INT_ST_REG); //clear interrupt WRITE_PERI_REG(RTC_CNTL_INT_CLR_REG, rtc_intr); SET_PERI_REG_MASK(SENS_SAR_TOUCH_CTRL2_REG, SENS_TOUCH_MEAS_EN_CLR); if (rtc_intr & RTC_CNTL_TOUCH_INT_ST) { for (int i = 0; i < TOUCH_PAD_NUM; i++) { if ((pad_intr >> i) & 0x01) { s_pad_activated[i] = true; } } } } bool Keyboard::getTouchDetected(uint8_t pad) { bool res = s_pad_activated[pad]; s_pad_activated[pad] = false; return res; } void Keyboard::init() { touch_pad_init(); Serial.println("touchpad values:"); for (int i=0; i