Touch driver api.
#include <rtthread.h>
#include "rtdevice.h"
static void gt9147_entry(void *parameter)
{
while (1)
{
if (rt_device_read(dev, 0, read_data, 5) == 5)
{
for (rt_uint8_t i = 0; i < 5; i++)
{
if (read_data[i].event == RT_TOUCH_EVENT_DOWN || read_data[i].event == RT_TOUCH_EVENT_MOVE)
{
rt_kprintf("%d %d %d %d %d\n",
read_data[i].track_id,
read_data[i].x_coordinate,
read_data[i].y_coordinate,
read_data[i].timestamp,
read_data[i].width);
}
}
}
rt_device_control(dev, RT_TOUCH_CTRL_ENABLE_INT, RT_NULL);
}
}
static rt_err_t rx_callback(
rt_device_t dev, rt_size_t size)
{
rt_device_control(dev, RT_TOUCH_CTRL_DISABLE_INT, RT_NULL);
return 0;
}
static int gt9147_sample(void)
{
dev = rt_device_find("touch");
if (dev == RT_NULL)
{
rt_kprintf("can't find device:%s\n", "touch");
return -1;
}
{
rt_kprintf("open device failed!");
return -1;
}
rt_device_set_rx_indicate(dev, rx_callback);
if (gt9147_sem == RT_NULL)
{
rt_kprintf("create dynamic semaphore failed.\n");
return -1;
}
gt9147_entry,
RT_NULL,
THREAD_STACK_SIZE,
THREAD_PRIORITY,
THREAD_TIMESLICE);
if (gt9147_thread != RT_NULL)
return 0;
}
#define RT_DEVICE_FLAG_INT_RX
Definition: rtdef.h:1297
#define RT_IPC_FLAG_PRIO
Definition: rtdef.h:973
#define RT_WAITING_FOREVER
Definition: rtdef.h:980
rt_weak void * rt_malloc(rt_size_t size)
Allocate a block of memory with a minimum of 'size' bytes.
Definition: kservice.c:807
rt_err_t rt_thread_startup(rt_thread_t thread)
This function will start a thread and put it to system ready queue.
Definition: thread.c:393
rt_thread_t rt_thread_create(const char *name, void(*entry)(void *parameter), void *parameter, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick)
This function will create a thread object and allocate thread object memory. and stack.
Definition: thread.c:523
#define MSH_CMD_EXPORT(...)
Definition: finsh.h:142
rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag)
Creating a semaphore object.
Definition: ipc.c:467
rt_err_t rt_sem_release(rt_sem_t sem)
This function will release a semaphore. If there is thread suspended on the semaphore,...
Definition: ipc.c:695
Touch data.
Definition: dev_touch.h:203