doc: updated readme
This commit is contained in:
1 parent
b6f88f48fb
commit
6f79a3c111
1 file changed
+136
-12
@@ -1,4 +1,4 @@
|
|||||||
# ESP32 ESP-IDF component for TTP229 touch pad (via RMT driver)
|
# ESP32 ESP-IDF component for TTP229 touch pad
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
## Using
|
## Using
|
||||||
|
|
||||||
In an existing project, run the following command to install the components:
|
In an existing project, run the following command to install the component:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd ../your_project/components
|
cd ../your_project/components
|
||||||
@@ -30,7 +30,9 @@ In the application, add the component:
|
|||||||
#include "zh_ttp229.h"
|
#include "zh_ttp229.h"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example
|
## Examples
|
||||||
|
|
||||||
|
### Basic Example: Single Device
|
||||||
|
|
||||||
```c
|
```c
|
||||||
#include "zh_ttp229.h"
|
#include "zh_ttp229.h"
|
||||||
@@ -53,18 +55,21 @@ void app_main(void)
|
|||||||
config.work_mode = ZH_TTP229_16_PAD;
|
config.work_mode = ZH_TTP229_16_PAD;
|
||||||
config.device_number = TTP229_NUMBER;
|
config.device_number = TTP229_NUMBER;
|
||||||
config.debounce_time = 300;
|
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 = 23;
|
config.rmt_tx_start_delay = 23;
|
||||||
zh_ttp229_init(&config, &ttp229_handle);
|
esp_err_t ret = zh_ttp229_init(&config, &ttp229_handle);
|
||||||
|
if (ret != ESP_OK)
|
||||||
|
{
|
||||||
|
printf("TTP229 initialization error: %s\n", esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
const zh_ttp229_stats_t *stats = zh_ttp229_get_stats();
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
printf("Number of RMT driver error: %ld.\n", stats->rmt_driver_error);
|
}
|
||||||
printf("Number of event post error: %ld.\n", stats->event_post_error);
|
ret = zh_ttp229_deinit(&ttp229_handle);
|
||||||
printf("Number of queue overflow error: %ld.\n", stats->queue_overflow_error);
|
if (ret != ESP_OK)
|
||||||
printf("Minimum free stack size: %ld.\n", stats->min_stack_size);
|
{
|
||||||
vTaskDelay(60000 / portTICK_PERIOD_MS);
|
printf("TTP229 deinit error: %s\n", esp_err_to_name(ret));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,3 +79,122 @@ void zh_ttp229_event_handler(void *arg, esp_event_base_t event_base, int32_t eve
|
|||||||
printf("Touch pad number %d pad number %d pressed.\n", ttp229_event->device_number, ttp229_event->pad_number);
|
printf("Touch pad number %d pad number %d pressed.\n", ttp229_event->device_number, ttp229_event->pad_number);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Stats Example
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include "zh_ttp229.h"
|
||||||
|
|
||||||
|
#define TTP229_NUMBER 0x01
|
||||||
|
|
||||||
|
zh_ttp229_handle_t *ttp229_handle = NULL;
|
||||||
|
|
||||||
|
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_log_level_set("zh_vector", 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;
|
||||||
|
config.rmt_tx_start_delay = 23;
|
||||||
|
esp_err_t ret = zh_ttp229_init(&config, &ttp229_handle);
|
||||||
|
if (ret != ESP_OK)
|
||||||
|
{
|
||||||
|
printf("TTP229 initialization error: %s\n", esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
zh_ttp229_reset_stats();
|
||||||
|
ret = zh_ttp229_deinit(&ttp229_handle);
|
||||||
|
if (ret != ESP_OK)
|
||||||
|
{
|
||||||
|
printf("TTP229 deinit error: %s\n", esp_err_to_name(ret));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Multi-Device Example
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include "zh_ttp229.h"
|
||||||
|
|
||||||
|
#define TTP229_DEVICE_1 0x01
|
||||||
|
#define TTP229_DEVICE_2 0x02
|
||||||
|
|
||||||
|
zh_ttp229_handle_t *ttp229_handle_1 = NULL;
|
||||||
|
zh_ttp229_handle_t *ttp229_handle_2 = NULL;
|
||||||
|
|
||||||
|
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_log_level_set("zh_vector", 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_1 = ZH_TTP229_INIT_CONFIG_DEFAULT();
|
||||||
|
config_1.scl_gpio = GPIO_NUM_25;
|
||||||
|
config_1.sdo_gpio = GPIO_NUM_27;
|
||||||
|
config_1.work_mode = ZH_TTP229_16_PAD;
|
||||||
|
config_1.device_number = TTP229_DEVICE_1;
|
||||||
|
config_1.debounce_time = 300;
|
||||||
|
config_1.rmt_tx_start_delay = 23;
|
||||||
|
esp_err_t ret = zh_ttp229_init(&config_1, &ttp229_handle_1);
|
||||||
|
if (ret != ESP_OK)
|
||||||
|
{
|
||||||
|
printf("TTP229 device 1 initialization error: %s\n", esp_err_to_name(ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
zh_ttp229_init_config_t config_2 = ZH_TTP229_INIT_CONFIG_DEFAULT();
|
||||||
|
config_2.scl_gpio = GPIO_NUM_26;
|
||||||
|
config_2.sdo_gpio = GPIO_NUM_28;
|
||||||
|
config_2.work_mode = ZH_TTP229_16_PAD;
|
||||||
|
config_2.device_number = TTP229_DEVICE_2;
|
||||||
|
config_2.debounce_time = 300;
|
||||||
|
config_2.rmt_tx_start_delay = 23;
|
||||||
|
ret = zh_ttp229_init(&config_2, &ttp229_handle_2);
|
||||||
|
if (ret != ESP_OK)
|
||||||
|
{
|
||||||
|
printf("TTP229 device 2 initialization error: %s\n", esp_err_to_name(ret));
|
||||||
|
zh_ttp229_deinit(&ttp229_handle_1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
zh_ttp229_deinit(&ttp229_handle_2);
|
||||||
|
zh_ttp229_deinit(&ttp229_handle_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in new issue
Block a user