last week we introduced a new version of the Bus Pirate universal serial interface tool. The last firmware update included an AT keyboard decoder library for both hardware versions.
There’s a ton of old AT keyboards making their way to the landfill. We’ll show you how to recycle one as an input device for your next project.
Σύνδεση
Πειρατής λεωφορείων
PC AT keyboard (pin #)
Sda
KBD data (3)
SCL
KBD Clock (1)
+ 5volts
VDD (5)
ΓΕ
GND (2)
AT keyboards communicate over a bidirectional two-wire interface. The bus is open collector, but keyboards already have internal pull-up resistors. The PC AT keyboard protocol is described here. We used our Bus Pirate tool to demonstrate the keyboard protocol, but the same basic principals apply to any microcontroller.
We connected the Bus Pirate to the keyboard as described in the table. We believe that this is a through-hole female AT keyboard jack, but we haven’t evaluated it. Do you know of a source for new sockets?
Πρωτόκολλο
The keyboard offers the clock signal for all data transfers; the PC side resembles a slave device. None of the existing Bus Pirate interface libraries work with an external clock, so we wrote a easy AT keyboard decoder library. The library depends on the keyboard’s clock signal, and it’ll hang if the keyboard fails or isn’t connected. If you use our library in your own project, consider adding a timeout delay in the readbit() and writebit() functions.
PC to keyboard command codes
Κώδικας
Εντολή
0xed
Set status LEDs
0xee
Echo 0xee
0xf0
Set scancode type
0xf3
Set repeat rate
0xf4
Keyboard enable
0xf5
Keyboard disable
0xfe
Resend last byte
0xff
Reset keyboard
A PC uses these commands to control various functions of an AT keyboard. The keyboard responds to commands with an acknowledge byte (oxfa). In our experience, the keyboard will reset if the reaction byte is not read shortly after the command is sent.
Keyboard to PC reaction codes
Κώδικας
Απάντηση
0xfa
Αναγνωρίζω
0xaa
Self test passed
0xee
Echo response
0xfe
Resend last byte
0x00 or 0xff
Error or buffer overflow
The keyboard has a number of single byte reaction codes. many PC commands are acknowledged with 0xfa. 0xaa is sent after a keyboard reset.
Setup the Bus Pirate
HiZ>m
1. Hiz
…
9. PC AT KEYBOARD
MODE>9 <–set mode
900 mode SET
X02 PC AT KB DECODER READY
PC AT KEYBOARD>
First, we setup the the Bus Pirate for AT keyboard mode, option 9.
PC AT KEYBOARD>p <–power supply setup W/w toggles 3.3volt supply? 1. NO 2. YES MODE>1 <–no 3.3volt supply W/w toggles 5volt supply? 1. NO 2. YES MODE>2 <–use the 5volt supply 9xx supply CONFIGURED, use W/w TO TOGGLE 9xx VOLTAGE MONITOR: 5V: 0.0 | 3.3V: 0.0 | VPULLUP: 0.0 | PC AT KEYBOARD>W <–capital ‘W’, turn supply on 9xx 5VOLT supply ON PC AT KEYBOARD>
Next, we configure the Bus Pirate’s power supply to offer 5volts for the AT keyboard.
PC AT KEYBOARD>r <–read byte from keyboard x30 PCATKB READ: NONE <–no data available PC AT KEYBOARD>
The AT keyboard library follows the standard Bus Pirate syntax. Numeric values are sent to the keyboard as bytes, ‘r’ reads a byte from the keyboard. The protocol is clocked by the keyboard so bitwise operations are disabled. If no data is available, the read will return ‘NONE’.
Setup the keyboard
PC AT KEYBOARD>0xee r <–send 0xee, read one byte X20 PCATKB WRITE: 0xEE got ACK <–write oxee, got ack bit x30 PCATKB READ: 0xEE <–read 0xee, echo was successful PC AT KEYBOARD>
We can test the connection to the AT keyboard using the echo command, 0xee. The keyboard will respond 0xee if our connections are correct.
The keyboard responds to commands with an ACK bit at the protocol level, and then again with an ACK byte. We found that our test keyboards reset automatically if the ACK byte wasn’t read immediately after sending the command.
PC AT KEYBOARD>0xee <–echo command X20 PCATKB WRITE: 0xEE got ACK <–wrote echo, got ACK PC AT KEYBOARD>r <–read one byte x30 PCATKB READ: 0xAA <–read 0xaa, reset indicator PC AT KEYBOARD>
Here, we tried to send the echo command and then read the reply later. The keyboard reset automatically and replies 0xaa, self-test passed.
PC AT KEYBOARD>0xff r r <–reset command, read two bytes X20 PCATKB WRITE: 0xFF got ACK <–write reset command, got ACK x30 PCATKB READ: 0xFA <–command ACK byte x30 PCATKB READ: NONE <–read once much more to reset PC AT KEYBOARD>
The keyboard is reset by writing the command 0xff, and reading two bytes. The Keyboard won’t reset until the second byte is read.
PC AT KEYBOARD>r <–read a byte x30 PCATKB READ: 0xAA <–reset success PC AT KEYBOARD>
A short period after reset we can read the power on self test (POST) results, 0xaa indicates post success.
PC AT KEYBOARD>0xf5 r <–disable the keyboard X20 PCATKB WRITE: 0xF5 got ACK <–wrote command x30 PCATKB READ: 0xFA <–read ACK byte PC AT KEYBOARD>0xf4 r <–enable keyboard X20 PCATKB WRITE: 0xF4 got ACK <–wrote command x30 PCATKB READ: 0xFA <–read ACK byte PC AT KEYBOARD>
0xf5 disaείσοδος πληκτρολογίου bles. Το 0xf4 επιτρέπει στο πληκτρολόγιο και καθαρίζει το ρυθμιστικό διάλυμα.
PC στο πληκτρολόγιο> 0xEd R 0B111 R <-SSET LED X20 PCATKB Γράψτε: 0xed πήρε εντολή LED ACK <-Set X30 PCATKB Διαβάστε: 0xFA <-Command αναγνώρισε X20 PCATKB Γράψτε: 0x07 πήρε ACK <-Send LED τιμή X30 PCATKB Διαβάστε: 0xfa <-Value αναγνώρισε PC στο πληκτρολόγιο>
Τα αριθμητικά, τα καπάκια και τα LED κλειδώματος κύλισης ελέγχονται από την εντολή 0xed. Τα τελευταία τρία κομμάτια ενός δεύτερου byte (OB111) δείχνουν ότι τα LED στο φως. Είναι πολύ σημαντικό να πραγματοποιήσετε όλες τις τέσσερις λειτουργίες byte εντός της περιόδου χρονικής περιόδου πληκτρολογίου ή το πληκτρολόγιο θα επαναρυθμιστεί.
PC στο πληκτρολόγιο> 0xee r <-cho εντολή δοκιμής X20 PCATKB Γράψτε: 0xee πήρε ACK X30 PCATKB Διαβάστε: 0xee PC στο πληκτρολόγιο> 0xfe r <-Repeat Τελευταία εντολή byte X20 PCATKB Γράψτε: 0xfe πήρε ACK <-WRITE REPEAR εντολή X30 PCATKB Διαβάστε: 0xee <-Previous byte επαναλαμβάνεται PC στο πληκτρολόγιο>
Η τελευταία εντολή ενδιαφέροντος πληκτρολογίου είναι η εντολή επανάληψης byte. Το 0xfe προκαλεί το πληκτρολόγιο να στείλει ξανά το τελευταίο byte. Αυτή είναι μια χρήσιμη εντολή εάν υπήρχε σφάλμα κατά την προηγούμενη μετάδοση.
Διαβάστε τις βασικές πρέσες
Οι πιέσεις κλειδιών είναι ρυθμισμένοι από το πληκτρολόγιο μέχρι να τα διαβάσουμε.
PC στο πληκτρολόγιο> R <-Read Byte X30 PCATKB Διαβάστε: 0x29 <-Scancode PC στο πληκτρολόγιο> R <-Read Byte X30 PCATKB Διαβάστε: 0xF0 <-Bey απελευθέρωση Scancode PC στο πληκτρολόγιο> R <-Read Byte X30 PCATKB Διαβάστε: 0x29 <-Scancode PC στο πληκτρολόγιο>
Ένας βασικός τύπος στέλνει scancodes, αλληλουχίες πολλαπλών byte που αντιπροσωπεύουν τους βασικούς πρέσες. Στο παράδειγμα, πιέσαμε χώρο που έχει το Scancode 0x29. When a essential is released, the keyboard sends 0xf0 and the scancode for the essential (0x29). Each essential press results in a similar three part sequence.
PC AT KEYBOARD>r:4 <–read 4 bytes x31 PCATKB bulk READ, 0x04 BYTES: 0x29 0xF0 0x29 NONE <–space scancode PC AT KEYBOARD>
This is just a simplified version of the previous example. rather than read three bytes individually, we used the bulk read command. Again, we get the space scancode sequence. Our attempt to read a non-existant fourth byte fails.
0