所以,当你购买键盘的时候,绝对不要忽略“键位冲突”的问题,一定要把键盘装到电脑上,试一试自己常玩的游戏是否能够正常使用(只有实际试用才能试出键位 冲突问题,由于它与键位表相关,所以看外表是看不出来的)。同时,一些游戏高手朋友也不要白费心机去寻找什么“没有键位冲突的键盘”了,只要它依然是非编 码键盘,那么键位冲突就是不可避免的,只要它的键位冲突不对你所玩的游戏构成影响,这就足够了。
PS/2协议分析
The PS/2 mouse and keyboard implement a bidirectional synchronous serial protocol.
PS/2鼠标和键盘执行一个双向同步串行协议。
The bus is "idle" when both lines are high (open-collector).
总线空闲时,两条线都是高电平(集电极开路)。
This is the only state where the keyboard/mouse is allowed begin transmitting data.
在这种状态下,键盘/鼠标才允许开始传输数据。
The host has ultimate control over the bus and may inhibit communication at any time by pulling the Clock line low.
主机对总线有最高的控制权,在任何时候通过将时钟线拉低就可以禁止通信。
The device always generates the clock signal.
时钟信号总是由设备端生成的。
If the host wants to send data, it must first inhibit communication from the device by pulling Clock low.
如果主机想发送数据,它必须先将时钟拉低来禁止来自设备端的通信。
The host then pulls Data low and releases Clock.
然后主机再拉低数据线,释放时钟。 <-- CETagParser ~color=red~ --><-- /CETagParser -->注释:释放时钟,就是再恢复时钟为高<-- CETagParser ~/color~ --><-- /CETagParser -->
This is the "Request-to-Send" state and signals the device to start generating clock pulses.
这就是"请求发送(Request-to-Send)"状态,提示 设备端 开始生成时钟信号。
Summary: Bus States
Data = high, Clock = high: Idle state.
Data = high, Clock = low: Communication Inhibited.
Data = low, Clock = high: Host Request-to-Send
总结:总线状态
数据 0 1
0 ---------通信禁止-----------
时钟
1 主机要求发送 总线空闲
The clock and data pins are bidirectional, open-collector
signals that are pulled to 5 V by pullup resistors in the keyboard.
时钟和数据 引脚时 双向 集电极开路的信号,可以被键盘内部的上拉电阻 拉高到5V
Data sent from the device to the host is read on the falling edge of the clock signal; data sent from the host to the device is read on the rising edge.
从设备发送给主机的数据时在时钟信号的下降沿读取的;从主机发给设备的数据是在上升沿读取的。
The clock frequency must be in the range 10 - 16.7 kHz. This means clock must be high for 30 - 50 microseconds and low for 30 - 50 microseconds..
时钟频率必须在10-16.7KHz之间。这意味着时钟必须是 高电平持续30~50毫秒,低电平持续
30~50毫秒。
If you\'re designing a keyboard, mouse, or host emulator, you should modify/sample the Data line in the middle of each cell. I.e. 15 - 25 microseconds after the appropriate clock transition.
如果你设计一个键盘 鼠标 或者 主机模拟器,你必须 在每个单元的中间时刻 (也就是,在时钟跳变之后的15~25毫秒后) 修改/取样数据线.
Again, the keyboard/mouse always generates the clock signal, but the host always has ultimate control over communication.
重复一遍,键盘/鼠标 总是 生成时钟信号, 而 主机 控制着整个通信过程。
Timing is absolutely crucial. Every time quantity I give in this article must be followed exactly.
时序是非常重要的。在本文中给出的时间数必须严格遵循。
设备发送数据到主机
The Data and Clock lines are both open collector.
数据和时钟线都是集电极开路的。
A resistor is connected between each line and +5V, so the idle state of the bus is high.
在+5V 和每根线 之间连接着一个电阻,所以 总线的空闲状态 是 高电平。
When the keyboard or mouse wants to send information, it first checks the Clock line to make sure it\'s at a high logic level.
当键盘或者鼠标想发送数据时,它首先必须检查时钟线 ,确认它处于高电平。
If it\'s not, the host is inhibiting communication and the device must buffer any to-be-sent data until the host releases Clock.
如果不是,主机禁止通信,设备必须缓冲任何要发送的数据,直到主机释放时钟。
The Clock line must be continuously high for at least 50 microseconds before the device can begin to transmit its data.
在设备开始传输数据之前,时钟线 必须持续为 高电平的 时间 必须 至少50ms
The keyboard/mouse writes a bit on the Data line when Clock is high, and it is read by the host when Clock is low.
当时钟为高电平时,键盘/鼠标写一个bit到数据线上;当时钟为低电平时,主机从数据线上读取这个bit 。
The Data line changes state when Clock is high and that data is valid when Clock is low.
当时钟位高时,数据线 改变状态;
当时钟位低时,(数据线上的)数据是有效的。
The clock frequency is 10-16.7 kHz.
时钟频率是10-16.7KHz
The time from the rising edge of a clock pulse to a Data transition must be at least 5 microseconds.
从时钟脉冲的上升沿到数据跳变 的时间必须至少 5ms
The time from a data transition to the falling edge of a clock pulse must be at least 5 microseconds and no greater than 25 microseconds.
从数据跳变 到时钟脉冲的下降沿 必须 至少5ms,且不超过25ms
The host may inhibit communication at any time by pulling the Clock line low for at least 100 microseconds.
主机可在任何时间禁止通信,只需要将时钟线下拉位低电平超过100ms即可
If a transmission is inhibited before the 11th clock pulse, the device must abort the current transmission and prepare to retransmit the current "chunk" of data when host releases Clock.
如果在第11个脉冲时禁止传输,设备必须中止当前的传输,准备重新传输当前的数据"chunk(块)"当主机释放时钟时
A "chunk" of data could be a make code, break code, device ID, mouse movement packet, etc.
一个数据块可能时 通码,断码,设备ID,鼠标移动包 等等。
For example, if a keyboard is interrupted while sending the second byte of a two-byte break code, it will need to retransmit both bytes of that break code, not just the one that was interrupted.
举个例子,如果当发送 一个两字节断码的 第2个字节时,键盘被中断,它将需要重新发送
此断码的两个字节,而不仅仅时被中断掉的那个字节。
If the host pulls clock low before the first high-to-low clock transition, or after the falling edge of the last clock pulse, the keyboard/mouse does not need to retransmit any data.
如果在第一个 高->低 时钟跳变 时,(或者在 最后一个时钟脉冲的下降沿 之后)主机将时钟拉低,键盘/鼠标 不必重新传输任何数据。
However, if new data is created that needs to be transmitted, it will have to be buffered until the host releases Clock.
但是,如果新产生的数据需要传输,它必须将数据缓冲,知道主机释放时钟。
Keyboards have a 16-byte buffer for this purpose. If more than 16 bytes worth of keystrokes occur, further keystrokes will be ignored until there\'s room in the buffer.
键盘有一个16字节的缓冲区。如果有超过16个字节的击键存在,更多的击键将被忽略。直到
缓冲区有空地。
Mice only store the most current movement packet for transmission.
鼠标只能缓冲最近的一个要传输的(移动)数据包。
<-- CETagParser ~code~ -->
<-- /CETagParser -->时间参数 最大值/最小值 T1数据跳变到时钟的下降沿 5/25 us T2时钟的上升沿 到 数据跳变 5/T4 - 5 us T3时钟inactive 30-50 us T4时钟active 30-50 us T5 >0/50 us<-- CETagParser ~/code~ --> | |
<-- /CETagParser -->
Time to auxiliary device inhibit after clock 11 to ensure the auxiliary device does not start another transmission
The auxiliary device checks the \'clock\' line. If the line is inactive, output from the device is not allowed.
辅助设备(指 键盘) 检查 时钟线 ,如果时低电平,禁止发送数据
The auxiliary device checks the \'data\' line. If the line is inactive, the controller receives data from the system.
设备检查数据线,如果是 低电平,那么控制器从系统接收数据
The auxiliary device checks the \'clock\' line during the transmission at intervals not exceeding 100 microseconds. If the device finds the system holding the \'clock\' line inactive, the transmission is terminated. The system can terminate transmission anytime during the first 10 clock cycles.
设备在传输过程中 检查 时钟 线 间隔不超过100us。 如果设备发现 主机系统 将电平拉低,就终止传输。 在传输过程的前10个时钟周期的任何时候,主机系统可以中止传输。
A final check for terminated transmission is performed at least 5 microseconds after the 10th clock.
终止传输的最后一个检查 要持续至少5us
The system can hold the \'clock\' signal inactive to inhibit the next transmission.
系统拉低时钟线,将禁止下一次传输
The system can set the \'data\' line inactive if it has a byte to transmit to the device. The \'data\' line is set inactive when the start bit (always 0) is placed on the \'data\' line.
系统如果有一个字节要传输给设备,可以拉低数据线。当开始位(总是0)放置到数据线时,数据线被拉低。
The system raises the \'clock\' line to allow the next transmission.
系统拉高时钟将允许下一次传输
Host-to-Device主机到设备的通信
First of all, the PS/2 device always generates the clock signal.
首先,PS/2设备总是产生时钟信号
If the host wants to send data, it must first put the Clock and Data lines in a "Request-to-send" state as follows:
如果主机想发送数据,它必须先将时钟线和数据线设置成"Request-to-send"状态:
1) Inhibit communication by pulling Clock low for at least 100 microseconds.
拉低时钟线至少100us来禁止通信
2) Apply "Request-to-send" by pulling Data low, then release Clock.
拉低数据线,请求 "Request-to-send", 然后释放时钟 .
The device should check for this state at intervals not to exceed 10 milliseconds.
设备应该在不超过10ms(注意,是毫秒)的间隔内就要检查一次这个状态。
When the device detects this state, it will begin generating Clock signals and clock in eight data bits and one stop bit.
当设备检测到这个状态,它将开始产生时钟信号,
The host changes the Data line only when the Clock line is low, and data is read by the device when Clock is high.
只有当时钟线 为低的时候,主机才可以改变数据线(也就是将数据写入到数据线)。数据将在时钟为高电平的时候 被 设备读取。
After the stop bit is received, the device will acknowledge the received byte by bringing the Data line low and generating one last clock pulse.
在收到停止位之后,设备将通过拉低数据线,生成最后一个时钟脉冲 来 应答收到的字节
If the host does not release the Data line after the 11th clock pulse, the device will continue to generate clock pulses until the the Data line is released (the device will then generate an error.)
在第11个时钟脉冲之后,如果主机并没有释放数据线,设备将继续产生时钟脉冲,直到数据线被释放(然后 设备将产生一个错误)
The host may abort transmission at time before the 11th clock pulse (acknowledge bit) by holding Clock low for at least 100 microseconds.
在第11个脉冲之前(回应位),主机可以随时中止传输,只要拉低时钟持续100us即可
<-- CETagParser ~code~ -->
<-- /CETagParser -->时间参数 最大值/最小值 T7 时钟低电平 30-50 us T8 时钟高电平 30-50 us T9 30-50 us<-- CETagParser ~/code~ --> | |
<-- /CETagParser -->
T9 == Time from inactive to active CLK transition, used to time when the auxiliary device samples DATA
FreeScale(Moto)提供的时序图
主机到键盘的数据传输
1.主机 通过拉低 时钟线 来 启动一个主机到键盘的数据传输。大约35us后,主机拉低数据线
。这个事件序列 就是 通知 键盘,主机要传输一个命令了。在数据信号的下降沿大约 125us 后 时钟信号释放,就被键盘内部的上拉电阻拉为高电平 。
2. 在时钟信号的上升沿 约 1ms ,数据传输开始。这个期间,数据线保持低电平。键盘拉低时钟线,clocking in the low data line. 这个就做传输的起始位。
3. 键盘用时钟驱动 8个数据位从主机传输到自己这边。 这个时钟有50%的占空比(duty cycle).高电平和低电平的时间都在30~50us之间。主机在每个周期的低电平的时候改变数据线上的数据。在每个时钟的上升沿5~25us之后键盘 开始从数据线上取样,取出主机发来的数据。
4.数据位之后是一个奇偶校验位(采用奇校验)
5.最后是停止位
6.如果键盘读到一个高电平的停止位,键盘就在 取样停止位的那个时钟的下降沿 之后的低电平期间 拉低数据线。这个行为叫做 键盘给主机的应答信号。
键盘拉高时钟之后,也拉高数据线。
7.在收到一个字节后,键盘对接收的数据执行一个奇偶校验。如果奇偶校验错误,或者接收的数据无法识别为有效的命令,那么键盘请求重新发送(发送0xFE给主机)
1. 键盘发送数据前,首先必须让时钟 和数据线都在键盘内部的上拉电阻作用下 拉成高电平。然后键盘拉低数据线,5-25us之后,键盘拉低时钟线。在时钟的下降沿,开始传输起始位The falling edge of the clock line clocks in the transfer’s start
bit.
2. 键盘用时钟驱动 8个数据位到主机。 这个时钟有50%的占空比(duty cycle).高电平和低电平的时间都在30~50us之间。键盘在每个周期的高电平的时候改变数据线上的数据。这个改变出现在时钟的上升沿的5us后 和 下降沿的5us前。键盘的数据在时钟的下降沿被锁存进主机。
3.数据位之后是一个奇校验位
4.最后是停止位。在时钟的下降沿 0~50us之间 主机拉低时钟 来锁存停止位。这就告诉键盘主机现在忙,不能在接收 其他的键盘传输数据。在处理完接收的数据,准备好接收下一个数据之前,主机释放时钟。
6.在键盘传输数据到主机的过程中,主机任何时候都可以中断这个传输,发送一个命令到键盘。主机拉低时钟和数据线 即可中止传输。所以,键盘在时钟为 低电平的时候必须取样数据线。(无论什么时候输出高数据位的时候)。在产生时钟的上升沿时,必须读取时钟。
在任何时候发现这两个条件不满足,就拉高时钟和数据线,放弃这次传输,并准备从 主机接收命令。
Moto 香港公司的 Derek Lau
当时钟 高电平是,发送给主机的数据被主机读取。在空闲状态,时钟和数据线都被拉为高电平。主机 拉低 时钟最少100ms(?还是us)开始发送数据给键盘:
1.主机等待,直到没有外部设备传输被处理
2.主机 拉低时钟
3.主机拉低数据作为开始位
4 .主机释放时钟
5.设备拉低时钟
6.主机发送数据
7.设备释放时钟,读取数据
8.设备检查时钟线,如果时钟为低,中止传输
9.重复 5-7步,发送 数据1-到数据0,以及 奇校验位
10. 设备拉低时钟
11. 主机释放数据
12.设备时钟时钟
13.设备读取数据线,想得到停止位,如果数据线为低(不是停止位),产生错误
14.设备拉低 时钟和数据线
15.设备释放 时钟和数据线
从设备发送到主机的数据,在时钟的下降沿被读取。在发送数据前,设备检查通过检测时钟信号为高来得知 主机是否贮备好:
1.键盘(设备)等待时钟为高(约50ms?us)
2.如果数据为 低,终止
3.键盘 发送数据
4.键盘拉低时钟为低
5.键盘释放时钟为高
6.键盘 读取时钟线,如果时钟为低,中止传输
7.重复 4-6步,传输数据0-数据7,奇校验位和停止位
8.键盘释放时钟为高