EEVblog Electronics Community Forum

Products => Computers => Programming => Topic started by: DiTBho on January 13, 2023, 12:52:02 pm

Title: 68hc11 as ps/2 keyboard controller: how is it possible?
Post by: DiTBho on January 13, 2023, 12:52:02 pm
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.

Code: [Select]
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
and the clock frequency must be { 10 ... 16 }  kHz.

That's all amazing because hc11 doesn't have any ps/2 hardware.

looking at the wiring configuration, i found that the hc11 used in my keyboard is not using SPI at all but rather this setup:
Code: [Select]
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?
Title: Re: 68hc11 as ps/2 keyboard controller: how is it possible?
Post by: pcprogrammer on January 13, 2023, 01:24:34 pm
Why so surprised that it is using a simple 8 bit micro to do this. PC keyboards have been made with various 8 bit micro's like 8051 derivatives.

10KHz is not that much even for these older micro's. Have never used or looked at a HC11, but guess it will have similar performance as 8051 or 6511 micro's. Have used these in multiple projects and managed to do much more then scanning a keyboard and sending out some data.
Title: Re: 68hc11 as ps/2 keyboard controller: how is it possible?
Post by: DiTBho on January 13, 2023, 01:43:56 pm
Why so surprised that it is using a simple 8 bit micro to do this. PC keyboards have been made with various 8 bit micro's like 8051 derivatives.

well, it's an uncommon and more expensive choice which even takes more space on the PCB in its "expanded mode", since in this configuration hc11 uses external ram, rom, and mux, while a single Intel {8048, 8049} chip with internal ram and rom is usually better, cheaper, therefore the common choice I have ever seen used in a ps/2 keyboard.

But I don't know, oh, Saint eBay ... I found it there, the seller has no idea and there's no label on the back of the keyboard, and it is really a weird keyboard with macro keys (you can register a keystroke) and a 4x40 LCD (looks like HD44780-ish)...so who knows ? probably only a few units were custom-made for someone in a super secret department of the CIA or FBI, or something to film x-files ;D

10KHz is not that much even for these older micro's. Have never used or looked at a HC11, but guess it will have similar performance as 8051 or 6511 micro's. Have used these in multiple projects and managed to do much more then scanning a keyboard and sending out some data.

well, HC11 has internal timers and dedicated circuits for timing, I myself wrote a PWM generator for an ESC (brush-less motor) controller, but... what seems strange and interesting is that the ps/2 lines are not connected to the pins of the timer but rather to the SCI pins.

What? Why? How? :o :o :o

So, is this some kind of bit-banging to *mimic" the ps/2 protocol? Or is there some trick to advance the internal shift register used by the SCI module? But in this case how is the clock generated?

Perplexed  :-//


Title: Re: 68hc11 as ps/2 keyboard controller: how is it possible?
Post by: DiTBho on January 13, 2023, 02:08:23 pm
 (https://www.youtube.com/watch?v=7aXbh9VUB3U)

"So how does a PS/2 keyboard interface work?" - Ben Eater
This video on Youtube is as nice as interesting  :D
Title: Re: 68hc11 as ps/2 keyboard controller: how is it possible?
Post by: pcprogrammer on January 13, 2023, 02:43:30 pm
How about some pictures of this special keyboard  :)

Quote
well, it's an uncommon and more expensive choice which even takes more space on the PCB in its "expanded mode", since in this configuration hc11 uses external ram, rom, and mux, while a single Intel {8048, 8049} chip with internal ram and rom is usually better, cheaper, therefore the common choice I have ever seen used in a ps/2 keyboard.

Yeah with additional ic's it becomes more expensive, but with the external rom it will be easier to extract and reverse engineer the firmware, to satisfy your curiosity.

Title: Re: 68hc11 as ps/2 keyboard controller: how is it possible?
Post by: SiliconWizard on January 13, 2023, 08:09:15 pm
Why so surprised that it is using a simple 8 bit micro to do this. PC keyboards have been made with various 8 bit micro's like 8051 derivatives.

I don't get the surprise factor either. You can use very slow processors to handle a keyboard. All you need is enough GPIOs to scan the keyboard matrix. The scan itself, even including debouncing and whatnot, can be done at a few kHz only, so there's ample processing power in any 8-bit CPU running at a couple MHz. You could do that with an 8-bit PIC running at 100 kHz probably, or even at lower clock rate if you program cleverly.
Title: Re: 68hc11 as ps/2 keyboard controller: how is it possible?
Post by: DiTBho on January 13, 2023, 08:30:21 pm
I don't get the surprise factor either. You can use very slow processors to handle a keyboard. All you need is enough GPIOs to scan the keyboard matrix. The scan itself, even including debouncing and whatnot, can be done at a few kHz only, so there's ample processing power in any 8-bit CPU running at a couple MHz. You could do that with an 8-bit PIC running at 100 kHz probably, or even at lower clock rate if you program cleverly.

Quote
well, it's an uncommon and more expensive choice which even takes more space on the PCB in its "expanded mode", since in this configuration hc11 uses external ram, rom, and mux, while a single Intel {8048, 8049} chip with internal ram and rom is usually better, cheaper, therefore the common choice I have ever seen used in a ps/2 keyboard.
[..]
what seems strange and interesting is that the ps/2 lines are not connected to the pins of the timer but rather to the SCI pins.
[..]
So, is this some kind of bit-banging to *mimic" the ps/2 protocol? Or is there some trick to advance the internal shift register used by the SCI module? But in this case how is the clock generated?

Title: Re: 68hc11 as ps/2 keyboard controller: how is it possible?
Post by: DiTBho on January 13, 2023, 08:32:52 pm
with additional ic's it becomes more expensive, but with the external rom it will be easier to extract and reverse engineer the firmware, to satisfy your curiosity.

reverse engineer the firmware? of course, I will  ;D