RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
+ Touch 的协作图:

结构体

struct  rt_touch_info
 
struct  rt_touch_config
 
struct  rt_touch_device
 
struct  rt_touch_data
 
struct  rt_touch_ops
 

宏定义

#define rt_touch_get_ts()
 
#define RT_TOUCH_VENDOR_UNKNOWN   (0) /* unknown */
 
#define RT_TOUCH_VENDOR_GT   (1) /* GTxx series */
 
#define RT_TOUCH_VENDOR_FT   (2) /* FTxx series */
 
#define RT_TOUCH_TYPE_NONE   (0) /* touch ic none */
 
#define RT_TOUCH_TYPE_CAPACITANCE   (1) /* capacitance ic */
 
#define RT_TOUCH_TYPE_RESISTANCE   (2) /* resistance ic */
 
#define RT_TOUCH_CTRL_GET_ID   (RT_DEVICE_CTRL_BASE(Touch) + 0) /* Get device id */
 
#define RT_TOUCH_CTRL_GET_INFO   (RT_DEVICE_CTRL_BASE(Touch) + 1) /* Get touch info */
 
#define RT_TOUCH_CTRL_SET_MODE   (RT_DEVICE_CTRL_BASE(Touch) + 2) /* Set touch's work mode. ex. RT_TOUCH_MODE_POLLING,RT_TOUCH_MODE_INT */
 
#define RT_TOUCH_CTRL_SET_X_RANGE   (RT_DEVICE_CTRL_BASE(Touch) + 3) /* Set x coordinate range */
 
#define RT_TOUCH_CTRL_SET_Y_RANGE   (RT_DEVICE_CTRL_BASE(Touch) + 4) /* Set y coordinate range */
 
#define RT_TOUCH_CTRL_SET_X_TO_Y   (RT_DEVICE_CTRL_BASE(Touch) + 5) /* Set X Y coordinate exchange */
 
#define RT_TOUCH_CTRL_DISABLE_INT   (RT_DEVICE_CTRL_BASE(Touch) + 6) /* Disable interrupt */
 
#define RT_TOUCH_CTRL_ENABLE_INT   (RT_DEVICE_CTRL_BASE(Touch) + 7) /* Enable interrupt */
 
#define RT_TOUCH_CTRL_POWER_ON   (RT_DEVICE_CTRL_BASE(Touch) + 8) /* Touch Power On */
 
#define RT_TOUCH_CTRL_POWER_OFF   (RT_DEVICE_CTRL_BASE(Touch) + 9) /* Touch Power Off */
 
#define RT_TOUCH_CTRL_GET_STATUS   (RT_DEVICE_CTRL_BASE(Touch) + 10) /* Get Touch Power Status */
 
#define RT_TOUCH_EVENT_NONE   (0) /* Touch none */
 
#define RT_TOUCH_EVENT_UP   (1) /* Touch up event */
 
#define RT_TOUCH_EVENT_DOWN   (2) /* Touch down event */
 
#define RT_TOUCH_EVENT_MOVE   (3) /* Touch move event */
 

类型定义

typedef struct rt_touch_devicert_touch_t
 

函数

int rt_hw_touch_register (rt_touch_t touch, const char *name, rt_uint32_t flag, void *data)
 
void rt_hw_touch_isr (rt_touch_t touch)
 

详细描述

Touch driver api

Example

#include <rtthread.h>
#include "rtdevice.h"
static rt_thread_t gt9147_thread = RT_NULL;
static rt_sem_t gt9147_sem = RT_NULL;
static rt_device_t dev = RT_NULL;
static struct rt_touch_data *read_data;
// 读取数据线程入口函数
static void gt9147_entry(void *parameter)
{
struct rt_touch_data *read_data;
read_data = (struct rt_touch_data *)rt_malloc(sizeof(struct rt_touch_data) * 5);
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);
}
}
}
// 打开中断
}
}
// 接收回调函数
static rt_err_t rx_callback(rt_device_t dev, rt_size_t size)
{
// 关闭中断
// 释放信号量
rt_sem_release(gt9147_sem);
return 0;
}
static int gt9147_sample(void)
{
// 查找 Touch 设备
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);
// 创建信号量
gt9147_sem = rt_sem_create("dsem", 0, RT_IPC_FLAG_PRIO);
if (gt9147_sem == RT_NULL)
{
rt_kprintf("create dynamic semaphore failed.\n");
return -1;
}
// 创建读取数据线程
gt9147_thread = rt_thread_create("thread1",
gt9147_entry,
THREAD_STACK_SIZE,
THREAD_PRIORITY,
THREAD_TIMESLICE);
// 启动线程
if (gt9147_thread != RT_NULL)
rt_thread_startup(gt9147_thread);
return 0;
}
MSH_CMD_EXPORT(gt9147_sample, gt9147 sample);
rt_err_t rt_device_set_rx_indicate(rt_device_t dev, rt_err_t(*rx_ind)(rt_device_t dev, rt_size_t size))
#define RT_DEVICE_FLAG_INT_RX
rt_err_t rt_device_control(rt_device_t dev, int cmd, void *arg)
rt_ssize_t rt_device_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
rt_device_t rt_device_find(const char *name)
struct rt_device * rt_device_t
rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflag)
#define RT_IPC_FLAG_PRIO
#define RT_WAITING_FOREVER
#define rt_kprintf(...)
rt_weak void * rt_malloc(rt_size_t size)
Allocate a block of memory with a minimum of 'size' bytes.
rt_err_t rt_thread_startup(rt_thread_t thread)
This function will start a thread and put it to system ready queue.
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.
struct rt_thread * rt_thread_t
#define RT_TOUCH_CTRL_DISABLE_INT
#define RT_TOUCH_EVENT_DOWN
#define RT_TOUCH_CTRL_ENABLE_INT
#define RT_TOUCH_EVENT_MOVE
#define MSH_CMD_EXPORT(...)
rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag)
Creating a semaphore object.
定义 ipc.c:467
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
定义 ipc.c:644
struct rt_semaphore * rt_sem_t
rt_err_t rt_sem_release(rt_sem_t sem)
This function will release a semaphore. If there is thread suspended on the semaphore,...
定义 ipc.c:695
rt_base_t rt_err_t
unsigned char rt_uint8_t
rt_ubase_t rt_size_t
#define RT_NULL
rt_uint16_t x_coordinate
rt_tick_t timestamp
rt_uint16_t y_coordinate
rt_uint8_t track_id

宏定义说明

◆ rt_touch_get_ts

#define rt_touch_get_ts ( )
值:
rt_tick_get() /* API for the touch to get the timestamp */
rt_tick_t rt_tick_get(void)
This function will return current tick from operating system startup.
定义 clock.c:69

在文件 dev_touch.h129 行定义.

◆ RT_TOUCH_VENDOR_UNKNOWN

#define RT_TOUCH_VENDOR_UNKNOWN   (0) /* unknown */

在文件 dev_touch.h133 行定义.

◆ RT_TOUCH_VENDOR_GT

#define RT_TOUCH_VENDOR_GT   (1) /* GTxx series */

在文件 dev_touch.h134 行定义.

◆ RT_TOUCH_VENDOR_FT

#define RT_TOUCH_VENDOR_FT   (2) /* FTxx series */

在文件 dev_touch.h135 行定义.

◆ RT_TOUCH_TYPE_NONE

#define RT_TOUCH_TYPE_NONE   (0) /* touch ic none */

在文件 dev_touch.h138 行定义.

◆ RT_TOUCH_TYPE_CAPACITANCE

#define RT_TOUCH_TYPE_CAPACITANCE   (1) /* capacitance ic */

在文件 dev_touch.h139 行定义.

◆ RT_TOUCH_TYPE_RESISTANCE

#define RT_TOUCH_TYPE_RESISTANCE   (2) /* resistance ic */

在文件 dev_touch.h140 行定义.

◆ RT_TOUCH_CTRL_GET_ID

#define RT_TOUCH_CTRL_GET_ID   (RT_DEVICE_CTRL_BASE(Touch) + 0) /* Get device id */

在文件 dev_touch.h143 行定义.

◆ RT_TOUCH_CTRL_GET_INFO

#define RT_TOUCH_CTRL_GET_INFO   (RT_DEVICE_CTRL_BASE(Touch) + 1) /* Get touch info */

在文件 dev_touch.h144 行定义.

◆ RT_TOUCH_CTRL_SET_MODE

#define RT_TOUCH_CTRL_SET_MODE   (RT_DEVICE_CTRL_BASE(Touch) + 2) /* Set touch's work mode. ex. RT_TOUCH_MODE_POLLING,RT_TOUCH_MODE_INT */

在文件 dev_touch.h145 行定义.

◆ RT_TOUCH_CTRL_SET_X_RANGE

#define RT_TOUCH_CTRL_SET_X_RANGE   (RT_DEVICE_CTRL_BASE(Touch) + 3) /* Set x coordinate range */

在文件 dev_touch.h146 行定义.

◆ RT_TOUCH_CTRL_SET_Y_RANGE

#define RT_TOUCH_CTRL_SET_Y_RANGE   (RT_DEVICE_CTRL_BASE(Touch) + 4) /* Set y coordinate range */

在文件 dev_touch.h147 行定义.

◆ RT_TOUCH_CTRL_SET_X_TO_Y

#define RT_TOUCH_CTRL_SET_X_TO_Y   (RT_DEVICE_CTRL_BASE(Touch) + 5) /* Set X Y coordinate exchange */

在文件 dev_touch.h148 行定义.

◆ RT_TOUCH_CTRL_DISABLE_INT

#define RT_TOUCH_CTRL_DISABLE_INT   (RT_DEVICE_CTRL_BASE(Touch) + 6) /* Disable interrupt */

在文件 dev_touch.h149 行定义.

◆ RT_TOUCH_CTRL_ENABLE_INT

#define RT_TOUCH_CTRL_ENABLE_INT   (RT_DEVICE_CTRL_BASE(Touch) + 7) /* Enable interrupt */

在文件 dev_touch.h150 行定义.

◆ RT_TOUCH_CTRL_POWER_ON

#define RT_TOUCH_CTRL_POWER_ON   (RT_DEVICE_CTRL_BASE(Touch) + 8) /* Touch Power On */

在文件 dev_touch.h151 行定义.

◆ RT_TOUCH_CTRL_POWER_OFF

#define RT_TOUCH_CTRL_POWER_OFF   (RT_DEVICE_CTRL_BASE(Touch) + 9) /* Touch Power Off */

在文件 dev_touch.h152 行定义.

◆ RT_TOUCH_CTRL_GET_STATUS

#define RT_TOUCH_CTRL_GET_STATUS   (RT_DEVICE_CTRL_BASE(Touch) + 10) /* Get Touch Power Status */

在文件 dev_touch.h153 行定义.

◆ RT_TOUCH_EVENT_NONE

#define RT_TOUCH_EVENT_NONE   (0) /* Touch none */

在文件 dev_touch.h156 行定义.

◆ RT_TOUCH_EVENT_UP

#define RT_TOUCH_EVENT_UP   (1) /* Touch up event */

在文件 dev_touch.h157 行定义.

◆ RT_TOUCH_EVENT_DOWN

#define RT_TOUCH_EVENT_DOWN   (2) /* Touch down event */

在文件 dev_touch.h158 行定义.

◆ RT_TOUCH_EVENT_MOVE

#define RT_TOUCH_EVENT_MOVE   (3) /* Touch move event */

在文件 dev_touch.h159 行定义.

类型定义说明

◆ rt_touch_t

typedef struct rt_touch_device* rt_touch_t

在文件 dev_touch.h185 行定义.

函数说明

◆ rt_hw_touch_register()

int rt_hw_touch_register ( rt_touch_t touch,
const char * name,
rt_uint32_t flag,
void * data )

register a touch device

参数
touchthe touch device
namethe name of touch device
flagthe flag of touch device
datathe user data of touch device
返回
rt_err_t error code

◆ rt_hw_touch_isr()

void rt_hw_touch_isr ( rt_touch_t touch)

Touch irq handle

参数
touchthe touch device
注解
If you doesn't use pin device. you must call this function in your touch irq callback