2025-09-30 11:56:06 +08:00
<!DOCTYPE html> < html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "zh-cn" lang = "zh-cn" data-whc_version = "26.0" >
< head > < meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" / > < meta name = "viewport" content = "width=device-width, initial-scale=1.0" / > < meta http-equiv = "X-UA-Compatible" content = "IE=edge" / > < meta name = "DC.rights.owner" content = "(C) 版权 2025" / > < meta name = "copyright" content = "(C) 版权 2025" / > < meta name = "generator" content = "DITA-OT" / > < meta name = "DC.type" content = "reference" / > < meta name = "description" content = "写寄存器函数:用于向 gt911 发送控制命令或数据 static rt_err_t gt911_write_reg( struct rt_i2c_client *dev, rt_uint8_t *data, rt_uint8_t len) { struct rt_i2c_msg msgs; msgs.addr = dev->client_addr; //CTP 从机地址 msgs.flags = ..." / > < meta name = "DC.contributor" content = "yan.wang" / > < meta name = "DC.date.modified" content = "2024-12-05" / > < meta name = "DC.format" content = "HTML5" / > < meta name = "DC.identifier" content = "reference_qpq_jwf_1dc" / >
< title > 核心函数参考示例< / title > <!-- Build number 2023110923. --> < meta name = "wh-path2root" content = "../../../" / > < meta name = "wh-toc-id" content = "" / > < meta name = "wh-source-relpath" content = "topics/sdk/peripheral/touch-drive-examples.dita" / > < meta name = "wh-out-relpath" content = "topics/sdk/peripheral/touch-drive-examples.html" / >
< link rel = "stylesheet" type = "text/css" href = "../../../webhelp/app/commons.css?buildId=2023110923" / >
< link rel = "stylesheet" type = "text/css" href = "../../../webhelp/app/topic.css?buildId=2023110923" / >
< script src = "../../../webhelp/app/options/properties.js?buildId=20250121171154" > < / script >
< script src = "../../../webhelp/app/localization/strings.js?buildId=2023110923" > < / script >
< script src = "../../../webhelp/app/search/index/keywords.js?buildId=20250121171154" > < / script >
< script defer = "defer" src = "../../../webhelp/app/commons.js?buildId=2023110923" > < / script >
< script defer = "defer" src = "../../../webhelp/app/topic.js?buildId=2023110923" > < / script >
< link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-styles-web.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/notes.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-common.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-images.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/footnote.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/aic-web-watermark.css?buildId=2023110923" / > < link rel = "stylesheet" type = "text/css" href = "../../../webhelp/template/topic-body-list.css?buildId=2023110923" / > < / head >
< body id = "reference_qpq_jwf_1dc" class = "wh_topic_page frmBody" >
< a href = "#wh_topic_body" class = "sr-only sr-only-focusable" >
跳转到主要内容
< / a >
< header class = "navbar navbar-default wh_header" >
< div class = "container-fluid" >
< div class = "wh_header_flex_container navbar-nav navbar-expand-md navbar-dark" >
< div class = "wh_logo_and_publication_title_container" >
< div class = "wh_logo_and_publication_title" >
< a href = "http://www.artinchip.com" class = " wh_logo d-none d-sm-block " > < img src = "../../../company-logo-white.png" alt = "RTOS SDK 使用指南SDK 指南文件" / > < / a >
< div class = " wh_publication_title " > < a href = "../../../index.html" > < span class = "booktitle" > < span class = "ph mainbooktitle" > RTOS SDK 使用指南< / span > < span class = "ph booktitlealt" > SDK 指南文件< / span > < / span > < / a > < / div >
< / div >
< / div >
< div class = "wh_top_menu_and_indexterms_link collapse navbar-collapse" id = "wh_top_menu_and_indexterms_link" >
< / div >
< / div >
< / div >
< / header >
< div class = " wh_search_input navbar-form wh_topic_page_search search " role = "form" >
< form id = "searchForm" method = "get" role = "search" action = "../../../search.html" > < div > < input type = "search" placeholder = "搜索 " class = "wh_search_textfield" id = "textToSearch" name = "searchQuery" aria-label = "搜索查询" required = "required" / > < button type = "submit" class = "wh_search_button" aria-label = "搜索" > < span class = "search_input_text" > 搜索< / span > < / button > < / div > < / form >
< / div >
< div class = "container-fluid" id = "wh_topic_container" >
< div class = "row" >
< nav class = "wh_tools d-print-none navbar-expand-md" aria-label = "Tools" >
< div data-tooltip-position = "bottom" class = " wh_breadcrumb " > < / div >
< div class = "wh_right_tools" >
< button class = "wh_hide_highlight" aria-label = "切换搜索突出显示" title = "切换搜索突出显示" > < / button >
< button class = "webhelp_expand_collapse_sections" data-next-state = "collapsed" aria-label = "折叠截面" title = "折叠截面" > < / button >
< div class = " wh_print_link print d-none d-md-inline-block " > < button onClick = "window.print()" title = "打印此页" aria-label = "打印此页" > < / button > < / div >
< / div >
< / nav >
< / div >
< div class = "wh_content_area" >
< div class = "row" >
< div class = "col-lg-10 col-md-10 col-sm-10 col-xs-12" id = "wh_topic_body" >
< button id = "wh_close_topic_toc_button" class = "close-toc-button d-none" aria-label = "Toggle topic table of content" aria-controls = "wh_topic_toc" aria-expanded = "true" >
< span class = "close-toc-icon-container" >
< span class = "close-toc-icon" > < / span >
< / span >
< / button >
< div class = " wh_topic_content body " > < main role = "main" > < article class = "- topic/topic reference/reference topic reference" role = "article" aria-labelledby = "ariaid-title1" > < span class = "edit-link" style = "font-size:12px; opacity:0.6; text-align:right; vertical-align:middle" > < a target = "_blank" href = "http://172.16.35.88/tasks/jdssno1uvvbf2mltu9kb9v3if05d5gopuakboe8hlud18rma/edit/F:/aicdita/aicdita-cn/topics/sdk/peripheral/touch-drive-examples.dita" > Edit online< / a > < / span > < h1 class = "- topic/title title topictitle1" id = "ariaid-title1" > 核心函数参考示例< / h1 > < div class = "date inPage" > 5 Dec 2024< / div > < div style = "color: gray;" >
Read time: 6 minute(s)
< / div > < div class = "- topic/body reference/refbody body refbody" > < p class = "- topic/shortdesc shortdesc" > < / p > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_rg2_mxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_rg2_mxf_1dc" > < h2 class = "- topic/title title sectiontitle" > 写寄存器函数:用于向 gt911 发送控制命令或数据< / h2 >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_sg2_mxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_sg2_mxf_1dc" > < strong class = "hl-keyword" > static< / strong > rt_err_t gt911_write_reg(< strong class = "hl-keyword" > struct< / strong > rt_i2c_client *dev, rt_uint8_t *data,
rt_uint8_t len)
{
< strong class = "hl-keyword" > struct< / strong > rt_i2c_msg msgs;
msgs.addr = dev-> client_addr; < em class = "hl-comment" > //CTP 从机地址< / em >
msgs.flags = RT_I2C_WR; < em class = "hl-comment" > //i2c 读写标志,这里是写标志< / em >
msgs.buf = data; < em class = "hl-comment" > //要写入的数据< / em >
msgs.len = len; < em class = "hl-comment" > //写入的长度< / em >
< strong class = "hl-keyword" > if< / strong > (rt_i2c_transfer(dev-> bus, & msgs, < span class = "hl-number" > 1< / span > ) == < span class = "hl-number" > 1< / span > ) { < em class = "hl-comment" > //i2c 标准读写接口,第一个参数是 i2c 总线句柄,第二个是 msgs, 但三个 msgs 的数量< / em >
< strong class = "hl-keyword" > return< / strong > RT_EOK;
} < strong class = "hl-keyword" > else< / strong > {
< strong class = "hl-keyword" > return< / strong > -RT_ERROR;
}
}< / pre >
< / div > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_tg2_mxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_tg2_mxf_1dc" > < h2 class = "- topic/title title sectiontitle" > 读寄存器函数:用于从 gt911 读取状态或数据< / h2 >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_ug2_mxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_ug2_mxf_1dc" > < strong class = "hl-keyword" > static< / strong > rt_err_t gt911_read_regs(< strong class = "hl-keyword" > struct< / strong > rt_i2c_client *dev, rt_uint8_t *reg,
rt_uint8_t *data, rt_uint8_t len)
{
< strong class = "hl-keyword" > struct< / strong > rt_i2c_msg msgs[< span class = "hl-number" > 2< / span > ];
msgs[< span class = "hl-number" > 0< / span > ].addr = dev-> client_addr;
msgs[< span class = "hl-number" > 0< / span > ].flags = RT_I2C_WR;
msgs[< span class = "hl-number" > 0< / span > ].buf = reg; < em class = "hl-comment" > //要读取的寄存器的地址,一般是 8 位的地址,但如 gt911 就有 16 位,需要每一次写入高 8 位和低 8 位两个 buf< / em >
msgs[< span class = "hl-number" > 0< / span > ].len = GT911_REGITER_LEN; < em class = "hl-comment" > //这个与寄存器地址长度对应, 8 位写 1, 16 位写 2< / em >
msgs[< span class = "hl-number" > 1< / span > ].addr = dev-> client_addr;
msgs[< span class = "hl-number" > 1< / span > ].flags = RT_I2C_RD; < em class = "hl-comment" > //读标志< / em >
msgs[< span class = "hl-number" > 1< / span > ].buf = data; < em class = "hl-comment" > //读取到数据存放位置< / em >
msgs[< span class = "hl-number" > 1< / span > ].len = len; < em class = "hl-comment" > //要读取的长度< / em >
< strong class = "hl-keyword" > if< / strong > (rt_i2c_transfer(dev-> bus, msgs, < span class = "hl-number" > 2< / span > ) == < span class = "hl-number" > 2< / span > ) { < em class = "hl-comment" > //标准的 i2c 读流程都是先写后读,先把要读的寄存器发出去,再读数据,所以这里 msgs 的数量是 2< / em >
< strong class = "hl-keyword" > return< / strong > RT_EOK;
} < strong class = "hl-keyword" > else< / strong > {
< strong class = "hl-keyword" > return< / strong > -RT_ERROR;
}
}< / pre >
< / div > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_vg2_mxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_vg2_mxf_1dc" > < h2 class = "- topic/title title sectiontitle" > gt911 获得设备 ID 函数编写< / h2 >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_wg2_mxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_wg2_mxf_1dc" > < strong class = "hl-keyword" > static< / strong > rt_err_t gt911_get_product_id(< strong class = "hl-keyword" > struct< / strong > rt_i2c_client *dev,
rt_uint8_t *data, rt_uint8_t len)
{
rt_uint8_t reg[< span class = "hl-number" > 2< / span > ];
reg[< span class = "hl-number" > 0< / span > ] = (rt_uint8_t)(GT911_PRODUCT_ID > > < span class = "hl-number" > 8< / span > );
reg[< span class = "hl-number" > 1< / span > ] = (rt_uint8_t)(GT911_PRODUCT_ID & < span class = "hl-number" > 0xff< / span > );
< strong class = "hl-keyword" > if< / strong > (gt911_read_regs(dev, reg, data, len) != RT_EOK) {
LOG_E(< span class = "hl-string" > "read id failed"< / span > );
< strong class = "hl-keyword" > return< / strong > -RT_ERROR;
}
< strong class = "hl-keyword" > return< / strong > RT_EOK;
}< / pre >
< div class = "- topic/p p" data-ofbid = "d199564e42__20250121171633" >
< div class = "- topic/div div section" >
< p class = "- topic/p p" data-ofbid = "d199564e46__20250121171633" > 以
gt911 获得设备 ID 的函数来讲解一下 gt911 读函数的使用:< / p >
< ul class = "- topic/ul ul simple" id = "reference_qpq_jwf_1dc__ul_xg2_mxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__ul_xg2_mxf_1dc" > < li class = "- topic/li li" data-ofbid = "d199564e51__20250121171633" >
< p class = "- topic/p p" data-ofbid = "d199564e53__20250121171633" > 第一步是定义一个 rt_uint8_t 的数组;< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d199564e56__20250121171633" > 第二步将要读取的寄存器赋值给数组< ul class = "- topic/ul ul" id = "reference_qpq_jwf_1dc__ul_zg2_mxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__ul_zg2_mxf_1dc" > < li class = "- topic/li li" data-ofbid = "d199564e59__20250121171633" >
< p class = "- topic/p p" data-ofbid = "d199564e61__20250121171633" > 16 位的 CTP 需将高 8 位赋值给 reg[0],低 8 位赋值给 reg[1]< / p >
< / li > < li class = "- topic/li li" data-ofbid = "d199564e64__20250121171633" >
< p class = "- topic/p p" data-ofbid = "d199564e66__20250121171633" > 8 位的 CTP 则只需要把寄存器直接赋给 reg[0]< / p >
< / li > < / ul > < / li > < li class = "- topic/li li" data-ofbid = "d199564e69__20250121171633" >
< p class = "- topic/p p" data-ofbid = "d199564e71__20250121171633" > 第三步调用自己编写的 CTP 读函数把相关的参数传递过去。< / p >
< / li > < / ul >
< div class = "- topic/note note note note_note" id = "reference_qpq_jwf_1dc__note_bg3_dyf_1dc" data-ofbid = "reference_qpq_jwf_1dc__note_bg3_dyf_1dc" > < span class = "note__title" > 注:< / span >
< p class = "- topic/p p" data-ofbid = "d199564e77__20250121171633" > 若某些触控芯片无设备 ID 寄存器,则此函数可直接返回成功状态。< / p >
< / div >
< / div >
< / div >
< / div > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_yw1_pxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_yw1_pxf_1dc" > < h2 class = "- topic/title title sectiontitle" > gt911 获得设备信息参数函数< / h2 >
< p class = "- topic/p p" data-ofbid = "d199564e89__20250121171633" > 此函数旨在提取触控屏的关键信息,如分辨率、坐标范围。其编写逻辑与获取 ID 相似,利用读寄存器操作完成。< / p >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_nd4_cyf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_nd4_cyf_1dc" > < strong class = "hl-keyword" > static< / strong > rt_err_t gt911_get_info(< strong class = "hl-keyword" > struct< / strong > rt_i2c_client *dev,
< strong class = "hl-keyword" > struct< / strong > rt_touch_info *info)< / pre >
< / div > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_iw3_pxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_iw3_pxf_1dc" > < h2 class = "- topic/title title sectiontitle" > gt911 读坐标点函数< / h2 >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_or2_wxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_or2_wxf_1dc" > < strong class = "hl-keyword" > static< / strong > rt_size_t gt911_read_point(< strong class = "hl-keyword" > struct< / strong > rt_touch_device *touch, < strong class = "hl-keyword" > void< / strong > *buf,
rt_size_t read_num)< / pre >
< p class = "- topic/p p" data-ofbid = "d199564e103__20250121171633" > 此为核心函数,负责读取触控点坐标及事件类型(如按下、移动、抬起)。利用之前定义的读写函数,结合逻辑判断处理触控事件,由于篇幅过长在这里不一一展开,建议参考 gt911 驱动。< / p >
< / div > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_hmk_pxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_hmk_pxf_1dc" > < h2 class = "- topic/title title sectiontitle" > gt911 控制函数< / h2 >
< p class = "- topic/p p" data-ofbid = "d199564e111__20250121171633" > 此函数提供了通过命令控制触控面板的能力,涵盖获取 ID、信息查询及参数设置等功能, 是驱动对外交互的接口。< / p >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_jsd_wxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_jsd_wxf_1dc" > < strong class = "hl-keyword" > static< / strong > rt_err_t gt911_control(< strong class = "hl-keyword" > struct< / strong > rt_touch_device *touch, < strong class = "hl-keyword" > int< / strong > cmd, < strong class = "hl-keyword" > void< / strong > *arg)< / pre >
< / div > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_f2m_pxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_f2m_pxf_1dc" > < h2 class = "- topic/title title sectiontitle" > gt911 ops 注册函数< / h2 >
< p class = "- topic/p p" data-ofbid = "d199564e122__20250121171633" > 此函数将读点和控制功能注册到触摸驱动框架中,确保系统能正确调用这些操作< / p >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_m2b_wxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_m2b_wxf_1dc" > < strong class = "hl-keyword" > static< / strong > < strong class = "hl-keyword" > struct< / strong > rt_touch_ops gt911_touch_ops = {
.touch_readpoint = gt911_read_point,
.touch_control = gt911_control,
};< / pre >
< / div > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_w1f_wyf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_w1f_wyf_1dc" > < h2 class = "- topic/title title sectiontitle" > gt911 gpio 引脚定义函数< / h2 >
< p class = "- topic/p p" data-ofbid = "d199564e133__20250121171633" > 此函数提供了通过命令控制触控面板的能力,涵盖获取 ID、信息查询及参数设置等功能, 是驱动对外交互的接口。< / p >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_x1f_wyf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_x1f_wyf_1dc" > < strong class = "hl-keyword" > static< / strong > < strong class = "hl-keyword" > int< / strong > rt_gt911_gpio_cfg()
{
< strong class = "hl-keyword" > unsigned< / strong > < strong class = "hl-keyword" > int< / strong > g, p;
< strong class = "hl-keyword" > long< / strong > pin;
< em class = "hl-comment" > // RST< / em >
pin = drv_pin_get(GT911_RST_PIN); < em class = "hl-comment" > //复位引脚的宏定义< / em >
g = GPIO_GROUP(pin);
p = GPIO_GROUP_PIN(pin);
hal_gpio_direction_input(g, p);
< em class = "hl-comment" > // INT< / em >
pin = drv_pin_get(GT911_INT_PIN); < em class = "hl-comment" > //中断引脚的宏定义< / em >
g = GPIO_GROUP(pin);
p = GPIO_GROUP_PIN(pin);
hal_gpio_direction_input(g, p);
hal_gpio_set_irq_mode(g, p, < span class = "hl-number" > 0< / span > );
< strong class = "hl-keyword" > return< / strong > < span class = "hl-number" > 0< / span > ;
}< / pre >
< / div > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_vtm_pxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_vtm_pxf_1dc" > < h2 class = "- topic/title title sectiontitle" > gt911 初始化函数< / h2 >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_h4x_vxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_h4x_vxf_1dc" > < strong class = "hl-keyword" > static< / strong > < strong class = "hl-keyword" > int< / strong > rt_hw_gt911_init(< strong class = "hl-keyword" > const< / strong > < strong class = "hl-keyword" > char< / strong > *name, < strong class = "hl-keyword" > struct< / strong > rt_touch_config *cfg)
{
< strong class = "hl-keyword" > struct< / strong > rt_touch_device *touch_device = RT_NULL; < em class = "hl-comment" > //初始化触摸设备句柄< / em >
touch_device =
(< strong class = "hl-keyword" > struct< / strong > rt_touch_device *)rt_malloc(< strong class = "hl-keyword" > sizeof< / strong > (< strong class = "hl-keyword" > struct< / strong > rt_touch_device)); < em class = "hl-comment" > //动态分配内存< / em >
< strong class = "hl-keyword" > if< / strong > (touch_device == RT_NULL) {
LOG_E(< span class = "hl-string" > "touch device malloc fail"< / span > );
< strong class = "hl-keyword" > return< / strong > -RT_ERROR;
}
rt_memset((< strong class = "hl-keyword" > void< / strong > *)touch_device, < span class = "hl-number" > 0< / span > , < strong class = "hl-keyword" > sizeof< / strong > (< strong class = "hl-keyword" > struct< / strong > rt_touch_device)); < em class = "hl-comment" > //初始化内存空间为 0< / em >
< em class = "hl-comment" > /* hw init*/< / em >
< em class = "hl-comment" > // rst output 0< / em >
rt_pin_mode(*(rt_uint8_t *)cfg-> user_data, PIN_MODE_OUTPUT); < em class = "hl-comment" > //设置复位引脚的方向< / em >
rt_pin_write(*(rt_uint8_t *)cfg-> user_data, PIN_LOW); < em class = "hl-comment" > //设置输出低电平< / em >
rt_thread_delay(< span class = "hl-number" > 10< / span > ); < em class = "hl-comment" > //一般设置完输出要延时一段时间,具体多少看规格书< / em >
< em class = "hl-comment" > // irq output 0< / em >
rt_pin_mode(cfg-> irq_pin.pin, PIN_MODE_OUTPUT); < em class = "hl-comment" > //设置中断引脚的方向< / em >
rt_pin_write(cfg-> irq_pin.pin, PIN_LOW);
rt_thread_delay(< span class = "hl-number" > 2< / span > );
< em class = "hl-comment" > // rst output 1< / em >
rt_pin_mode(*(rt_uint8_t *)cfg-> user_data, PIN_MODE_OUTPUT);
rt_pin_write(*(rt_uint8_t *)cfg-> user_data, PIN_HIGH); < em class = "hl-comment" > //设置输出高电平< / em >
rt_thread_delay(< span class = "hl-number" > 5< / span > );
< em class = "hl-comment" > // rst input< / em >
rt_pin_mode(*(rt_uint8_t *)cfg-> user_data, PIN_MODE_INPUT);
< em class = "hl-comment" > //irq output 0< / em >
rt_pin_mode(cfg-> irq_pin.pin, PIN_MODE_OUTPUT);
rt_pin_write(cfg-> irq_pin.pin, PIN_LOW);
rt_thread_delay(< span class = "hl-number" > 50< / span > );
rt_pin_mode(cfg-> irq_pin.pin, PIN_MODE_INPUT);
gt911_client.bus =
(< strong class = "hl-keyword" > struct< / strong > rt_i2c_bus_device *)rt_device_find(cfg-> dev_name); < em class = "hl-comment" > //寻找 i2c 总线< / em >
< strong class = "hl-keyword" > if< / strong > (gt911_client.bus == RT_NULL) {
LOG_E(< span class = "hl-string" > "Can't find %s device"< / span > , cfg-> dev_name);
< strong class = "hl-keyword" > return< / strong > -RT_ERROR;
}
< strong class = "hl-keyword" > if< / strong > (rt_device_open((rt_device_t)gt911_client.bus, RT_DEVICE_FLAG_RDWR) !=
RT_EOK) { < em class = "hl-comment" > //打开设备< / em >
LOG_E(< span class = "hl-string" > "open %s device failed"< / span > , cfg-> dev_name);
< strong class = "hl-keyword" > return< / strong > -RT_ERROR;
}
gt911_client.client_addr = GT911_ADDRESS_HIGH; < em class = "hl-comment" > //将 CTP 的设备地址进行赋值< / em >
< em class = "hl-comment" > /* register touch device */< / em >
touch_device-> info.type = RT_TOUCH_TYPE_CAPACITANCE;
touch_device-> info.vendor = RT_TOUCH_VENDOR_GT;
rt_memcpy(& touch_device-> config, cfg, < strong class = "hl-keyword" > sizeof< / strong > (< strong class = "hl-keyword" > struct< / strong > rt_touch_config));
touch_device-> ops = & gt911_touch_ops;
< strong class = "hl-keyword" > if< / strong > (RT_EOK != rt_hw_touch_register(touch_device, name, RT_DEVICE_FLAG_INT_RX, RT_NULL)) { < em class = "hl-comment" > //注册触摸设备< / em >
LOG_E(< span class = "hl-string" > "touch device gt911 init failed !!!"< / span > );
< strong class = "hl-keyword" > return< / strong > -RT_ERROR;
}
LOG_I(< span class = "hl-string" > "touch device gt911 init success"< / span > );
< strong class = "hl-keyword" > return< / strong > RT_EOK;
}< / pre >
< p class = "- topic/p p" data-ofbid = "d199564e147__20250121171633" > 此函数完成硬件初始化、I²C 总线配置、设备结构体设置及注册触摸设备等关键步骤。遵循芯片规格书中关于复位和中断引脚的操作时序< / p >
< / div > < div class = "- topic/example example" id = "reference_qpq_jwf_1dc__example_wjn_pxf_1dc" data-ofbid = "reference_qpq_jwf_1dc__example_wjn_pxf_1dc" > < h2 class = "- topic/title title sectiontitle" > gt911 驱动注册函数< / h2 >
< pre class = "+ topic/pre pr-d/codeblock pre codeblock language-c" id = "reference_qpq_jwf_1dc__codeblock_qt1_5xf_1dc" data-ofbid = "reference_qpq_jwf_1dc__codeblock_qt1_5xf_1dc" > < strong class = "hl-keyword" > static< / strong > < strong class = "hl-keyword" > int< / strong > rt_hw_gt911_port(< strong class = "hl-keyword" > void< / strong > )
{
< strong class = "hl-keyword" > struct< / strong > rt_touch_config cfg;
rt_uint8_t rst_pin;
rt_gt911_gpio_cfg();
rst_pin = drv_pin_get(GT911_RST_PIN); < em class = "hl-comment" > //复位引脚宏定义< / em >
cfg.dev_name = GT911_I2C_CHAN;
cfg.irq_pin.pin = drv_pin_get(GT911_INT_PIN); < em class = "hl-comment" > //中断引脚宏定义< / em >
cfg.irq_pin.mode = PIN_MODE_INPUT;
cfg.user_data = & rst_pin;
rt_hw_gt911_init(< span class = "hl-string" > "gt911"< / span > , & cfg);
< strong class = "hl-keyword" > return< / strong > < span class = "hl-number" > 0< / span > ;
}
INIT_DEVICE_EXPORT(rt_hw_gt911_port);< / pre >
< p class = "- topic/p p" data-ofbid = "d199564e158__20250121171633" > 通过宏
< span class = "+ topic/keyword pr-d/apiname keyword apiname" > INIT_DEVICE_EXPORT< / span > ,驱动在系统启动时自动加载。只需调整引脚宏定义和设备名称,即可轻松适配不同型号的触控芯片,假设硬件 CTP 是 FT7411 则将示例中的 gt911 替换为 ft7411, 以及修改对应的引脚宏定义< / p >
< / div > < / div > < / article > < / main > < / div >
< / div >
< nav role = "navigation" id = "wh_topic_toc" aria-label = "On this page" class = "col-lg-2 d-none d-lg-block navbar d-print-none" >
< div id = "wh_topic_toc_content" >
< div class = " wh_topic_toc " > < div class = "wh_topic_label" > 在本页上< / div > < ul > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_rg2_mxf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_rg2_mxf_1dc" > 写寄存器函数:用于向 gt911 发送控制命令或数据< / a > < / li > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_tg2_mxf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_tg2_mxf_1dc" > 读寄存器函数:用于从 gt911 读取状态或数据< / a > < / li > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_vg2_mxf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_vg2_mxf_1dc" > gt911 获得设备 ID 函数编写< / a > < / li > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_yw1_pxf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_yw1_pxf_1dc" > gt911 获得设备信息参数函数< / a > < / li > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_iw3_pxf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_iw3_pxf_1dc" > gt911 读坐标点函数< / a > < / li > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_hmk_pxf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_hmk_pxf_1dc" > gt911 控制函数< / a > < / li > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_f2m_pxf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_f2m_pxf_1dc" > gt911 ops 注册函数< / a > < / li > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_w1f_wyf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_w1f_wyf_1dc" > gt911 gpio 引脚定义函数< / a > < / li > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_vtm_pxf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_vtm_pxf_1dc" > gt911 初始化函数< / a > < / li > < li class = "section-title" > < a href = "#reference_qpq_jwf_1dc__example_wjn_pxf_1dc" data-tocid = "reference_qpq_jwf_1dc__example_wjn_pxf_1dc" > gt911 驱动注册函数< / a > < / li > < / ul > < / div >
< / div >
< / nav >
< / div >
< / div >
< / div >
< footer class = "navbar navbar-default wh_footer" >
< div class = " footer-container mx-auto " >
< title > footer def< / title >
< style > < ! - -
.p1 {
font-family: FangZhengShuSong, Times, serif;
}
.p2 {
font-family: Arial, Helvetica, sans-serif;
}
.p3 {
font-family: "Lucida Console", "Courier New", monospace;
}
-->< / style >
< div class = "webhelp.fragment.footer" >
< p class = "p1" > Copyright © 2019-2024 广东匠芯创科技有限公司. All rights reserved.< / p >
< / div > < div >
< div class = "generation_time" >
Update Time: 2025-01-21
< / div >
< / div >
< / div >
< / footer >
< div id = "go2top" class = "d-print-none" >
< span class = "oxy-icon oxy-icon-up" > < / span >
< / div >
< div id = "modal_img_large" class = "modal" >
< span class = "close oxy-icon oxy-icon-remove" > < / span >
< div id = "modal_img_container" > < / div >
< div id = "caption" > < / div >
< / div >
< script src = "${pd}/publishing/publishing-styles-AIC-template/js/custom.js" defer = "defer" > < / script >
< / body >
2025-01-23 16:37:00 +08:00
< / html >