Your keyboard is a USB keyboard, and therefore you probably shouldn't be using it for testing PS/2 drivers in the first place.octacone wrote:My keyboard is an USB keyboard, which means that I don't use that port at all.
The firmware's code to do "legacy emulation for USB" (which you're relying on now) is almost always minimal and/or buggy, and this prevents an OS from doing adequate PS/2 controller initialisation and testing reliably. In addition to that, USB keyboard and USB mouse can have multiple modes - e.g. a "normal mode" where all of the device's features can be used and a (technically optional) "boot device mode" where the protocol the device uses is restricted to a standardised minimum set of features (to make it easier for the firmware's "legacy emulation of USB" code).
You checked all the scan codes that you got; and because your PS/2 controller initialisation is bad (and doesn't disable "scancode translation") you ended up getting scancode set 1 (even though keyboard is using scancode set 2).octacone wrote:When I checked all the scan codes I got, they corresponded to the first keyboard layout set. Doesn't disabling it mean that I will get a whole other set of key codes that I will have to map, bummer.
For real PS/2 devices; if a keyboard only supports scancode set 2 and that keyboard is plugged into the 2nd PS/2 port (where the PS/2 controller doesn't support scancode translation); then there is only one possible choice. If you use scancode set 2 then you can cover all possible scenarios. If you try to use scancode set 1 then you will have to support scancode set 2 for some cases (or fail to support those cases).
You mostly want a state machine to decode scancodes. For scancode set 1 the states would be:octacone wrote:Am I handling those multi bytes the right way?
- state 0: no escape sequence bytes yet
state 1: 0xE0 was received
state 2: 0xE0, 0x2A was received (first 2 bytes of "print screen pressed")
state 3: 0xE0, 0x2A, 0xE0 was received (first 3 bytes of "print screen pressed")
state 4: 0xE0, 0xB7 was received (first 2 bytes of "print screen released")
state 5: 0xE0, 0xB7, 0xE0 was received (first 3 bytes of "print screen released")
state 6: 0xE1 was received
state 7: 0xE1, 0x1D was received (first 2 bytes of "pause")
state 8: 0xE1, 0x1D, 0x45 was received (first 3 bytes of "pause")
state 9: 0xE1, 0x1D, 0x45, 0xE1 was received (first 4 bytes of "pause")
state 10: 0xE1, 0x1D, 0x45, 0xE1, 0x9D was received (first 5 bytes of "pause")
- state 0: no escape sequence bytes yet
state 1: 0xE0 was received
state 2: 0xE0, 0xF0 was received
state 3: 0xF0 was received
state 4: 0xE0, 0x12 was received (first 2 bytes of "print screen pressed")
state 5: 0xE0, 0x12, 0xE0 was received (first 3 bytes of "print screen pressed")
state 6: 0xE0, 0xF0, 0x7C was received (first 3 bytes of "print screen released")
state 7: 0xE0, 0xF0, 0x7C, 0xE0 was received (first 4 bytes of "print screen released")
state 8: 0xE0, 0xF0, 0x7C, 0xE0, 0xF0 was received (first 5 bytes of "print screen released")
state 9: 0xE1 was received
state 10: 0xE1, 0x14 (first 2 bytes of "pause")
state 11: 0xE1, 0x14, 0x77 (first 3 bytes of "pause")
state 12: 0xE1, 0x14, 0x77, 0xE1 (first 4 bytes of "pause")
state 13: 0xE1, 0x14, 0x77, 0xE1, 0xF0 (first 5 bytes of "pause")
state 14: 0xE1, 0x14, 0x77, 0xE1, 0xF0, 0x14 (first 6 bytes of "pause")
state 15: 0xE1, 0x14, 0x77, 0xE1, 0xF0, 0x14, 0xF0 (first 7 bytes of "pause")
On top of that; you may receive any of the "special bytes" listed here at any time (even when you're in the middle of receiving a multi-byte scan code). Most of these indicate some sort of problem and either causes your state machine to be reset (because driver re-tested and reset the device), or causes your driver to tell the OS "device is faulty" and terminate itself. Some of the special bytes (command acknowledged, command needs to be resent and echo) don't effect the state machine.
Cheers,
Brendan