公司需要支持 ps/2 键盘, 但是 PXA310 上没有 ps/2 控制器。 硬件让研究一下 gpio 模拟的可能性。
仔细看了一下 ps/2 协议, 它主要是两根线, 一根 CLK, 一根 DATA. CLK 的频率大概是 10k – 30k . 对应一个 CLK 周期为 30us – 100us 。
当 ps/2 键盘 (或者鼠标)需要向主机发送信号时,它会先拉低时钟信号, 然后发出 1 个起始位, 8 个数据位, 1 个奇偶校验, 1 个停止位。如下图:
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"Century Gothic";
panose-1:2 11 5 2 2 2 2 2 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:647 0 0 0 159 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:42.55pt;
mso-footer-margin:49.6pt;
mso-paper-source:0;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
-->
这意味着如果我们使用 gpio 模拟 ps/2 接口, 那么在收到 CLK ( 由高到低 ) 的中断时,必须在 1 个时钟周期内去访问 DATA. 否则数据就会丢失。
这意味着我们的操作系统必须保证 30us-100us 的实时性! 目前我们的 Linux 为 2.6 标准内核, 不能满足这个要求!