触摸输入(Touch)API 参考#
概述#
K230 的触摸能力由两部分组成:
触摸设备管理:通过 canmv_misc 动态注册/删除触摸设备
触摸读写 HAL:通过 drv_touch 实例读取触摸点与设备信息
相关头文件:
src/rtsmart/libs/rtsmart_hal/components/canmv_misc/canmv_misc.hsrc/rtsmart/libs/rtsmart_hal/drivers/touch/drv_touch.h
API 参考#
设备管理 API(canmv_misc)#
canmv_misc_create_touch_device#
描述
按 cfg 注册一个触摸设备。
语法
int canmv_misc_create_touch_device(struct drv_touch_config_t* cfg);
参数
参数名称 |
描述 |
输入/输出 |
|---|---|---|
|
设备配置。 |
输入 |
返回值
返回值 |
描述 |
|---|---|
|
成功。 |
非 |
失败。 |
canmv_misc_delete_touch_device#
描述
按索引注销触摸设备。
语法
int canmv_misc_delete_touch_device(int index);
参数
参数名称 |
描述 |
输入/输出 |
|---|---|---|
|
设备索引。 |
输入 |
返回值
返回值 |
描述 |
|---|---|
|
成功。 |
非 |
失败。 |
读写 HAL API(drv_touch)#
drv_touch_inst_create#
描述
创建触摸实例。
语法
int drv_touch_inst_create(int id, drv_touch_inst_t** inst);
参数
参数名称 |
描述 |
输入/输出 |
|---|---|---|
|
设备编号。 |
输入 |
|
驱动实例句柄。 |
输出 |
返回值
常见错误:-1 参数错误,-2 设备 ID 无效,-3 内存不足。
drv_touch_inst_destroy#
描述
销毁实例并释放资源。
语法
void drv_touch_inst_destroy(drv_touch_inst_t** inst);
参数
参数名称 |
描述 |
输入/输出 |
|---|---|---|
|
驱动实例句柄。 |
输入/输出 |
返回值
无。
drv_touch_read#
描述
读取触摸点。
语法
int drv_touch_read(drv_touch_inst_t* inst, struct drv_touch_data* touch_data, int max_points);
参数
参数名称 |
描述 |
输入/输出 |
|---|---|---|
|
驱动实例句柄。 |
输入 |
|
触点数据缓冲区。 |
输出 |
|
最多读取的触点数。 |
输入 |
返回值
>0 表示触点数量,0 无事件,<0 错误(常见 -1/-2)。
drv_touch_get_info#
描述
查询设备能力信息。
语法
int drv_touch_get_info(drv_touch_inst_t* inst, struct drv_touch_info* info);
参数
参数名称 |
描述 |
输入/输出 |
|---|---|---|
|
驱动实例句柄。 |
输入 |
|
设备能力信息。 |
输出 |
drv_touch_get_config#
描述
查询当前设备配置。
语法
int drv_touch_get_config(drv_touch_inst_t* inst, struct drv_touch_config_t* cfg);
参数
参数名称 |
描述 |
输入/输出 |
|---|---|---|
|
驱动实例句柄。 |
输入 |
|
设备配置。 |
输出 |
drv_touch_reset#
描述
执行触摸设备复位。
语法
int drv_touch_reset(drv_touch_inst_t* inst);
参数
参数名称 |
描述 |
输入/输出 |
|---|---|---|
|
驱动实例句柄。 |
输入 |
drv_touch_get_default_rotate#
描述
读取默认旋转配置(0/90/180/270/swap_xy)。
语法
int drv_touch_get_default_rotate(drv_touch_inst_t* inst, int* rotate);
参数
参数名称 |
描述 |
输入/输出 |
|---|---|---|
|
驱动实例句柄。 |
输入 |
|
默认旋转配置。 |
输出 |
数据类型#
struct drv_touch_config_t#
描述
用于创建触摸设备时传入硬件配置:
成员
成员名称 |
描述 |
|---|---|
|
设备索引 |
|
坐标范围(0 可交由系统默认) |
|
中断引脚与有效电平(无中断时可用 |
|
复位引脚与有效电平(无复位时可用 |
|
I2C 总线号与速率 |
struct drv_touch_data#
描述
单个触点数据:
成员
成员名称 |
描述 |
|---|---|
|
事件类型( |
|
触点追踪 ID |
|
触点坐标 |
|
触点宽度 |
|
时间戳 |
struct drv_touch_info#
描述
设备能力信息:
成员
成员名称 |
描述 |
|---|---|
|
触摸类型 |
|
厂商信息 |
|
最大触点数 |
|
坐标范围 |
使用流程#
如需动态创建设备,先调用
canmv_misc_create_touch_device()。调用
drv_touch_inst_create()打开实例。先调用
drv_touch_get_info()/drv_touch_get_config()确认能力与坐标范围。循环调用
drv_touch_read()读取触点事件。退出时调用
drv_touch_inst_destroy()。若是动态创建的设备,最后调用
canmv_misc_delete_touch_device()。
相关文档#
src/rtsmart/examples/peripheral/touch/test_touch.c
