digilentinc官网上PS2鼠标程序说明文档MouseRefComp.pdf的理解

本地地址:E:/FPGA/myown/basysmouse/pdf/MouseRefComp.pdf

注:绿色的为我自己做的标注,紫色的为不明白、不清楚的地方,红色的是重要的地方。图和表参加原文档。
文档下载地址:http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,398,829&Prod=BASYS
 
Page 1:
鼠标参考组件
概述

 
鼠标参考组件式一个基于PS/2接口协议的鼠标控制器。对于这个组件有很多用途,并且最常用的是在VGA屏幕上作为一个鼠标。这里描述的大部分初始值和方法都包括这个通用用途。

 
这个鼠标参考组件与PS/2接口通信并且在上电和复位时进行初始化。一旦滚动模式被允许(如果鼠标有一个滚轮),这个分辨率和简单速度(??)被设定,数据报告就能被使能(等待从鼠标那接受数据包)。之后数据移动包被封装来产生关于展示X和Y数据、按键状态和鼠标滚轮路径(Z,如果允许 ,即有滚轮)。

 
功能性描述

 
如表格2所示,鼠标参考组件包括3个主要的模块:PS/2接口模块,它主要负责鼠标与控制器之间的通信;鼠标控制器,它主要接受从鼠标来的数据包,和鼠标的位置输出和按键状态;分辨率鼠标通知者(??),它来提供在X和Y轴有效屏幕边界。第三个组件( 即模块)接受分辨率信息并计算出在X轴和Y轴的最大值并设置鼠标的初始位置。( 注:要了解PS2协议,只做之一部分,第三个模块便不需要涉及

 
接口定义

PS/2_clk input, clock line of the PS/2 interface
PS/2_data input, clock line of the PS/2 interface
clk input, system clock signal
rst input, system reset signal
resolution input, sets one of two resolution options: 0 for 640x480 or 1 for 800x600
分辨率 输入,设置两种分辨率选项中的一个:0表示640x480,1表示800x600
switch input, active for one clk period when resolution changes.
left output, state of the left mouse button (‘1’ if pressed, or ‘0’)
middle output, state of the middle mouse button (‘1’ if pressed, or ‘0’)
right output, state of the right mouse button (‘1’ if pressed, or ‘0’)
xpos output, nine bits, the current horizontal position of the mouse(主要用于VGA显示
ypos output, nine bits, the current vertical position of the mouse
zpos output, four bits, the last Z delta movement received
new_event output, high for one clk period after a data packet is received and processed
新事件 输出,当在一个数据包被接受和处理之后的一个时钟周期后显示高电平

Page 2:

The PS/2 Interface

The PS/2 interface module implements a generic bi-directional PS/2 interface. It can be used with any  PS/2 compatible(兼容的) device and it offers its clients a convenient way to exchange data. The interface  transparently wraps the byte to be sent into a PS/2 frame, generates the parity bit, and sends the  frame one bit at a time to the device. (这个接口程序明显地数据包起来放入一个PS/2帧中,产生一个奇偶校验位,给器件时向帧中逐次放入一位 (??) 。)Similarly, when receiving data from the PS2 device, the interface  receives the frame, checks for parity, extracts(取出) the useful data, and forwards(发送) it to the client. If an error  occurs when sending or receiving a byte, the client is informed by setting the err output line high. This  way the client can resend the data or issue a resend command to the device.( client指的是什么?? 这个client是发送者,因为PS2_data是双向的,所以这个client不能确定是哪一个器件。

The physical PS/2 interface uses four lines. The PS/2 6-pin connector pins are assigned as follows :
1 Data
2 Not Implemented
3 Ground
4 VCC (+5V)
5 Clock
6 Not Implemented

The clock line carries the device clock with the frequency range 10 to 16.7KHz (30 to 50μs). When the  line is idle it is placed in high impedance(高阻态). The clock is only generated when the device is sending orreceiving data. Data and clock lines are both open-collectors(集电极开路??) with pull-up resistors to VCC. An opencollector interface has two possible states: low ('0') or high ('Z') impedance.

When a device wants to send a byte, it pulls the clock line low and the host (i.e., the PS/2 interface)recognizes that the device is sending data. When the host wants to send data, it makes a send request. This is done by holding the clock line low for at least 100μs, then the data line is brought low.Next, the clock line is released (placed in high impedance). The device begins generating clock pulses. When receiving data, bits are read from the data line (PS/2_data) on the falling edge of the clock (PS/2_clk). When sending data, the device reads the bits from the data line on the rising edge of the clock. A frame for sending a byte is comprised of an 11-bit value as shown in Figure 3. The frame is sent one bit at a time from the least significant bit, or starting bit, and is received the same way.
当一个器件想发送一位数据时,它会把时钟线拉低,并且主机(如:PS2接口程序)来识别那个设备发送数据。当主机向发送数据时,它会产生一个发送请求。 这是通过保持时钟线为低至少100us的时间来实现的,之后数据线被拉低。 之后,时钟线被释放(处于高阻态)。 器件开始产生时钟脉冲 。当收到数据,字节在时钟的下降沿从数据线上被读取(PS/2_data)。当发送数据时,器件在时钟的上升沿读取数据线上的数据。(这些都是主机进行发送,器件进行接收)一个发送帧包含如表格3所示的11位数据。这个帧一次发送一个字节从最低位开始,或者说是起始位(起始位是bit0,即最低位),并且接受也是相同的方式。
(网络资料: 这不叫“最不重要”... the least significant bit 这叫最低位 ...the most significant bit这叫最高位
Page3:

10 9 8 7 6 5 4 3 2 1 0
STOP PAR D7 D6 D5 D4 D3 D2 D1 D0 START
Figure 3 PS/2 Frame for Sending a Byte
STOP stop bit, always '1'
PAR parity bit, odd(奇) parity; the number of bits of '1' in the data bits together with parity bit is  odd
D0-7 data bits
START start bit, always '0'

When receiving, the frame register is shifted to the right, placing the first bit on the data line at the most significant position. This way the first bit sent will reach the least significant bit of the frame once all the bits have been received.
当接收时,帧寄存器被转换到右侧(??),把数据线上的第一个字节放在最高位。在这种方式下,当所有的字节被接受到时,第一个发送的字节将要到帧上的最低位。

When sending data, the least significant bit of the frame is placed on the data line and the frame is  shifted to the right. When releasing the clock line during the send request, the device reads the data  line and interprets the data as the first bit of the frame. As a result, when sending, only ten shifts of the  frame will be made. For the parity bit, a look-up table is defined in a 256x1 ROM.
当发送数据时,帧上的最低位被放在数据线上,并且帧被转换到右侧。当在发送请求时释放时钟线,器件读取数据线并解释为帧上的第一个字节。因此,当发送时,只产生帧上的十次转换。对于校验位,一个查找表被定义为256x1的ROM。 ??

While the interface is sending or receiving data, the busy output signal goes high. When the interface  is idle, the output signal is low. After sending all the bits in the frame, the device must acknowledge ( 告知已收到(某物)   the sent data.( 此处主机发送数据给器件 ) The host releases the data line (the clock line is already released) after the last bit is  sent. The device brings the data line and the clock line low, in that order, to acknowledge the data. If  the device does not acknowledge the data, err output is set.

To generate the necessary delay, counters are used. For example, to generate the 100μs delay, a 14- bit counter that counts to 10,000 is used. Because the interface is designed to run at 100MHz, therefore 10,000x10ns = 100μs.

Port Definitions for the PS/2 Interface Module

PS/2_clk in/out pin, clock line of the PS/2 interface
PS/2_data in/out pin, clock line of the PS/2 interface
clk input pin, system clock signal
rst input pin, system reset signal
tx_data input pin, eight bits, from client data to be sent to the device
tx_data 输入引脚,八位,把客户端的数据发送到器件上。
write input pin, from client, should be active for one clock period when then client wants to  send data to the device and data to be sent is valid on tx_data
rx_data output pin, eight bits, to client data received from device
read output pin, to client for one clock period when new data is available from device
busy output pin, to client active while sending or receiving data
err output pin, to client active for one clock period when an error occurred during sending

Page 4

The PS/2 interface receives bytes from the PS/2 device (mouse or keyboard) and sends them further to the mouse or keyboard controller. Data is sent on the rx_data output port. The read signal is active for one clock period when a new byte is available on rx_data.(当一个新位在rx_data上可获得时,read信号表现为在一个时钟周期内是高电平) When the err input goes high for one clock (indicating an error while the PS/2 interface received a byte), the controller enters the reset state.

The PS/2 interface also gets bytes from the mouse or keyboard controller and sends them further to  the device. Data is received on the tx_data output port. The write output signal should be active for  one clock period when tx_data contains the command or data to be sent to the mouse or keyboard.
数据及控制指令是在Mouse controller和鼠标之间进行传输,mouse interface只是进行匹配时序。作为中间的一部分。

The Mouse Controller

When in reset state, the controller resets the mouse and begins an initialization procedure. It performs  the BAT (Basic Assurance(确信,保证) Test) and sends the result of the test to the host, followed by the ID of the  mouse, 00h. Next it enters stream mode, but with data reporting disabled. This means it will not send  data movement packets when the mouse is moved or the state of the button changes. Also, it doesn’t  have the scrolling mode enabled.

The controller first resets the mouse, waits for the BAT result and the mouse ID, and then starts the  enable scrolling mode procedure. The procedure consists of successively( 接连着,继续地) setting the sample rate to 200, then 100, and finally 80. After this is done, the controller requests the mouse ID by sending the F2h byte to the mouse (request ID command). If the received ID is 00h then the mouse does not have a wheel, or if the ID is 03h, then the mouse has entered scrolling mode and will include Z movement information in its data movement packets. Note that data reporting is still disabled at this point.

Next, the resolution is set to eight counts/mm(??) and the sample rate is set to 40 samples采样,取样,抽样)per second.The last command sent to the mouse is the enable reporting command (F4h). After this, the mouse sends data movement packets every time the mouse is moved, its button states change, or the mouse wheel is moved (when available). The controller now enters another state, waiting for bytes from the mouse. The mouse sends the acknowledge byte (FAh) after each byte it receives from the host.

When the mouse wheel is disabled, or the mouse does not have a wheel, data movement packets  consist of three consecutively sent bytes. When the scrolling mode is enabled, it sends four bytes.

Page 5:

The first received byte contains button states on the least significant three bits. If one of these bits is high, then the corresponding mouse button is pressed. The X and Y sign(正负号) bit is the most significant bit of the X and Y movement value. The X and Y movements are represented using nine-bit two’s complement(补码) encoding. Thus, the range of movement is -256 to 255. The delta(希腊字母表中第四个字母) movement from the mouse’s last position is sent for either axis. The mouse does not keep track of(与…保持联系) the absolute position of the mouse. The controller uses the delta movements received to keep track of the absolute position.(the delta movements是什么)
(网络资料two 's   complement是补码的意思。one 's   complement是反码。)

The mouse uses the lower-left corner for axes origin, meaning the mouse reports a positive displacement on X when moved to the right and negative (X sign bit is ‘1’) when moved to the left.(鼠标使用一个下边-左边角作为轴的起始,意味着鼠标报告一个正当鼠标在X轴上在向右移动,并显示负(X正负位为1时)当鼠标向左移动时。) When the mouse is moved upward, the Y displacement is positive, and when moved downward it is negative. The monitor uses the upper-left corner for the axes origin. The controller negates the Y displacement before adding it to the previous Y position to report the position relative to the monitor axes origin.(控制器在添加它到先前Y位置之前,否定(即显示负)Y显示,来报告正相对于监视器的初始
什么是监视器??

The current position of the mouse can be set at any time by placing the desired horizontal or vertical position (relative to the monitor’s axes origin) on the value input. Then set the set-x input signal (set-y
for the vertical position) high for one clock period.

Similarly, the upper bounds(边界) of the mouse can be set by placing the value of those bounds on the  value input and placing setmax_x or setmax_y high for one clock period. This is done when the  resolution changes to place the mouse cursor (its hot spot(点)) in the middle of the screen and also  prevents the cursor from leaving the visible area.

Controller Outputs

left state of the left mouse button (‘1’ if pressed, or ‘0’)
middle state of the middle mouse button (‘1’ if pressed, or ‘0’)
right state of the right mouse button (‘1’ if pressed, or ‘0’)
xpos nine bits, the current horizontal position of the mouse
ypos nine bits, the current vertical position of the mouse
zpos four bits, the last Z delta movement received
new_event high for a clock period after a new data movement packet is received and processed

The Resolution Mouse Informer

The resolution_mouse_informer implements the logic that sets the position of the mouse when the  FPGA is powered-up or when the resolution changes. It also sets the bounds of the mouse according
to the present resolution.

The mouse is centered for the currently-selected resolution and the bounds are set accordingly. This  way, the mouse cursor will appear in the center of the screen at start-up, and when the resolution is
changed it will not leave the screen. The position, and the bounds, are set by placing the coordinate of  the center point on the output value and activating the corresponding set signal (set-x for horizontal
position, set-y for vertical position, setmax_x for horizontal maximum value, and setmax_y for the  vertical maximum value).

Port Definitions for the Resolution_mouse_informer

clk global clock signal
rst reset signal
resolution input pin, from resolution_switcher
          0 for 640x480 selected resolution
          1 for 800x600 selected resolution
switch input pin, from resolution_switcher, active for one clock period when resolution  changes
value output pin, 10 bits, to mouse_controller, position on X or Y, max value for X or Y that is  sent to the mouse_controller
setx output pin, to mouse_controller, active for one clock period when the value output  contains the horizontal position of the mouse cursor
sety output pin, to mouse_controller, active for one clock period when the value output  contains the vertical position of the mouse cursor
setmax_x output pin, to mouse_controller, active for one clock period when the value output  contains the horizontal maximum position of the mouse cursor
setmax_y output pin, to mouse_controller, active for one clock period when the value output  contains the vertical maximum position of the mouse cursor
如何来通过setx、sety、setmax_x、setmax_y来进行相应的设置??













  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值