tmk / tmk_keyboard

Keyboard firmwares for Atmel AVR and Cortex-M
3.98k stars 1.7k forks source link

NeXT non-ADB keyboard timing #704

Closed spenczar closed 2 years ago

spenczar commented 2 years ago

I recently acquired a NeXT non-ADB keyboard, and have been exploring it pretty thoroughly with an oscilloscope and logic analyzer. Like you (https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/protocol/next_kbd.c#L153-L162), I noticed that the timing of the keyboard's signal is not quite 50 microseconds, or even 51 microseconds.

It turns out that the timing is actually 52.75 microseconds per pulse, corresponding to a frequency of 18,957 hertz. That's because the keyboard uses a Ceralock CSB455 oscillator:

image

This oscillator has a frequency of 455 kHz, and drives the keyboard's signal, updating the pulse every 24 clock cycles. 455 kHz / 24 is 18.957 kHz - resulting in the 52.75 microsecond pulses.

I have no reason to believe your code is behaving too badly, but at the least you might want to fix comments and the header settings, for example here: https://github.com/tmk/tmk_keyboard/blob/a93677cbf145baf210f92a9129ded55c9ef5657b/tmk_core/protocol/next_kbd.h#L54

and here: https://github.com/tmk/tmk_keyboard/blob/8c0e245f52182055de1d10397b58373f2bdad46d/tmk_core/protocol/next_kbd.c#L62-L67

tmk commented 2 years ago

Thanks for the headsup. I'll look into the timing when I setup NeXT keyboard and converter next time.

spenczar commented 2 years ago

FWIW, I wrote more about this here, including logic analyzer and oscilloscope images of the timing: https://journal.spencerwnelson.com/entries/nextkb.html

tmk commented 2 years ago

Thank you for your detailed writeup.

I also confirmed the bit width(52.75us) with my NeXT Keyboard using Logic Analyzer.

The converter can read signal at way better timing now.

Before Fix(signal read timing at 9b99f8f) 8GB83tI

After Fix(signal read timing at dcebfb4f) pL7NeW3

In this capture the converter reads 'IN' at either edge of 'Read'.

MEMO: https://github.com/tmk/tmk_keyboard/wiki/NeXT#next-keyboard-protocol