Yesterday I got shocked when I opened a QWERTY ps/2 scan-2 keyboard and found an HC11 chip as controller.
So, key scan, key debounce, key decode, and PS/2 protocol all done by a HC11!!!
I don't know yet how much it uses, but I know it does not operate in "single-chip mode" but rather in "expanded mode". That's amazing!!! Even because the PS/2 keyboard implement a bidirectional synchronous serial protocol.
[attachimg=1]
ps/2 lines are open-collector type; the bus is "idle" when both lines are high: this is the only state where the keyboard (hc11 as kb controller) is allowed begin transmitting data, but the host has ultimate control over the bus and may inhibit communication at any time by pulling the clock line low, so hc11 has to monitor the line, and stop transmitting if the host requires the bus.
The ps/2 keyboard has also to generate the clock signal. If the host wants to send data, it must first inhibit communication from the device by pulling clock low. The host then pulls Data low and releases Clock. This is the "Request-to-Send" (RTS) state and signals the device to start generating clock pulses.
bus states, ps/2 bus
========================
state data clock
idle high high
inhibited high low
host_RTS low high
So, looking at the communication "hc11-to-host", when the hc11-keyboard wants to send information, it first checks the Clock line to make sure it's at a high logic level. If it's not, the host is inhibiting communication and the device must buffer any to-be-sent data until the host releases Clock.
hc11 needs an internal buffer!
Also, following the ps/2 protocol spec, the Clock line must be continuously high for at least 50 microseconds before the device can begin to transmit its data.
hc11 has internal timers for this.
Then it needs to use a 11-bit frames to transmit
- 1 start bit (always 0)
- 8 data bits (least significant bit first)
- 1 parity bit (odd parity)
- 1 stop bit (always 1)
and the clock frequency must be { 10 ... 16 } kHz.
That's all amazing because hc11 doesn't have any ps/2 hardware.
- SPI, synchronous serial protocol
- SCI, asynchronous serial protocol, what we usually call "uart"
looking at the wiring configuration, i found that the hc11 used in my keyboard is not using SPI at all but rather this setup:
ps/2 clock <------- HC11.uart_rx (crazy? hc11 has to generate the clock!!!)
ps/2 data_out <------- HC11.uart_tx
ps/2_data_in -------> HC11.???
I still have to figure out how it can generate the 10Khz ps/2 clock, and how it can use the SCI synchronously :-//
Anyone?