The PS2 Mouse Interface.docx
《The PS2 Mouse Interface.docx》由会员分享,可在线阅读,更多相关《The PS2 Mouse Interface.docx(16页珍藏版)》请在冰点文库上搜索。
ThePS2MouseInterface
ThePS/2MouseInterface
Source:
http:
//www.Computer-Engineering.org
Author:
AdamChapweske
LastUpdated:
04/01/03
LegalInformation:
Allinformationwithinthisarticleisprovided"asis"andwithoutanyexpressorimpliedwarranties,including,withoutlimitation,theimpliedwarrantiesofmerchantibilityandfitnessforaparticularpurpose.
Thisarticleisprotectedundercopyrightlaw. Thisdocumentmaybecopiedonlyifthesource,author,date,andlegalinformationisincluded.
Abstract:
ThisarticleattemptstoexplaineveryaspectofthePS/2mouseinterfaceincludingthephysicalandelectricalinterface,low-levelprotocol,modesofoperation,commands,andextensions. AllcodesamplesinvolvingthemouseencoderarewritteninassemblyforMicrochip'sPICmicrocontrollers. Allcodesamplesrelatedtotheauxiliarydevicecontroller(keyboardcontroller)arewritteninx86assembly
GeneralDescription:
TherearemanytypesofpointingdevicesavailableformodernPCs,includingmice,trackballs,touchpads,electronicwhiteboards,etc. Virtuallyallofthesepointingdevicescommunicatewithacomputerusingoneoftwointerfaces:
UniversalSerialBus(USB)orthePS/2MouseInterface. Seethefollowingtableforacomparison:
USB(v1.1)
PS/2MouseInterface
NumberofDevicesSupported
Upto127
One
MaximumDataRate
12Mbps
40kbps
Power(max)
5V@500mA
5V@100mA
Hot-Pluggable?
Yes
No
Documentation
Well-documented:
http:
//www.usb.org
Out-of-print
(IBMTechReference)
OlderpointingdeviceinterfacesincludetheAppleDesktopBus(ADB),RS-232serialport,andthebusmouseinterface. Theseareobsoleteandarenotcoveredinthisarticle.
ThePS/2mouseinterfaceoriginallyappearedinIBM's"PersonalSystem/2"computersinthelate80's. Itstillremainsawidely-supportedinterfaceforthesakeofconstantlymaintainingbackwardcompatibility. However,USBhasquicklycaughtontheselastfewyearsandwilleventuallyreplacethePS/2mouseinterfaceentirely.
ThePS/2mouseinterfaceusesabidirectionalserialprotocoltotransmitmovementandbutton-positiondatatothecomputer'sauxiliarydevicecontroller(keyboardcontroller). Thecomputer,inturn,maysendanumberofcommandstothemousetosetthereportrate,resolution,resetthemouse,disablethemouse,etc. Thecomputeralsoprovidesthemousewithanoverload-protected5Vpowersupply.
ElectricalInterface/Protocol:
ThePS/2mouseusesthesameprotocolasthePS/2keyboard(akaATkeyboard). Clickherefordetailedinformationonthisprotocol.
Inputs,Resolution,andScaling:
ThestandardPS/2mouseinterfacesupportsthefollowinginputs:
X(right/left)movement,Y(up/down)movement,leftbutton,middlebutton,andrightbutton.Themousereadstheseinputsataregularfreqencyandupdatesvariouscountersandflagstoreflectmovementandbuttonstates. TherearemanyPS/2pointingdevicesthathaveadditionalinputsandmayreportdatadifferentlythandescribedinthisdocument. OnepopularextensionIcoverlaterinthisdocumentistheMicrosoftIntellimouse,whichincludessupportforthestandardinputsaswellasascrollingwheelandtwoadditionalbuttons.
Thestandardmousehastwocountersthatkeeptrackofmovement:
theX-movementcounterandtheY-movementcounter. These are9-bit2'scomplementvaluesandeachhasanassociatedoverflowflag. Theircontents,alongwiththestateofthethreemousebuttons,aresenttothehostintheformofa3-bytemovementdatapacket(asdescribedinthenextsection.) Themovementcountersrepresenttheamountofmovementthathasoccurredsincethelastmovmentdatapacketwassenttothehost(ie,theydonotrepresentabsolutepositions.)
Whenthemousereadsitsinputs,itrecordsthecurrentstateofitsbuttonsandchecksformovement.Ifmovementhasoccurreditincrements(for+Xor+Ymovement)ordecrements(for-Xor-Ymovement)itsXand/orYmovementcounters.Ifeitherofthecountershasoverflowed,itsetstheappropriateoverflowflag.
Theparameterthatdeterminestheamountbywhichthemovementcountersareincremented/decrementedistheresolution.Thedefaultresolutionis4counts/mmandthehostmaychangethatvalueusingthe"SetResolution"(0xE8)command.
Thereisaparameterthatdoesnoteffectthemovementcounters,butdoeseffectthereported
(1)valueofthesecounters. Thisparameterisscaling. Bydefault,themouseuses1:
1scaling,whichhasnoeffectonthereportedmousemovement. However,thehostmayselect2:
1scalingbysendingthe"SetScaling2:
1"(0xE7)command. If2:
1scalingisenabled,themousewillapplythefollowingalgorithmtothecountersbeforesendingtheircontentstothehost:
MovementCounter
ReportedMovement
0
0
1
1
2
1
3
3
4
6
5
9
N>5
2*N
MovementDataPacket:
ThestandardPS/2mousesendsmovement/buttoninformationtothehostusingthefollowing3-bytepacket(4):
Byte1
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Yoverflow
Xoverflow
Ysignbit
Xsignbit
Always1
MiddleBtn
RightBtn
LeftBtn
Byte2
XMovement
Byte3
YMovement
Themovementcountersare9-bit2'scomplementintegers,wherethemostsignificantbitappearsasasignbitinByte1ofthemovementdatapacket.Thesecountersareupdatedwhenthemousereadsitsinputandfindsmovementhasoccurred.Theirvalueistheamountofmovementthathasoccurredsincethelastmovementdatapacketwassenttothehost(ie,afterapacketissenttothehost,themovementcountersarereset.)Therangeofvaluesthatcanbeexpressedbythemovementcountersis-255to+255.Ifthisrangeisexceeded,theappropriateoverflowbitisset.
AsImentionedearlier,themovementcountersareresetwheneveramovementdatapacketissuccessfullysenttothehost.Theyarealsoresetafterthemousereceivesanycommandfromthehostotherthanthe"Resend"(0xFE)command.
ModesofOperation:
Datareportingishandledaccordingtothemodeinwhichthemouseisoperating. Therearefourstandardmodesofoperation:
∙Reset-ThemouseentersResetmodeatpower-uporafterreceivingthe"Reset"(0xFF)command.
∙Stream-Thisisthedefaultmode(afterResetfinishesexecuting)andisthemodeinwhichmostsoftwareusesthemouse. IfthehosthaspreviouslysetthemousetoRemotemode,itmayre-enterStreammodebysendingthe"SetStreamMode"(0xEA)commandtothemouse.
∙Remote-Remotemodeisusefulinsomesituationsandmaybeenteredbysendingthe"SetRemoteMode"(0xF0)commandtothemouse.
∙Wrap-Thismodeisn'tparticularlyusefulexceptfortestingtheconnectionbetweenthemouseanditshost. Wrapmodemaybeenteredbysendingthe"SetWrapMode"(0xEE)commandtothemouse. ToexitWrapmode,thehostmustissuethe"Reset"(0xFF)commandor"ResetWrapMode"(0xEC)command. Ifthe"Reset"(0xFF)commandisrecieved,themousewillenterResetmode. Ifthe"ResetWrapMode"(0xEC)commandisreceived,themousewillenterthemodeitwasinpriortoWrapMode.
(Note:
Themousemayalsoenter"extended"modesofoperation,asdescribedlaterinthisdocument. However,thisisnotafeatureofthestandardPS/2mouse.)
ResetMode:
Themouseentersresetmodeatpower-onorinresponsetothe"Reset"(0xFF)command.Afterentringthismode,themouseperformsadiagnosticself-testreferredtoasBAT(BasicAssuranceTest)andsetsthefollowingdefaultvalues:
∙SampleRate=100samples/sec
∙Resolution=4counts/mm
∙Scaling=1:
1
∙DataReportingDisabled
ItthensendsaBATcompletioncodeofeitherAAh(BATsuccessful)orFCh(Error).Thehost'sresponsetoacompletioncodeotherthanAAhisundefined.
FollowingtheBATcompletioncode(AAhorFCh),themousesendsitsdeviceIDof00h.Thisdistinguishesitfromakeyboard,oramouseinanextendedmode.IhavereaddocumentssaythingthehostisnotsupposedtotransmitanydatauntilitreceivesadeviceID. HoweverI'vefoundthatsomeBIOS'swillsendthe"Reset"commandimmediatelyfollowingthe0xAAreceivedafterapower-onreset.
AfterthemousehassentitsdeviceIDtothehost,itwillenterStreamMode. Notethatoneofthedefaultvaluessetbythemouseis"DataReportingDisabled". Thismeansthemousewillnotissueanymovementdatapacketsuntilitreceivesthe"EnableDataReporting"command.
StreamMode:
Instreammode,themousesendsmovementdatawhenitdetectsmovementorachangeinstateofoneormoremousebuttons.Themaximumrateatwhichthisdatareportingmayoccurisknownasthesamplerate. Thisparameterrangesfrom10samples/secto200samples/sec.Itsdefaultvalueis100samples/secandthehostmaychangethatvaluebyusingthe"SetSampleRate"command. Streammodeisthedefaultmodeofoperationfollowingreset.
RemoteMode:
Inthismodethemousereadsitsinputsandupdatesitscounters/flagsatthecurrentsamplerate,butitdoesnotautomaticallyissuedatapacketswhenmovementhasoccured. Instead,thehostmustpollthemouseusingthe"ReadData"command. Uponreceivingthiscommandthemousewillsendasinglemovementdatapacketandresetitsmovementcounters.
WrapMode:
Thisisan"echoing"modeinwhicheverybytereceivedbythemouseissentbacktothehost.Evenifthebyterepresentsavalidcommand,themousewillnotrespondtothatcommand--itwillonlyechothatbytebacktothehost.Therearetwoexceptionstothis:
the"Reset"commandand"ResetWrapMode"command.Themousetreatstheseasvalidcommandsanddoesnotechothembacktothehost.
IntellimouseExtensions:
Apopularextensiontot