<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cyher.NET &#187; input</title>
	<atom:link href="http://cyher.net/tag/input/feed" rel="self" type="application/rss+xml" />
	<link>http://cyher.net</link>
	<description>Technology, Life, Code, OpenSource, *nix, Mac and iphone, Mobile development</description>
	<lastBuildDate>Wed, 16 Mar 2011 01:25:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>android驱动之jogball</title>
		<link>http://cyher.net/gnulinux/android/android-driver-jogball</link>
		<comments>http://cyher.net/gnulinux/android/android-driver-jogball#comments</comments>
		<pubDate>Tue, 16 Mar 2010 09:18:16 +0000</pubDate>
		<dc:creator>cyher</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[driver]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://cyher.net/?p=637024</guid>
		<description><![CDATA[1 简介 JogBall是首款Android手机-HTC Dream上附带的类似轨迹球Trackball的滑轮，通过Jogball用户可以轻松的实现网页的翻页、地图翻 转等操作，这种在手机上增加轨迹球的方式可以取消传统的4维导航键，Jogball并非HTC公司的首例，早在HTC 3300(Dopod P800)就 实现了这项功能，轨迹球操作方式的加入可以实现像电脑上鼠标一样轻松操控。现在jogball基本上算是android手机的标准配置了。 2 框图&#38;架构 2.1 gpio_event子系统 Jogball驱动是由linux代码中的gpio_event子系统实现的。 由以下文件组成： driver/input/misc/gpio_event.c driver/input/misc/gpio_input.c driver/input/misc/gpio_output.c driver/input/misc/gpio_matrix.c driver/input/misc/gpio_axis.c gpio_event子系统是一个关于gpio的输入设备的通用代码，里面可以包含一般嵌入式设备中需要的键盘阵列和坐标有关的输入等。 2.2 Jogball架构 Jogball是归类于gpio_axis.c中的，是一个相对坐标系，判断电信号的高低来对坐标加或者减一定数值。具体细节在gpio_axis.c中 gpio_axis.c中的结构体初始化是在xxx-borad.c中的，基本架构就是这样，细节在下文叙述。 3 硬件描述 3.1 Jogball机械特性 Jogball是一个基于滚球滚动的输入设备，所以它机械特性也是比较重要，知道他的机械特性，便于我们理解驱动。 Jogball和以前的滚球鼠标比较相似，依靠滚轮的滚动来带动四周的圆柱体旋转。每个圆柱体端头都有一个磁铁，这个磁体铁从横断 面来看就是由N极的扇形和S极的扇形来组成一个圆周。这样当磁铁旋转的时候，N极和S极切换，使霍尔IC产生高低电平。 注意：在滚球旋转时，两个相对方向只有一个方向可以转动，这是为了减化软件编写的一个机械特性。 3.2 Jogball的电气特性 Jogball最重要的电特性就是这个霍尔IC， 霍尔元件的工作原理：所谓霍尔效应，是指磁场作用于载流金属导体、半导体中的载流子时，产生横向电位差的物理现 象。金属的霍尔效应是1879年被美 国物理学家霍尔发现的。当电流通过金属箔片时，若在垂直于电流的方向施加磁场，则金属箔片 两侧面会出现横向电位差。半导体中的霍尔效应比金属箔片中更为明 显，而铁磁金属在居里温度以下将呈现极强的霍尔效应。 所以jogball是旋转磁轴引起磁场的变幻，来产生高低电压的。从而根据机械特性就不难理解jogball的数字输入过程。 3.3 Jogball的原理图 其实jogball只是机械结构,原理图是hall ic的,有兴趣的人在这里下载 4 数据结构 struct hero_axis_info &#123; struct gpio_event_axis_info info; /*gpio_event_axis结构的信息*/ uint16_t [...]]]></description>
			<content:encoded><![CDATA[<h1><span style="color: #000000;">1 简介</span></h1>
<p>JogBall是首款Android手机-HTC Dream上附带的类似轨迹球Trackball的滑轮，通过Jogball用户可以轻松的实现网页的翻页、地图翻</p>
<p>转等操作，这种在手机上增加轨迹球的方式可以取消传统的4维导航键，Jogball并非HTC公司的首例，早在HTC 3300(Dopod P800)就</p>
<p>实现了这项功能，轨迹球操作方式的加入可以实现像电脑上鼠标一样轻松操控。现在jogball基本上算是android手机的标准配置了。</p>
<h1><span style="color: #000000;">2 框图&amp;架构</span></h1>
<p><span style="color: #000000;"><br />
</span></p>
<h3><span style="color: #000000;">2.1    gpio_event子系统</span></h3>
<p>Jogball驱动是由linux代码中的gpio_event子系统实现的。<br />
由以下文件组成：</p>
<ul>
<li> <a href="http://cyher.net/tag/driver" class="st_tag internal_tag" rel="tag" title="标签 driver 下的日志">driver</a>/input/misc/gpio_event.c</li>
<li> driver/input/misc/gpio_input.c</li>
<li> driver/input/misc/gpio_output.c</li>
<li> driver/input/misc/gpio_matrix.c</li>
<li> driver/input/misc/gpio_axis.c</li>
</ul>
<p>gpio_event子系统是一个关于gpio的输入设备的通用代码，里面可以包含一般嵌入式设备中需要的键盘阵列和坐标有关的输入等。</p>
<h3><span style="color: #000000;">2.2 Jogball架构</span></h3>
<p>Jogball是归类于gpio_axis.c中的，是一个相对坐标系，判断电信号的高低来对坐标加或者减一定数值。具体细节在gpio_axis.c中</p>
<p>gpio_axis.c中的结构体初始化是在xxx-borad.c中的，基本架构就是这样，细节在下文叙述。</p>
<h1><span style="color: #000000;">3 硬件描述</span></h1>
<p><span style="color: #000000;"><br />
</span></p>
<h3><span style="color: #000000;">3.1 Jogball机械特性</span></h3>
<p>Jogball是一个基于滚球滚动的输入设备，所以它机械特性也是比较重要，知道他的机械特性，便于我们理解驱动。<br />
Jogball和以前的滚球鼠标比较相似，依靠滚轮的滚动来带动四周的圆柱体旋转。每个圆柱体端头都有一个磁铁，这个磁体铁从横断</p>
<p>面来看就是由N极的扇形和S极的扇形来组成一个圆周。这样当磁铁旋转的时候，N极和S极切换，使霍尔IC产生高低电平。<br />
注意：在滚球旋转时，两个相对方向只有一个方向可以转动，这是为了减化软件编写的一个机械特性。</p>
<h3><span style="color: #000000;">3.2 Jogball的电气特性</span></h3>
<p>Jogball最重要的电特性就是这个霍尔IC，</p>
<blockquote><p>霍尔元件的工作原理：所谓霍尔效应，是指磁场作用于载流金属导体、半导体中的载流子时，产生横向电位差的物理现</p>
<p>象。金属的霍尔效应是1879年被美 国物理学家霍尔发现的。当电流通过金属箔片时，若在垂直于电流的方向施加磁场，则金属箔片</p>
<p>两侧面会出现横向电位差。半导体中的霍尔效应比金属箔片中更为明 显，而铁磁金属在居里温度以下将呈现极强的霍尔效应。</p></blockquote>
<p>所以jogball是旋转磁轴引起磁场的变幻，来产生高低电压的。从而根据机械特性就不难理解jogball的数字输入过程。</p>
<p>3.3 Jogball的原理图</p>
<p>其实jogball只是机械结构,原理图是hall ic的,有兴趣的人在<a href="http://www.datasheetarchive.com/pdf-datasheets/Datasheets-24/DSA-469829.pdf" target="_blank">这里下载</a></p>
<h1><span style="color: #000000;">4 数据结构</span></h1>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> hero_axis_info <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">struct</span> gpio_event_axis_info info<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*gpio_event_axis结构的信息*/</span>
        <span style="color: #993333;">uint16_t</span> in_state<span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*记录输入的高低电平信号*/</span>
        <span style="color: #993333;">uint16_t</span> out_state<span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*记录输出的高低电平信号*/</span>
        <span style="color: #993333;">uint16_t</span> temp_state<span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*临时存储高低电平*/</span>
        <span style="color: #993333;">uint16_t</span> threshold<span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*门限值，超过这个值上报给input子系统*/</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">struct</span> gpio_event_axis_info <span style="color: #009900;">&#123;</span>
        <span style="color: #808080; font-style: italic;">/* initialize to gpio_event_axis_func */</span>
        <span style="color: #993333;">struct</span> gpio_event_info info<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*gpio_event信息*/</span>
        <span style="color: #993333;">uint8_t</span>  count<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*gpio的数量*/</span>
        <span style="color: #993333;">uint8_t</span>  type<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* EV_REL or EV_ABS */</span>
        <span style="color: #993333;">uint16_t</span> code<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*输入键值类型*/</span>
        <span style="color: #993333;">uint16_t</span> decoded_size<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*gpio 数组的大小*/</span>
        <span style="color: #993333;">uint16_t</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>map<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> gpio_event_axis_info <span style="color: #339933;">*</span>info<span style="color: #339933;">,</span> <span style="color: #993333;">uint16_t</span> in<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*解析回调函数*/</span>
        <span style="color: #993333;">uint32_t</span> <span style="color: #339933;">*</span>gpio<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*gpio端口数组*/</span>
        <span style="color: #993333;">uint32_t</span> flags<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*调试标值*/</span>
        <span style="color: #993333;">uint32_t</span> enable_emc_protect_delay<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*保护间隔时间*/</span>
        <span style="color: #993333;">uint16_t</span> emc_gpio_state<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* 延时中用到gpio_state*/</span>
        atomic_t emc_disable_irqnum<span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*延时中用到的屏蔽的中断号*/</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">struct</span> gpio_event_info <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> input_dev <span style="color: #339933;">*</span>input_dev<span style="color: #339933;">,</span>
        <span style="color: #993333;">struct</span> gpio_event_info <span style="color: #339933;">*</span>info<span style="color: #339933;">,</span>
        <span style="color: #993333;">void</span> <span style="color: #339933;">**</span>data<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> func<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #808080; font-style: italic;">/*给gpio_event子系统中实现注册到内核中的回调函数*/</span>
        <span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> input_dev <span style="color: #339933;">*</span>input_dev<span style="color: #339933;">,</span>
        <span style="color: #993333;">struct</span> gpio_event_info <span style="color: #339933;">*</span>info<span style="color: #339933;">,</span>
        <span style="color: #993333;">void</span> <span style="color: #339933;">**</span>data<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> type<span style="color: #339933;">,</span>
        <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> code<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* out events */</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">struct</span> gpio_event_platform_data <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>name<span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*名字*/</span>
        <span style="color: #993333;">struct</span> gpio_event_info <span style="color: #339933;">**</span>info<span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*gpio_event的结构指针*/</span>
        size_t info_count<span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*注册到axis中的info 结构体的数量*/</span>
        <span style="color: #993333;">int</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>power<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">struct</span> gpio_event_platform_data <span style="color: #339933;">*</span>pdata<span style="color: #339933;">,</span> bool on<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*电源管理回调函数*/</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<h1><span style="color: #000000;">5 代码分析</span></h1>
<h3><span style="color: #000000;">5.1 通用代码</span></h3>
<p>driver/input/misc/gpio_event.c</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*gpio_event基本数据结构*/</span>
<span style="color: #993333;">struct</span> gpio_event <span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">struct</span> input_dev <span style="color: #339933;">*</span>input_dev<span style="color: #339933;">;</span>
        <span style="color: #993333;">const</span> <span style="color: #993333;">struct</span> gpio_event_platform_data <span style="color: #339933;">*</span>info<span style="color: #339933;">;</span>
        <span style="color: #993333;">struct</span> early_suspend early_suspend<span style="color: #339933;">;</span>
        <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>state<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*注册给input的回调函数*/</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> gpio_input_event<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> input_dev <span style="color: #339933;">*</span>dev<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> type<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> code<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*调用下层给的回调函数来实现具体的注册*/</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> gpio_event_call_all_func<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> gpio_event <span style="color: #339933;">*</span>ip<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> func<span style="color: #009900;">&#41;</span>
<span style="color: #808080; font-style: italic;">/*电源管理*/</span>
<span style="color: #339933;">#ifdef CONFIG_HAS_EARLYSUSPEND</span>
<span style="color: #993333;">void</span> gpio_event_suspend<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> early_suspend <span style="color: #339933;">*</span>h<span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #993333;">void</span> gpio_event_resume<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> early_suspend <span style="color: #339933;">*</span>h<span style="color: #009900;">&#41;</span>
<span style="color: #339933;">#endif</span>
<span style="color: #808080; font-style: italic;">/*注册*/</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> __init gpio_event_probe<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> platform_device <span style="color: #339933;">*</span>pdev<span style="color: #009900;">&#41;</span>
<span style="color: #808080; font-style: italic;">/*注销*/</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> gpio_event_remove<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> platform_device <span style="color: #339933;">*</span>pdev<span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> platform_driver gpio_event_driver
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> __devinit gpio_event_init<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> __exit gpio_event_exit<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>gpio_event.c:主要是gpio_event子系统的框架</p>
<h3><span style="color: #000000;">5.2    soc代码</span></h3>
<p>driver/input/misc/gpio_axis.c</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">struct</span> gpio_axis_state <span style="color: #009900;">&#123;</span>
<span style="color: #993333;">struct</span> input_dev <span style="color: #339933;">*</span>input_dev<span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*input设备结构*/</span>
<span style="color: #993333;">struct</span> gpio_event_axis_info <span style="color: #339933;">*</span>info<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*坐标系数据结构*/</span>
<span style="color: #993333;">uint32_t</span> pos<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*位置*/</span>
<span style="color: #993333;">struct</span> hrtimer emc_hrtimer_delay<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* 延时时间*/</span>
atomic_t atomic_emc_hrtimer_is_run<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*延时的原子变量*/</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #808080; font-style: italic;">/*上报input数据*/</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> gpio_event_update_axis<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> gpio_axis_state <span style="color: #339933;">*</span>as<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> report<span style="color: #009900;">&#41;</span>
<span style="color: #808080; font-style: italic;">/*时间处理函数*/</span>
<span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">enum</span> hrtimer_restart emc_progress_hrtimer_handler_func<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> hrtimer <span style="color: #339933;">*</span>timer<span style="color: #009900;">&#41;</span>
<span style="color: #808080; font-style: italic;">/*中断处理函数*/</span>
<span style="color: #993333;">static</span> irqreturn_t gpio_axis_irq_handler<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> irq<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span>dev_id<span style="color: #009900;">&#41;</span>
<span style="color: #808080; font-style: italic;">/*给上层的注册回调函数*/</span>
<span style="color: #993333;">int</span> gpio_event_axis_func<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> input_dev <span style="color: #339933;">*</span>input_dev<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> gpio_event_info <span style="color: #339933;">*</span>info<span style="color: #339933;">,</span> <span style="color: #993333;">void</span> <span style="color: #339933;">**</span>data<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> func<span style="color: #009900;">&#41;</span></pre></div></div>

<h3><span style="color: #000000;">5.3    platform代码</span></h3>
<p>例如：/arch/arm/match-msm/board-72&#215;7.c</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">uint16_t</span> hero_axis_map<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> gpio_event_axis_info <span style="color: #339933;">*</span>info<span style="color: #339933;">,</span> <span style="color: #993333;">uint16_t</span> in<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">struct</span> hero_axis_info <span style="color: #339933;">*</span>ai <span style="color: #339933;">=</span> container_of<span style="color: #009900;">&#40;</span>info<span style="color: #339933;">,</span> <span style="color: #993333;">struct</span> hero_axis_info<span style="color: #339933;">,</span> info<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">uint16_t</span> out <span style="color: #339933;">=</span> ai<span style="color: #339933;">-&gt;</span>out_state<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>nav_just_on<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>jiffies <span style="color: #339933;">==</span> nav_on_jiffies <span style="color: #339933;">||</span> jiffies <span style="color: #339933;">==</span> nav_on_jiffies <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
                <span style="color: #b1b100;">goto</span> ignore<span style="color: #339933;">;</span>
        nav_just_on <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ai<span style="color: #339933;">-&gt;</span>in_state <span style="color: #339933;">^</span> in<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #808080; font-style: italic;">/*检测在方向1上有没有数值变化*/</span>
        out<span style="color: #339933;">--;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ai<span style="color: #339933;">-&gt;</span>n_state <span style="color: #339933;">^</span> in<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #808080; font-style: italic;">/*检测在方向1相对方向上有没有数值变化*/</span>
        out<span style="color: #339933;">++;</span>
ai<span style="color: #339933;">-&gt;;</span>out_state <span style="color: #339933;">=</span> out<span style="color: #339933;">;</span>
ignore<span style="color: #339933;">:</span>
        ai<span style="color: #339933;">-&gt;</span>in_state <span style="color: #339933;">=</span> in<span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ai<span style="color: #339933;">-&gt;</span>out_state <span style="color: #339933;">-</span> ai<span style="color: #339933;">-&gt;</span>temp_state <span style="color: #339933;">==</span> ai<span style="color: #339933;">-&gt;</span>threshold<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ai<span style="color: #339933;">-&gt;</span>temp_state<span style="color: #339933;">++;</span>
        ai<span style="color: #339933;">-&gt;</span>out_state <span style="color: #339933;">=</span> ai<span style="color: #339933;">-&gt;</span>temp_state<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ai<span style="color: #339933;">-&gt;</span>temp_state <span style="color: #339933;">-</span> ai<span style="color: #339933;">-</span>out_state <span style="color: #339933;">==</span> ai<span style="color: #339933;">-&gt;</span>threshold<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        ai<span style="color: #339933;">-&gt;</span>temp_state<span style="color: #339933;">--;</span>
        ai<span style="color: #339933;">-&gt;</span>out_state <span style="color: #339933;">=</span> ai<span style="color: #339933;">-&gt;</span>temp_state<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>abs<span style="color: #009900;">&#40;</span>ai<span style="color: #339933;">-&gt;</span>out_state <span style="color: #339933;">-</span> ai<span style="color: #339933;">-&gt;;</span>temp_state<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> ai<span style="color: #339933;">-&gt;</span>threshold<span style="color: #009900;">&#41;</span>
        ai<span style="color: #339933;">-&gt;</span>temp_state <span style="color: #339933;">=</span> ai<span style="color: #339933;">-&gt;</span>out_state<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">return</span> ai<span style="color: #339933;">-&gt;</span>temp_state<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>以上函数，是最终的数据解析函数，也就是把硬件中读出来的数据，转化为实际的位置变化的函数。此函数主要做了差错控制，增加</p>
<p>了程序的鲁棒性和可订制性。</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> hero_axis_info hero_x_axis <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        .<span style="color: #202020;">threshold</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>
                .<span style="color: #202020;">info</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                .<span style="color: #202020;">info</span>.<span style="color: #202020;">func</span> <span style="color: #339933;">=</span> gpio_event_axis_func<span style="color: #339933;">,</span>
                .<span style="color: #202020;">count</span> <span style="color: #339933;">=</span> ARRAY_SIZE<span style="color: #009900;">&#40;</span>hero_x_axis_gpios<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                .<span style="color: #202020;">type</span> <span style="color: #339933;">=</span> EV_REL<span style="color: #339933;">,</span>
                .<span style="color: #202020;">code</span> <span style="color: #339933;">=</span> REL_X<span style="color: #339933;">,</span>
                .<span style="color: #202020;">decoded_size</span> <span style="color: #339933;">=</span> 1U <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> ARRAY_SIZE<span style="color: #009900;">&#40;</span>hero_x_axis_gpios<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                .<span style="color: #202020;">map</span> <span style="color: #339933;">=</span> hero_axis_map<span style="color: #339933;">,</span>
                .<span style="color: #202020;">gpio</span> <span style="color: #339933;">=</span> hero_x_axis_gpios<span style="color: #339933;">,</span>
                .<span style="color: #202020;">flags</span> <span style="color: #339933;">=</span> GPIOEAF_PRINT_UNKNOWN_DIRECTION <span style="color: #808080; font-style: italic;">/*| GPIOEAF_PRINT_RAW | GPIOEAF_PRINT_EVENT */</span><span style="color: #339933;">,</span>
                .<span style="color: #202020;">enable_emc_protect_delay</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">*</span> NSEC_PER_MSEC<span style="color: #339933;">,</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>X轴上的info结构体的初始化</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> hero_axis_info hero_y_axis <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        .<span style="color: #202020;">threshold</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>
                .<span style="color: #202020;">info</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
                .<span style="color: #202020;">info</span>.<span style="color: #202020;">func</span> <span style="color: #339933;">=</span> gpio_event_axis_func<span style="color: #339933;">,</span>
                .<span style="color: #202020;">count</span> <span style="color: #339933;">=</span> ARRAY_SIZE<span style="color: #009900;">&#40;</span>hero_y_axis_gpios<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                .<span style="color: #202020;">type</span> <span style="color: #339933;">=</span> EV_REL<span style="color: #339933;">,</span>
                .<span style="color: #202020;">code</span> <span style="color: #339933;">=</span> REL_Y<span style="color: #339933;">,</span>
                .<span style="color: #202020;">decoded_size</span> <span style="color: #339933;">=</span> 1U <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span> ARRAY_SIZE<span style="color: #009900;">&#40;</span>hero_y_axis_gpios<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                .<span style="color: #202020;">map</span> <span style="color: #339933;">=</span> hero_axis_map<span style="color: #339933;">,</span>
                .<span style="color: #202020;">gpio</span> <span style="color: #339933;">=</span> hero_y_axis_gpios<span style="color: #339933;">,</span>
                .<span style="color: #202020;">flags</span> <span style="color: #339933;">=</span> GPIOEAF_PRINT_UNKNOWN_DIRECTION <span style="color: #808080; font-style: italic;">/*| GPIOEAF_PRINT_RAW | GPIOEAF_PRINT_EVENT  */</span><span style="color: #339933;">,</span>
                .<span style="color: #202020;">enable_emc_protect_delay</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span> <span style="color: #339933;">*</span> NSEC_PER_MSEC<span style="color: #339933;">,</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Y轴上的info结构体的初始化</p>
<h1><span style="color: #000000;">6 备注</span></h1>
<p>在android的framework的代码中识别jogball设备是识别成鼠标的特性的，不仅有坐标还是由按键的，但是驱动中并没有axis中并没</p>
<p>有按键，所以在注册input设备的时候要加入按键的键值。如下代码：<br />
在drivers/input/misc/gpio_axis.c中的gpio_event_axis_func函数中</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">as<span style="color: #339933;">-&gt;</span>input_dev <span style="color: #339933;">=</span> input_dev<span style="color: #339933;">;</span>
as<span style="color: #339933;">-&gt;</span>info <span style="color: #339933;">=</span> ai<span style="color: #339933;">;</span>
&nbsp;
input_set_capability<span style="color: #009900;">&#40;</span>input_dev<span style="color: #339933;">,</span> ai<span style="color: #339933;">-&gt;</span>type<span style="color: #339933;">,</span> ai<span style="color: #339933;">-&gt;;</span>code<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ai<span style="color: #339933;">-&gt;</span>type <span style="color: #339933;">==</span> EV_ABS<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        input_set_abs_params<span style="color: #009900;">&#40;</span>input_dev<span style="color: #339933;">,</span> ai<span style="color: #339933;">-&gt;</span>code<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>
        ai<span style="color: #339933;">-&gt;</span>decoded_size <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>input_set_capability(input_dev, ai->type, BT_MOUSE);</p>
<p>本文源码是基于hero手机kernel代码<br />
kernel_hero/arch/arm/mach-msm/board-hero.c<br />
下载地址 <a href="http://developer.htc.com/">http://developer.htc.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://cyher.net/gnulinux/android/android-driver-jogball/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

