读《RT-Thread设备驱动开发指南》---第二篇
<div class='showpostmsg'> 本帖最后由 xiaolinen 于 2023-8-30 22:19 编辑<p style="text-align: center;"><span style="font-size:20px;"><strong>读《RT-Thread设备驱动开发指南》--- TOUCH设备驱动开发</strong></span></p>
<p><span style="font-size:20px;">第一部分:了解Touch层级结构</span></p>
<p><span style="font-size:20px;"> 1)什么是Touch设备:</span></p>
<p><span style="font-size:20px;"> Touch设备就是触摸设备,是目前嵌入式人机交互领域常用的输入设备。</span></p>
<p><span style="font-size:20px;"> 2)Touch的层级结构:</span></p>
<p><span style="font-size:20px;"> 如图所示,即是Touch设备的层级结构示意:</span></p>
<div style="text-align: center;"></div>
<div style="text-align: center;"><span style="color:#e74c3c;"><span style="font-size:18px;">注:图中只体现出的硬件层的IIC总线,其实也可以通过SPI总线实现!</span></span></div>
<div><span style="font-size:20px;"> 2.1)图中的应用层主要是开发者自己编写的应用代码,调用统一的I/O设备操作函数,实现自己的业务需求。</span></div>
<div><span style="font-size:20px;"> 2.2)I/O设备管理层主要是为设备驱动框架提供统一的操作接口,即rt_device_find,rt_device_open,rt_device_control等。</span></div>
<div><span style="font-size:20px;"> 2.3)Touch设备驱动框架层是对触摸设备基本功能的抽象,与硬件无关,需要开发者自行实现这部分操作方法,比如:rt_touch_info;另外,Touch设备属于I/O设备的一类,同样需要进行设备注册操作,接口为:rt_hw_touch_register。</span></div>
<div><span style="font-size:20px;"> 2.4)Touch设备驱动层就是针对具体的触摸芯片编写的,开发者可借助RT-Thread提供的软件包快速实现功能,本次实验就会用到XPT2046相关软件包。</span></div>
<div><span style="font-size:20px;"> 2.5)硬件层就是对应不同厂家,不同型号的触摸芯片,如:IIC总线的FT5426,GT911等;SPI总线的XPT2046,HR2046等。</span></div>
<p><span style="font-size:20px;">第二部分:Touch设备涉及到的函数接口</span></p>
<p><span style="font-size:20px;"> 查找设备</span></p>
<p> </p>
<pre data-lang="c" v-pre="">
<code>rt_device_t rt_device_find(const char* name);</code></pre>
<p><span style="font-size:20px;"> 打开设备</span></p>
<p> </p>
<pre data-lang="c" v-pre="">
<code>rt_err_t rt_device_open(rt_device_t dev, rt_uint16_t oflags);</code></pre>
<p><span style="font-size:20px;"> 读设备</span></p>
<p> </p>
<pre data-lang="c" v-pre="">
<code>rt_size_t rt_device_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size);</code></pre>
<p><span style="font-size:20px;"> 控制设备</span></p>
<p> </p>
<pre data-lang="c" v-pre="">
<code>rt_err_t rt_device_control(rt_device_t dev, rt_uint8_t cmd, void* arg);</code></pre>
<p><span style="font-size:20px;"> 设置接收回调函数</span></p>
<p> </p>
<pre data-lang="c" v-pre="">
<code>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));</code></pre>
<p><span style="font-size:20px;"> 关闭设备</span></p>
<p> </p>
<pre data-lang="c" v-pre="">
<code>rt_err_t rt_device_close(rt_device_t dev);</code></pre>
<p><span style="font-size:20px;">第三部分:实验用到的相关软件包以及效果</span></p>
<p><span style="font-size:20px;"> 3.1)软件包添加路径:</span></p>
<div style="text-align: center;"></div>
<p style="text-align: center;"><span style="color: rgb(231, 76, 60); text-align: center;">注:该软件包依赖:RT-Thread 4.0+,SPI设备驱动程序,PIN设备驱动程序</span></p>
<p><span style="font-size:20px;"> 3.2)查找设备:</span></p>
<pre>
<code>#define PRO_TOUCH_EQU "xpt0"
rt_device_t touch = rt_device_find(PRO_TOUCH_EQU);
if (touch == RT_NULL)
{
LOG_E("can't find device: %s\n", PRO_TOUCH_EQU);
return;
}</code></pre>
<p><span style="font-size:20px;"> 3.3)打开设备:</span></p>
<pre>
<code>if (rt_device_open(touch, RT_DEVICE_FLAG_INT_RX) != RT_EOK)
{
LOG_E("open %s failed!\n",PRO_TOUCH_EQU);
return;
}</code></pre>
<p><span style="font-size:20px;"> 3.4)读设备:</span></p>
<pre>
<code>if (rt_device_read(touch, 0, &read_data, 1) == 1)
{
LOG_I("x = %d,y = %d\n",read_data.x_coordinate,read_data.y_coordinate);
}</code></pre>
<p><span style="font-size:20px;"> 3.5)打印输出:</span></p>
<p><span style="font-size:20px;"> 操作为触摸屏进行校准后,手指长按一个点,不动。</span></p>
<pre>
<code>ph_xpt2046: x = 3189,y = 1994
ph_xpt2046: x = 3199,y = 1977
ph_xpt2046: x = 3199,y = 1979
ph_xpt2046: x = 3213,y = 1972
ph_xpt2046: x = 3247,y = 1991
ph_xpt2046: x = 3247,y = 1979
ph_xpt2046: x = 3247,y = 1967
ph_xpt2046: x = 3247,y = 1971
ph_xpt2046: x = 3247,y = 1955
ph_xpt2046: x = 3199,y = 1973
ph_xpt2046: x = 3199,y = 1990
ph_xpt2046: x = 3199,y = 2007
ph_xpt2046: x = 3167,y = 2039
ph_xpt2046: x = 3071,y = 2019
ph_xpt2046: x = 2943,y = 1911
ph_xpt2046: x = 2735,y = 1871
ph_xpt2046: x = 2523,y = 1865
ph_xpt2046: x = 2399,y = 1853
ph_xpt2046: x = 2295,y = 1839</code></pre>
<p> </p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> _device_read(touch, 0, &read_data, 1) == 1) { LOG_I("x = %d,y = %d\n",read_data.x_coordinate,read_data.y_coordinate); }这个&read_data怎么设置能讲一下吗
页:
[1]