73a2b00c2a199d4ec431ba7cb5fc62264c9b88ec
ESP32 ESP-IDF component for TTP229 touch pad (via RMT driver)
Tested on
SAST Tools
PVS-Studio - static analyzer for C, C++, C#, and Java code.
Features
- Support up to 4 touch pads on one device (depends on the used ESP32 chip).
- Support 8 or 16 pad work mode.
Note
- After start/reset first touch not work.
- Multi touch not supported.
Attention
- For correct operation, please enable the following settings in the menuconfig:
CONFIG_GPIO_CTRL_FUNC_IN_IRAM
CONFIG_RMT_ENCODER_FUNC_IN_IRAM
CONFIG_RMT_TX_ISR_HANDLER_IN_IRAM
CONFIG_RMT_RX_ISR_HANDLER_IN_IRAM
CONFIG_RMT_RECV_FUNC_IN_IRAM
CONFIG_RMT_TX_ISR_CACHE_SAFE
CONFIG_RMT_RX_ISR_CACHE_SAFE
Using
In an existing project, run the following command to install the components:
cd ../your_project/components
git clone https://github.com/aZholtikov/zh_ttp229
In the application, add the component:
#include "zh_ttp229.h"
Examples
One touch pad on device:
#include "zh_ttp229.h"
#define TTP229_NUMBER 0x01
zh_ttp229_handle_t ttp229_handle = {0};
void zh_ttp229_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
void app_main(void)
{
esp_log_level_set("zh_ttp229", ESP_LOG_ERROR);
esp_event_loop_create_default();
esp_event_handler_instance_register(ZH_TTP229, ESP_EVENT_ANY_ID, &zh_ttp229_event_handler, NULL, NULL);
zh_ttp229_init_config_t config = ZH_TTP229_INIT_CONFIG_DEFAULT();
config.scl_gpio = GPIO_NUM_25;
config.sdo_gpio = GPIO_NUM_27;
config.work_mode = ZH_TTP229_16_PAD;
config.device_number = TTP229_NUMBER;
config.debounce_time = 300;
// The time between the low-level pulse in the interrupt and the actual start time of the RMT signal generator (in microseconds).
// It is determined experimentally or using a logic analyzer.
config.rmt_tx_start_delay = 19;
zh_ttp229_init(&config, &ttp229_handle);
for (;;)
{
const zh_ttp229_stats_t *stats = zh_ttp229_get_stats();
printf("Number of RMT driver error: %ld.\n", stats->rmt_driver_error);
printf("Number of event post error: %ld.\n", stats->event_post_error);
printf("Number of queue overflow error: %ld.\n", stats->queue_overflow_error);
printf("Minimum free stack size: %ld.\n", stats->min_stack_size);
vTaskDelay(60000 / portTICK_PERIOD_MS);
}
}
void zh_ttp229_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
zh_ttp229_event_on_isr_t *ttp229_event = event_data;
printf("Touch pad number %d pad number %d pressed.\n", ttp229_event->device_number, ttp229_event->pad_number);
}
Description
ESP32 ESP-IDF component for TTP229 touch pad (via RMT driver).
803 KiB
0 Stars
1 Watchers
0 Forks
Languages
C
99.4%
CMake
0.6%