现在的位置: 首页 > 综合 > 正文

summaries of keyboard

2013年05月11日 ⁄ 综合 ⁄ 共 5704字 ⁄ 字号 评论关闭

i8048

Although most set two make codes are only one-byte wide, there are a handfull of "extended keys" whose make codes are two or four bytes wide.  These make codes can be identified by the fact that their first byte is E0h

you won't always have to use lookup tables to figure out a key's break code--certain relationships do exist between make codes and break codes.  Most set two break codes are two bytes long where the first byte is F0h and the second byte is the make code for that key.  Break codes for extended keys are usually three bytes long where the first two bytes are E0h, F0h, and the last byte is the last byte of that key's make code.

Key
(Set 2)
Make Code
(Set 2)
Break Code
"A"
1C
F0,1C
"5"
2E
F0,2E
"F10"
09
F0,09
Right Arrow
E0, 74
E0, F0, 74
Right "Ctrl"
E0, 14
E0, F0, 14

There are two important parameters here:  the typematic delay, which is the short delay between the first and second "a", and the typematic rate, which is how many characters per second will appear on your screen after the typematic delay.  The typematic delay can range from 0.25 seconds to 1.00 second and the typematic rate can range from 2.0 cps (characters per second) to 30.0 cps.  You may change the typematic rate and delay using the "Set Typematic Rate/Delay" (0xF3) command.

At power-on or software reset (see the "Reset" command) the keyboard performs a diagnostic self-test referred to as BAT (Basic Assurance Test) and loads the following default values: 

  • Typematic delay 500 ms.
  • Typematic rate 10.9 cps.
  • Scan code set 2.
  • Set all keys typematic/make/break.

When entering BAT, the keyboard enables its three LED indicators, and turns them off when BAT has completed.  At this time, a BAT completion code of either 0xAA (BAT successful) or 0xFC (Error) is sent to the host.   This BAT completion code must be sent 500~750 milliseconds after power-on.

Command Set:

A few notes regarding commands the host can issue to the keyboard:

  • The keyboard clears its output buffer when it recieves any command.
  • If the keyboard receives an invalid command or argument, it must respond with "resend" (0xFE).
  • The keyboard must not send any scancodes while processing a command.
  • If the keyboard is waiting for an argument byte and it instead receives a command, it should discard the previous command and process this new one.

Below are all the commands the host may send to the keyboard:

  • 0xFF (Reset) - Keyboard responds with "ack" (0xFA), then enters "Reset" mode.  (See "Reset" section.)
  • 0xFE (Resend) - Keyboard responds by resending the last-sent byte.  The exception to this is if the last-sent byte was "resend" (0xFE).  If this is the case, the keyboard resends the last non-0xFE byte.  This command is used by the host to indicate an error in reception.

The next six commands can be issued when the keyboard is in any mode, but it only effects the behavior of the keyboard when in "mode 3" (ie, set to scan code set 3.)

  • *0xFD (Set Key Type Make) - Disable break codes and typematic repeat for specified keys.  Keyboard responds with "ack" (0xFA), then disables scanning (if enabled) and reads a list of keys from the host.  These keys are specified by their set 3 make codes.  Keyboard responds to each make code with "ack".  Host terminates this list by sending an invalid set 3 make code (eg, a valid command.)  The keyboard then re-enables scanning (if previously disabled).
  • *0xFC (Set Key Type Make/Break) - Similar to previous command, except this one only disables typematic repeat.
  • *0xFB (Set Key Type Typematic) - Similar to previous two, except this one only disables break codes.
  • *0xFA (Set All Keys Typematic/Make/Break) - Keyboard responds with "ack" (0xFA).  Sets all keys to their normal setting (generate scan codes on make, break, and typematic repeat)
  • *0xF9 (Set All Keys Make) - Keyboard responds with "ack" (0xFA).  Similar to 0xFD, except applies to all keys.
  • *0xF8 (Set All Keys Make/Break) - Keyboard responds with "ack" (0xFA).  Similar to 0xFC, except applies to all keys.
  • *0xF7 (Set All Keys Typematic) - Keyboard responds with "ack" (0xFA).  Similar to 0xFB, except applies to all keys.
  • 0xF6 (Set Default) - Load default typematic rate/delay (10.9cps / 500ms), key types (all keys typematic/make/break), and scan code set (2).
  • 0xF5 (Disable) - Keyboard stops scanning, loads default values (see "Set Default" command), and waits further instructions.
  • 0xF4 (Enable) - Re-enables keyboard after disabled using previous command.
  • 0xF3 (Set Typematic Rate/Delay) - Host follows this command with one argument byte that defines the typematic rate and delay as follows:
    .
    Repeat Rate

    Bits 0-4
    Rate(cps)
     
    Bits 0-4
    Rate(cps)
     
    Bits 0-4
    Rate(cps)
     
    Bits 0-4
    Rate(cps)
    00h
    30.0
     
    08h
    15.0
     
    10h
    7.5
     
    18h
    3.7
    01h
    26.7
     
    09h
    13.3
     
    11h
    6.7
     
    19h
    3.3
    02h
    24.0
     
    0Ah
    12.0
     
    12h
    6.0
     
    1Ah
    3.0
    03h
    21.8
     
    0Bh
    10.9
     
    13h
    5.5
     
    1Bh
    2.7
    04h
    20.7
     
    0Ch
    10.0
     
    14h
    5.0
     
    1Ch
    2.5
    05h
    18.5
     
    0Dh
    9.2
     
    15h
    4.6
     
    1Dh
    2.3
    06h
    17.1
     
    0Eh
    8.6
     
    16h
    4.3
     
    1Eh
    2.1
    07h
    16.0
     
    0Fh
    8.0
     
    17h
    4.0
     
    1Fh
    2.0

    Delay

    Bits 5-6
    Delay (seconds)
    00b
    0.25
    01b
    0.50
    10b
    0.75
    11b
    1.00


     
  • *0xF2 (Read ID) - The keyboard responds by sending a two-byte device ID of 0xAB, 0x83. (0xAB is sent first, followed by 0x83.)
  • *0xF0 (Set Scan Code Set) -  Keyboard responds with "ack", then reads argument byte from the host.  This argument byte may be 0x01, 0x02, or 0x03 to select scan code set 1, 2, or 3, respectively.  The keyboard responds to this argument byte with "ack".  If the argument byte is 0x00, the keyboard responds with "ack" followed by the current scan code set.
  • 0xEE (Echo) - The keyboard responds with "Echo" (0xEE).
  • 0xED (Set/Reset LEDs) - The host follows this command with one argument byte, that specifies the state of the keyboard's Num Lock, Caps Lock, and Scroll Lock LEDs.  This argument byte is defined as follows:

MSb LSb

Always 0 Always 0 Always 0 Always 0 Always 0 Caps Lock Num Lock Scroll Lock


    • "Scroll Lock" - Scroll Lock LED off(0)/on(1)
    • "Num Lock" - Num Lock LED off(0)/on(1)
    • "Caps Lock" - Caps Lock LED off(0)/on(1)

*Originally available in PS/2 keyboards only.

i8042

The 8042 contains the following registers:

  • A one-byte input buffer - contains byte read from keyboard; read-only
  • A one-byte output buffer - contains byte to-be-written to keyboard; write-only
  • A one-byte status register - 8 status flags; read-only
  • A one-byte control register - 7 control flags; read/write 

The first three registers (input, output, status) are directly accessible via ports 0x60 and 0x64. 

Port
Read / 
Write
Function
0x60 Read Read Input Buffer
0x60 Write Write Output Buffer
0x64 Read Read Status Register
0x64 Write Send Command

Writing to port 0x64 doesn't write to any specific register, but sends a command for the 8042 to interpret.  If the command accepts a parameter, this parameter is sent to port 0x60.  Likewise, any results returned by the command may be read from port 0x60.

to be continued ...........

抱歉!评论已关闭.