Kestrel Interface
Loading...
Searching...
No Matches
kest_touch_irq.c
Go to the documentation of this file.
1#include <freertos/FreeRTOS.h>
2#include <driver/gpio.h>
3#include "esp_lcd_touch_gt911.h"
4
5#include "kest_error_codes.h"
6
7#include "kest_i2c.h"
8
9static TaskHandle_t touch_task_handle;
10
11static void IRAM_ATTR gt911_isr_handler(void *arg)
12{
13 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
14 vTaskNotifyGiveFromISR(touch_task_handle, &xHigherPriorityTaskWoken);
15 if (xHigherPriorityTaskWoken) portYIELD_FROM_ISR();
16}
17
18static void touch_task(void *arg)
19{
20 esp_lcd_touch_handle_t tp_handle = (esp_lcd_touch_handle_t)arg;
21
22 gpio_install_isr_service(0);
23 gpio_isr_handler_add(GPIO_NUM_4, gt911_isr_handler, NULL);
24
25 for (;;)
26 {
27 ulTaskNotifyTake(pdTRUE, portMAX_DELAY); // wait for IRQ
28
29 if (xSemaphoreTake(i2c_mutex, pdMS_TO_TICKS(I2C_MASTER_TIMEOUT_MS)) == pdTRUE)
30 {
31 if (!gpio_get_level(GPIO_NUM_4))
32 esp_lcd_touch_read_data(tp_handle); // safe in task context
33 xSemaphoreGive(i2c_mutex);
34 }
35 }
36}
37
38void init_touch_task(esp_lcd_touch_handle_t tp_handle)
39{
41 touch_task,
42 "gt911_touch",
43 4096,
44 tp_handle, // task arg
45 5, // priority
46 &touch_task_handle, // <-- store handle here
47 1
48 );
49}
50
51
52
#define xTaskCreatePinnedToCore(task_func, name, stack, param, priority, handle, core_id)
SemaphoreHandle_t i2c_mutex
#define I2C_MASTER_TIMEOUT_MS
Definition kest_i2c.h:12
void init_touch_task(esp_lcd_touch_handle_t tp_handle)