PS/2 Keyboard Working with ATTINY and I2C
Posted: Tue Jul 12, 2022 7:31 am
All of you have done a great job!?.
a point remains open : Does it work also with the mouse?
Commander X16 Community Forums
https://cx16forum.com/forum/
On 7/11/2022 at 7:37 PM, Wavicle said:
There is a performance increase. Is it noticeable? That depends.
... If we instead ask "can it get more done in a single frame than it could before", then yes it can, but it may only work out to 0.5 to maybe 2.0 milliseconds per second saved. It's definitely more than nothing; it may be below the threshold of perception. I'd have to put the scope on the hardware and get the per-frame timing of each to answer better.
On 7/14/2022 at 5:35 AM, Wavicle said:
A couple quick updates:
I was able to work with Kevin Williams the last few days and the PS/2 -> I2C -> X16 path is now working on the official X16 Prototype 3 board!
We have been working on stabilizing the I2C code. My initial optimism of 0% key loss was not quite correct.
Tonight I took the time to understand the kernel's I2C code, document it, and fix some of the ugly corners that could have been contributing to the overall stability of I2C. A logic analyzer trace of a key fetch transaction now looks like this:
The clocks are fairly even, though the duty cycle is obviously not 50%. The clock is pretty consistently about 33%, which is well within spec. Start conditions (green circles on the purple waveform) and stop conditions (red circles on the purple waveform) are clean and it looks like SDA is only ever changing when SCL is low (per I2C spec).
I2C isn't done yet, but it is getting closer. My greatest point of unhappiness right now is the effective clock rate - it's about 56KHz. Checking the keyboard consumes roughly 700 microseconds. The challenge to increasing the speed here comes down to the ATTINY. The trace above shows two I2C transactions: a write of 0x07 (telling ATTINY that we wish to access register 7, the scan code buffer register) and a single byte read that returns the data in that register. The ATTINY's Universal Serial Interface can receive a single byte at up to 24MHz! BUT it has to process the request in the gap between the "Setup Read" byte and the "0x00 + NAK" byte in the above trace. That's only about 20 microseconds. I switched the ATTINY to use the internal PLL clock which increased it from 8MHz to 16MHz, which helped a lot, but it sometimes misses the window of opportunity leading to bytes that don't start clocking out until the second or third I2C clock.
Things are progressing ever more in the forward direction...
On 7/14/2022 at 3:58 PM, BruceMcF said:
I still wonder about whether SPI access could be used ... even bit banged, it seems like it would be a higher bandwidth way of accessing an ATTiny ... and if the four VIA pins for the PS2 are no longer being used, then that is the minimum number of pins needed to bit bang an SPI interface.
On 7/14/2022 at 8:15 PM, Wavicle said:
If we used SPI to talk with the SMC, we would still need I2C to talk with the RTC. I haven't done a deep dive to see why the clock rate is so much slower than I was expecting after I removed all of the superfluous delays. The code is pretty tight, but the clock high pulse is pretty consistently 4.3us. At 8 MHz that works out to 25-26 cycles? That may only be 10 instructions, so it could be the best we can do. ...