Author Topic: ADB to USB keyboard converter  (Read 77256 times)

0 Members and 1 Guest are viewing this topic.

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter
« on: Wed, 12 January 2011, 11:53:40 »
I needed a ADB to USB keyboard converter to test a feel of ADB keyboards on actual usage. After 2days coding and several hours debug, I made this converter based on my keyboard firmware. If you are interested in ADB keyboard converter, try this.


README FIRST
https://github.com/tmk/tmk_keyboard
https://github.com/tmk/tmk_keyboard/tree/master/converter/adb_usb

and optionally,
https://github.com/tmk/tmk_keyboard/wiki
https://github.com/tmk/tmk_keyboard/labels/NOTE


NEED HELP?
Your converter doesn't work?
Frist, post pics of your hardware and wriring this really save time of us. Don't save your time by omitting this.

If you edit code
Post your code. Don't hesitate to show your dirty code!



UPDATE
2012/12/12 Extended keyboard support by blargg
2013/04/08 Fix issue: ADB-USB converter misses keystrokes (NOT FIXED COMPLETELY)
2013/07/22 Changed Pin usage: PD0, NOT PF0 now
2013/10/11 WIP: Fix ADB-USB converter misses keystrokes
2013/11/28 Fix key drop problem finally Thank you, blargg!
2015/04/28 Mouse is supported by mek-apelsin



SOURCE CODE
https://github.com/tmk/tmk_keyboard/tree/master/converter/adb_usb


BUILD FIRMWARE
https://github.com/tmk/tmk_keyboard/blob/master/doc/build.md


BUILD CONVERTER
You can use PJRC Teensy or other dev board with ATMega32U4.

Code: [Select]
ADB female socket from the front:
  ,--_--.                 
 / o4 3o \      1: DATA
| o2   1o |     2: Power SW
 -  ===  -      3: VCC
  `-___-'       4: GND

  • Connect keyboard DATA line to PD0 pin(configurable in config.h), not to mention VCC and GND as well.
  • Just 'make' to build firmware binary.
  • And program your AVR with the firmware.
DEBUG
You can use PJRC's 'hid_listen' command to see debug print.
http://www.pjrc.com/teensy/hid_listen.html


LOCKING CAPSLOCK
Many of old ADB keyboards have locking switch for Caps lock.
https://github.com/tmk/tmk_keyboard#mechanical-locking-support-for-capslock


Also you may want to remove locking pin from the push-lock switch to use it as a normal momentary switch.
http://www.youtube.com/watch?v=9wqnt2mGJ2Y



PULL-UP RESISTOR
You must have a external pull-up resistor(1K is recommended) on DATA line.
This converter uses AVR's internal pull-up, but it seems to be  too weak to communicate with ADB keyboard. The external pull-up resistor is strongly recommended required.

Code: [Select]
Keyboard       Conveter
               ,------.
5V------+------|VCC   |
        |      |      |
        R      |      |
        |      |      |
Signal--+------|PD0   |
               |      |
GND------------|GND   |
               `------'
R: 1K Ohm resistor
https://github.com/tmk/tmk_keyboard/wiki/FAQ#pull-up-resistor


ADB protocol Resource for Developer
This is code for ADB protocol:
https://github.com/tmk/tmk_keyboard/blob/master/protocol/adb.c



More
« Last Edit: Mon, 27 April 2015, 21:54:17 by hasu »
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline lowpoly

  • Posts: 2516
ADB to USB keyboard converter for Teensy
« Reply #1 on: Fri, 14 January 2011, 04:51:53 »
Hah, great.

Strange nobody replied. I thought the Griffin iMate was hard to get these days. The mod forum should have a better place in the forum overview, IMO.

Also, the iMate had issues with intl. 'boards.

So, Colemak converter for ps/2 'boards next? :-)

Miniguru thread at GH, preview site at guru-board.com
The Apple M0110 Today

Offline Soarer

  • * Moderator
  • Posts: 2672
  • Location: UK
ADB to USB keyboard converter for Teensy
« Reply #2 on: Fri, 14 January 2011, 06:20:26 »
Neat. :)

I would like to add ADB support to my adapter in the future, but I have lots of other tasks to complete first! One of them is implementing a key remapping UI ;)

And I recently bought a couple of the Belkin ADB adapters, which work ok, at least on US layout. But it seems they are not generally available either :/

Offline Findecanor

  • Posts: 3488
  • Location: Stockholm, Sweden
ADB to USB keyboard converter for Teensy
« Reply #3 on: Fri, 14 January 2011, 06:57:32 »
Superb! How does it handle latching Caps Lock, though?
Home: Phantom (Lubricated Cherry MX Clear, Custom case, Thick laser-etched Cherry PBT keycaps, Custom firmware).

Online iMav

  • babysitter
  • Location: Columbus, WI
  • "En casa del herrero, cuchillo de palo"
ADB to USB keyboard converter for Teensy
« Reply #4 on: Fri, 14 January 2011, 07:26:10 »
Great job!  Love seeing this type of stuff.  How many days have you lost with your head down programming that teensy?  ;)

I may just have to pick up one of these and start playing as well.

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #5 on: Sat, 15 January 2011, 01:08:18 »
Quote from: Findecanor;278417
Superb! How does it handle latching Caps Lock, though?


It doesn't nothing actually now.
At this time you must remove lock pin form the ALPS or replace with normal switch :)
Or if you don't care about Caps LED, you can remap to Shift.
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline kps

  • Posts: 607
ADB to USB keyboard converter for Teensy
« Reply #6 on: Sat, 15 January 2011, 12:12:08 »
Hasu, would you mind posting your hex file? I am trying to figure out what stupid thing I have done, since I see no keystrokes. The device is recognized as a keyboard, so I know it has been programmed correctly. I have tried two different computers, three different keyboards, and double-checked my wiring.


Quote from: hasu;278881
It doesn't nothing actually now.
At this time you must remove lock pin form the ALPS or replace with normal switch :)
Or if you don't care about Caps LED, you can remap to Shift.


This part should be simple; there is a specific USB code for locking Caps keys 130 rather than 57.

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #7 on: Sat, 15 January 2011, 23:05:37 »
Quote from: kps;279038
Hasu, would you mind posting your hex file? I am trying to figure out what stupid thing I have done, since I see no keystrokes. The device is recognized as a keyboard, so I know it has been programmed correctly. I have tried two different computers, three different keyboards, and double-checked my wiring.

No, I don't mind at all.

Regarding your wiring, it seems to be OK but you may need to check ADB socket side again.
Following is my ADB socket pinouts, but I think yours is same as mine.

Code: [Select]

    Female socket from the front
    __________
    |        | <--- top
    | 4o  o3 |
    |2o    o1|
    |   ==   |
    |________| <--- bottom
      |    |   <--- 4pins

    Female socket from bottom

    ========== <--- front
    |        |
    |        |
    |2o    o1|
    |4o    o3|
    ---------- <--- back

    1: Data
    2: Power SW(low when press Power key)
    3: Vcc(5V)
    4: GND


   

Quote

This part should be simple; there is a specific USB code for locking Caps keys 130 rather than 57.


Thank you. I will try the keycode and fix my code.
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #8 on: Sun, 16 January 2011, 00:04:22 »
I tried the "Locking Caps Lock"(0x82) instead of Caps Lock(0x39) in Windows and it failed to handle the key. I didn't check it on other OSes, but Windows fails at least.

Windows has no translation table for "Locking Caps Lock", thus we can use the key unfortunately :(

See this document for details:
http://www.microsoft.com/whdc/archive/scancode.mspx
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline Soarer

  • * Moderator
  • Posts: 2672
  • Location: UK
ADB to USB keyboard converter for Teensy
« Reply #9 on: Sun, 16 January 2011, 07:38:31 »
That's a messy problem :(

I suppose the only solution is to send two packets for each change in state of the caps lock - one with the key down, and then one with the key up a millisecond or so later.

That appears to be how the Belkin adapter handles it.

What a hassle though!

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #10 on: Sun, 16 January 2011, 08:17:58 »
Quote from: hasu;279286
No, I don't mind at all.

kps,
I misinterpreted your first sentence :)
Sorry. I attached my hex.



Quote from: Soarer;279367
That's a messy problem :(

I suppose the only solution is to send two packets for each change in state of the caps lock - one with the key down, and then one with the key up a millisecond or so later.

That appears to be how the Belkin adapter handles it.

What a hassle though!


Belkin solution will be a problem for someone who want to remap the key.
But it may be good for most people.

I prefer switch conversion solution though it is not for everyone.
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline Soarer

  • * Moderator
  • Posts: 2672
  • Location: UK
ADB to USB keyboard converter for Teensy
« Reply #11 on: Sun, 16 January 2011, 08:32:14 »
Quote from: hasu;279388
Belkin solution will be a problem for someone who want to remap the key.
But it may be good for most people.

I prefer switch conversion solution though it is not for everyone.


Yes, that would be better.

But... I have a Macally MK96, and it already has a non-locking switch for caps lock! Its keyboard firmware must simulate the locking action, I guess. I don't know how many other ADB keyboards do a similar thing, but the only way to get a normal key action with them would be to replace the keyboard controller (which is what I will do :) ).

Offline kps

  • Posts: 607
ADB to USB keyboard converter for Teensy
« Reply #12 on: Sun, 16 January 2011, 12:33:21 »
Quote from: hasu;279388
kps, I misinterpreted your first sentence :)


Sorry, my fault for using idiomatic English.

Thank you; that has helped me narrow down my problem somewhat.

I hacked in some ugly code to send a Shift directly when the power key is pressed, and that worked. With a logic probe, I see "chatter" on the ADB line on the other port of the keyboard, so I think my connections are sound. I suspect my problem may be either noise or timing related, since (by using the LED on the Teensy) it seems I never get past the if (read_bit()) // Stopbit(0) in adb_host_kbd_recv().

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #13 on: Mon, 17 January 2011, 09:38:47 »
Quote from: kps;279449

I hacked in some ugly code to send a Shift directly when the power key is pressed, and that worked. With a logic probe, I see "chatter" on the ADB line on the other port of the keyboard, so I think my connections are sound. I suspect my problem may be either noise or timing related, since (by using the LED on the Teensy) it seems I never get past the if (read_bit()) // Stopbit(0) in adb_host_kbd_recv().



My code is very primitive and have not been checked its signal conformity
by logic analyzer nor oscilloscope, thus it could lose the sync under some circumstances.

Another possibility I come up with is  port damage of your Teensy.
My Teensy actually lost one port by latch-up while prototyping/debug :)
If your DATA line port is suspicious, you should try another port.
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline kps

  • Posts: 607
ADB to USB keyboard converter for Teensy
« Reply #14 on: Mon, 17 January 2011, 10:52:09 »
Quote from: hasu;279835
My code is very primitive and have not been checked its signal conformity by logic analyzer nor oscilloscope, thus it could lose the sync under some circumstances.


I may get out those tools next weekend. My logic analyzer is ancient (HP1615A, 1979) but should be adequate for ADB.

Quote
Another possibility I come up with is  port damage of your Teensy.
My Teensy actually lost one port by latch-up while prototyping/debug :)
If your DATA line port is suspicious, you should try another port.


I don't think that is the case, but I will check.

I do own an iMate, so this is not vital to me, but it might help other people later.

Later, I want to try using one of the cheap PS3 dongles with an AT90USB162. That, plus half an s-video cable, would make an ADB converter for under $10.

Offline jeffreysung

  • Posts: 11
ADB to USB keyboard converter for Teensy
« Reply #15 on: Fri, 11 February 2011, 02:30:41 »

This week I got Teensy++ 2.0 and tried. As a result I found problems.

1. If ADB cabe is long, OSX couldn't detect keyboard. (In fact, it does but couldn't detect any key strokes) I have short cable which is included in Apple adjustable keyboard and three other normal cables. Short cable works good but others not.
2. key stroke is recognized multiple time.

These problems (I Think) caused by my environment...

I changed adb/config.h (I moved port and bit)

#define ADB_PORT        PORTB
#define ADB_PIN         PINB
#define ADB_DDR         DDRB
#define ADB_DATA_BIT    6
#define ADB_PSW_BIT     5       // optional

I should change ADB_DDR/ADB_PIN as above right ?
« Last Edit: Fri, 11 February 2011, 02:42:54 by jeffreysung »

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #16 on: Sat, 12 February 2011, 03:03:55 »
jeffreysung,
Thank you for your reporting!
I don't use this converter daily, so it is still very immature.
But I am happy to improve this project, any feedback is welcome.

Quote from: jeffreysung;293270

This week I got Teensy++ 2.0 and tried. As a result I found problems.

1. If ADB cabe is long, OSX couldn't detect keyboard. (In fact, it does but couldn't detect any key strokes) I have short cable which is included in Apple adjustable keyboard and three other normal cables. Short cable works good but others not.
2. key stroke is recognized multiple time.

These problems (I Think) caused by my environment...

My code(adb.c) which process ADB signal is very primitive. It use polling & delay method to check the DATA line activity, while it should use interrupt routine.  I think it is prone to lose sync with keyboard under some condition(signal with loose edge or interference by other interrupt code). This perhaps causes your problems.

I will rewrite adb.c using pin chajnge interrupt at an early day.


Quote

I changed adb/config.h (I moved port and bit)

#define ADB_PORT        PORTB
#define ADB_PIN         PINB
#define ADB_DDR         DDRB
#define ADB_DATA_BIT    6
#define ADB_PSW_BIT     5       // optional

I should change ADB_DDR/ADB_PIN as above right ?

You are right. It is OK to use PB6.
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline kps

  • Posts: 607
ADB to USB keyboard converter for Teensy
« Reply #17 on: Sat, 12 February 2011, 12:56:17 »
Quote from: jeffreysung;293270
1. If ADB cabe is long, OSX couldn't detect keyboard.


Ah. I just tried this. (Last time I used a normal coiled ADB cable.)  I made a 3-inch cable from an S-video cable. With this, a IIgs keyboard worked (except for the duplicates) and an Extended partly worked.

Then I did a little searching and found a PIC application note on ADB. Based on that, I added a pullup to the ADB data line. With the pullup, both keyboards work, even with a long cable.

Offline jeffreysung

  • Posts: 11
ADB to USB keyboard converter for Teensy
« Reply #18 on: Sat, 12 February 2011, 19:50:21 »
Quote from: kps;294046
Ah. I just tried this. (Last time I used a normal coiled ADB cable.)  I made a 3-inch cable from an S-video cable. With this, a IIgs keyboard worked (except for the duplicates) and an Extended partly worked.

Then I did a little searching and found a PIC application note on ADB. Based on that, I added a pullup to the ADB data line. With the pullup, both keyboards work, even with a long cable.


ATMEL supports (maybe) both pull up/down. This could be very useful in weak signal but pull up/down is a little bit slow compared to normal signaling. Thanks for useful info.

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #19 on: Sun, 13 February 2011, 03:02:09 »
kps,

I confirmed the problem on coiled cable, and pull-up resistor solved it.  With coiled cable the converter couldn't get signal from keyboard and  didn't recognize any key stroke. I couldn't see the key duplicate  problem.

AVR's internal pull-up seems to be too weak to communicate with ADB  keyboards, we may need external pull-up resistor instead in many case  though some cable including my  straight cable doesn't need it.

Thanks.

My pull-up resistor:
« Last Edit: Sun, 13 February 2011, 04:12:27 by hasu »
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline jeffreysung

  • Posts: 11
ADB to USB keyboard converter for Teensy
« Reply #20 on: Mon, 14 February 2011, 01:36:39 »
Quote from: hasu;294316
kps,


AVR's internal pull-up seems to be too weak to communicate with ADB  keyboards, we may need external pull-up resistor instead in many case  though some cable including my  straight cable doesn't need it.


It is the other around.

There is internal pull-up resistor inside and if you add resistor outside pin, total resistance goes down(1/Rt = 1/Rin + 1/Rout) and this could explain why coiled or long cable couldn't work with.
The ADB cable is like a attenuator and because of internal (big) pull up resistor, signal couldn't swing between +5V and 0V properly (means couldn't go down to ground level).

By adding a external resistor, total pull up resistance goes down, and signal could swing more properly.

Offline Soarer

  • * Moderator
  • Posts: 2672
  • Location: UK
ADB to USB keyboard converter for Teensy
« Reply #21 on: Mon, 14 February 2011, 08:24:19 »
Partly, you are saying the same thing: a big resistor = a weak pull-up.

But the voltage range of the signal is not affected. The capacitance of the cable makes the signal slow to rise from 0V to +V, since that capacitance has to charge up via the pull-up resistor.

Offline jeffreysung

  • Posts: 11
ADB to USB keyboard converter for Teensy
« Reply #22 on: Tue, 15 February 2011, 22:24:30 »
I fount a strange thing.

Up to now, I tested this board with my macbookpro/iMac. It always shows multiple stroke from time to time. When I connected to Windows PC, there is no multiple strokes.

Is there anybody who tried with Mac ?

Offline Soarer

  • * Moderator
  • Posts: 2672
  • Location: UK
ADB to USB keyboard converter for Teensy
« Reply #23 on: Wed, 16 February 2011, 09:07:40 »
I played around with external pull-up resistors on my PS2 adapter (the principle is the same).

This is with about 5m of cable in all, so pretty much a worst case scenario.

Internal pull-up:

6042-0

External 2k2 pull-up - better, but still a bit slow to rise and a fair bit of crosstalk between the clock and data signals:

6044-1

External 1k pull-up - seems to be the sweet spot, much cleaner signals in every respect:

6046-2

I think it affects the ADB adapter more because the timing is critical - if you have a slow rise on the signal it moves the switching point in time.
« Last Edit: Sun, 14 October 2012, 10:49:01 by Soarer »

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #24 on: Wed, 16 February 2011, 22:55:18 »
jeffreysung,
hmm, it is a weird behaviour.  I can't come up with the cause now and I have no healthy mac to try:(

Soarer,
It is nice to see real wave forms!
I have ordered my first oscilloscope a few days ago. I can hardly wait for my Rigol :)
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline Soarer

  • * Moderator
  • Posts: 2672
  • Location: UK
ADB to USB keyboard converter for Teensy
« Reply #25 on: Thu, 17 February 2011, 06:40:34 »
Excellent! I don't know how I managed before I got my 'scope :-)

I have just ordered my first logic analyzer (although a cheap one!), an Open Workbench Logic Sniffer. So, similar suspense here :-)

Offline jeffreysung

  • Posts: 11
ADB to USB keyboard converter for Teensy
« Reply #26 on: Wed, 23 February 2011, 00:49:40 »
Multiple key stroke problem solved.

in adb/matrix.c

just add delay statement before if (codes == 0 ) {

like this.

    key0 = codes>>8;
    key1 = codes&0xFF;

   _delay_us(300);
    if (codes == 0) {                           // no keys
        return 0;
    } else if (key0 == 0xFF && key1 != 0xFF) {  // error
 


I found this problem in making USB controller for Apple Desktop Bus Keyboard(a.k.a. IIgs keyboard).

Why 300us ? This is experimental value. I tried from 250us to 500us and 300us is the most stable value.
(With 300us, there is little multiple stroke issue.)

and I don't know why this problem is occurred only with OSX. : (

Offline jeffreysung

  • Posts: 11
ADB to USB keyboard converter for Teensy
« Reply #27 on: Thu, 03 March 2011, 21:06:40 »
The upper solution could solve almost multiple key stroke problem but not all.

By setting USB device as low speed device, this problem could be solved.(I didn't tried)

I made USB controller for Apple desktop bus keyboard(IIgs) with Teensy++2.0 and this multiple key stroke problem exists also. I tried in many ways but I couldn't find what is wrong but I could expect there is some timing issue between USB host and firmware. As a work around, by setting this controller as low speed device this problem has gone.

Here is my work picture

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #28 on: Fri, 04 March 2011, 09:01:14 »
jeffreysung,
Nice USB receptacle setting!


Your problem is not bouncing. right?
I have not experienced the multiple key stroke problem. I tried AEKII, m0116 and some Macways, but it was not a long time use.
Unfortunately I have no IIgs to try. (It is one of keyboards I want to own! :)

Do you have other ADB keyboard than IIgs?
I want to know whether the problem is specific to IIgs or not.

Do you have iMate or other converter?
I want to know whether the problem is caused by my converter or not.
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline kps

  • Posts: 607
ADB to USB keyboard converter for Teensy
« Reply #29 on: Fri, 04 March 2011, 09:17:19 »
Quote from: hasu;304861
Do you have other ADB keyboard than IIgs?
I want to know whether the problem is specific to IIgs or not.


I do have most models of Apple ADB keyboard, including the IIgs. I will test several this weekend.

Quote
Do you have iMate or other converter?
I want to know whether the problem is caused by my converter or not.


I have an iMate, and have never seen duplicate keys with it.

Offline kps

  • Posts: 607
ADB to USB keyboard converter for Teensy
« Reply #30 on: Sun, 06 March 2011, 10:24:02 »
I have tried several different keyboards, and got duplicate key reports with all of them.

Quote
TThis is an  Apple  Desktop Bus keyboard, modell A9M0330.
This  is ann Apple Keyboardd,  model  M0116.
This is a squishy Apple Keyboard II,  mmodel  MM0487..
This  is  ann Apple   Extended  Keyboard,, model M0115.
TThis  is an  Appple Extennded Keyboard  II, mmodel M3501.
Thhis is an Applle Adjustable Keyboard, modell MM1242.

woody

  •  Guest
ADB to USB keyboard converter for Teensy
« Reply #31 on: Sun, 06 March 2011, 11:36:39 »
kps, do you happen to have extra A9M0330 for sale?

Offline jeffreysung

  • Posts: 11
ADB to USB keyboard converter for Teensy
« Reply #32 on: Sun, 06 March 2011, 20:12:10 »
Quote from: hasu;304861
jeffreysung,
Nice USB receptacle setting!


Your problem is not bouncing. right?
I have not experienced the multiple key stroke problem. I tried AEKII, m0116 and some Macways, but it was not a long time use.
Unfortunately I have no IIgs to try. (It is one of keyboards I want to own! :)

Do you have other ADB keyboard than IIgs?
I want to know whether the problem is specific to IIgs or not.

Do you have iMate or other converter?
I want to know whether the problem is caused by my converter or not.

1.I have two "2 adb to usb" converters and there is no problems with these.
2.I have AEKII/IIgs/Design/Adjustable keyboards and all the same problem with converter.
3.I think there is a different in handling USB interrupt between OSX and Windows. Windows doesn't have problem.
4.If I set teensy( ++ 2.0) as low speed device, this multiple stroke problem is gone. There should be a timing mismatch between this firmware and OSX.
   a. As I wrote before, if I insert delay in keyscan function, the occurrence of this multiple stroke reduced.
   b. If I set as low speed device, USB interrupt/FIFO speed would go lower and this prevent our problem.
   c. With low speed device setting, USB debugging has some problem. It it too low to print debug information on screen.


To set Teensy++ 2.0 as low speed device, you should modify some functions and headers.

usb.c, usb_init
UDCON = 0; --> UDCON = 0x04;  (for Teensy++2.0, set LSM bit.)

usb_debyg.h
#define DEBUG_TX_SIZE 32 --> 8  (All endpoint size should be 8byte)

usb_keyboard.h
#define KDB2_SIZE 16 --> 8 (the same with above)

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #33 on: Sun, 06 March 2011, 20:36:22 »
Quote from: kps;306178
I have tried several different keyboards, and got duplicate key reports with all of them.

Thanks.
It is on OS X? You see this problem on WIndows or Linux too?

I have no problem during 20-30min my daily usage. Hmm...
Disclosure: I am slow typer 40-50wpm.

I tried this attached firmware on Teensy2.0 and latest firmware on Teensy2.0/Teensy++2.0. My pull-up resistor is 10K Ohm.

Cables: coiled cable and straight cable.
Keyboards: AEKII(M3501) and Apple keyboard(M0116)
OS: WIndows 7 64bit and Ubuntu 10.04


Quote
1.I have two "2 adb to usb" converters and there is no problems with these.
2.I have AEKII/IIgs/Design/Adjustable keyboards and all the same problem with converter.
3.I think there is a different in handling USB interrupt between OSX and Windows. Windows doesn't have problem.
Thanks, jeffreysung.
Finally, I understood that it is a problem specific to OS X.
Unfortunately I have no OSX to try :(

My USB stack(based on PJRC's code) seems to have some faults.
« Last Edit: Sun, 06 March 2011, 20:45:00 by hasu »
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline kps

  • Posts: 607
ADB to USB keyboard converter for Teensy
« Reply #34 on: Mon, 07 March 2011, 09:12:12 »
Quote from: hasu;306544
It is on OS X? You see this problem on WIndows or Linux too?


It was OS X. I tried again on Windows (with an AEK) and saw two instances of doubled characters in a half page of text.

For my tests I was using yesterday's firmware (did a 'git pull' before testing), 10K pullups, and a 1m straight cable (half an S-video cable).

Quote
My USB stack(based on PJRC's code) seems to have some faults.


I am not sure that is so. I notice in my tests above that 12 of 14 doubles occur at the beginning or end of words. Obviously the software does not know about words, but my fingers do. I wonder whether the ADB keyboards might actually be sending a second event if the key is still down when it is polled again.

Offline jeffreysung

  • Posts: 11
ADB to USB keyboard converter for Teensy
« Reply #35 on: Mon, 07 March 2011, 11:26:04 »
Quote from: kps;306815

I am not sure that is so. I notice in my tests above that 12 of 14 doubles occur at the beginning or end of words. Obviously the software does not know about words, but my fingers do. I wonder whether the ADB keyboards might actually be sending a second event if the key is still down when it is polled again.


According to my test (USB controller directly attached to IIgs), this multiple stroke might be caused with interrupt handling. The source code looks good and USB interrupt handling functions are based on sample code of pjrc.com.

1. When I debugged adb adapter, key stroke scanning has no problem and USB report(data structure for sending keys to USB host) has no problem.
2. The problem is adb adapter has only one key data but it seems that USB host get the data multiple time.
3. This situation could be occurred if interrupt flag is handled wrong. Think about this. USB host requested to device for new data. Device had sent one data(right data). With some problem, device think there is more data in FIFO and send data at next request. (USB host search new data by polling devices)
4. I think that there could be a problems in key scan turn around time. The simplified actions of firmware is repeating this procedure "key scan - if there is modified key send it FIFO". In repeating this procedure, there should be some problems (especially interrupt handling).
5. In the case of USB controller(directly attached to IIgs), everything from keyscan to storing data to FIFO is perfect.

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #36 on: Tue, 08 March 2011, 00:20:18 »
After browse of some codes of Darwin, I found a clue of the problem.
OS X seems to request SET_IDLE(24ms) to keyboard, while Windows requests SET_IDLE(0ms). I think Linux also requests 0ms.

HID SET_IDLE request inhibits device to report keys during given interval if key state is not changed. 0ms means device must not report without change.
I assume this difference causes the problem appeared only in OS X.

Bug codes run only when idle interval runs out. On Windows and Linux the codes with bug never run, on the other hand the problem occasionally occurs on OS X.

This bug is very timing issue around interrupt handlers. I will fix this problem but it may take some time.



This is the codelet from Apple.
OS X requests 24ms on most keyboards, but 0ms on Apple's. why?
If I found right clue, changing VENDOR_ID to '0x05AC'(Apple) in config.h will disappear the problem.

http://www.opensource.apple.com/source/IOUSBFamily/IOUSBFamily-417.4.1/IOUSBHIDDriver/Classes/IOUSBHIDDriver.cpp

Code: [Select]
   // For Keyboards, set the idle millecs to 24 or to 0 if from Apple
    //
    if ( (_interface->GetInterfaceClass() == kUSBHIDClass) &&
         (_interface->GetInterfaceSubClass() == kUSBHIDBootInterfaceSubClass) &&
         (_interface->GetInterfaceProtocol() == kHIDKeyboardInterfaceProtocol) )
    {
        if (_device->GetVendorID() == kIOUSBVendorIDAppleComputer)
        {
            SetIdleMillisecs(0);
        }
        else
        {
            SetIdleMillisecs(24);
        }
    }
« Last Edit: Tue, 08 March 2011, 00:23:53 by hasu »
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline jeffreysung

  • Posts: 11
ADB to USB keyboard converter for Teensy
« Reply #37 on: Tue, 08 March 2011, 00:39:15 »
Wow.. awesome!!! there is no multiple key stroke!!!!

Thanks. Hasu

I attach screenshot.


Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #38 on: Wed, 09 March 2011, 20:27:21 »
Quote from: jeffreysung;307403
Wow.. awesome!!! there is no multiple key stroke!!!!


jeffreysung,
Thanks for your feedback.

I pushed fix for the problem to github now. I think this fix avoids multiple key stroke.
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline b0bb3r5

  • Posts: 2
ADB to USB keyboard converter for Teensy
« Reply #39 on: Sat, 12 March 2011, 11:56:29 »
i have a old m0110a how would i go about getting this to work with a teensy? i have a teensy, the keyboard, electronics...etc and id really love to get some help converting it

Offline kps

  • Posts: 607
ADB to USB keyboard converter for Teensy
« Reply #40 on: Sat, 12 March 2011, 13:33:25 »
Quote from: b0bb3r5;310514
i have a old m0110a how would i go about getting this to work with a teensy? i have a teensy, the keyboard, electronics...etc and id really love to get some help converting it


The M0110A is not an ADB keyboard, so you should probably start a separate thread for that.

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #41 on: Thu, 01 September 2011, 00:06:35 »
I finally added locking capslock key support and this is default now.
Someone sent me a patch for this feature. Thank you!

I think most ADB keyboards has a locking capslock in either case whether physical push-lock or software locking.
So this feature is good for people using their keyboard as is, while some who replace caps with non-locking switch
for remapping will want to disable this feature with commenting out following macro in config.h.
Code: [Select]

/* Locking Caps Lock support */
#define MATRIX_HAS_LOCKING_CAPS
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline nodnerb

  • Posts: 10
  • Location: Sydney
ADB to USB keyboard converter for Teensy
« Reply #42 on: Sat, 29 October 2011, 00:36:38 »
Hi Hasu,

Your firmware is some great work... works out of the box for my Apple-branded keyboards!

I had some problems with a Datadesk Smartboard, and it wasn't until I got it on an oscilloscope that I found out why...
For some reason, this keyboard sends a '1' as a stop bit (which is against the ADB standard... how did this keyboard ever work on a Mac?).
Also, the timing of the signals is a bit screwy,
__~~~ after 35 us for '1'
___~~ after 56 us for a '0' (This should be 65 us!) - this one is causing random bit-swapping with the default 55 us delay before reading the bit value.
So, for this board, I've changed the read delay to 45 us and disregard the value of the stop bit.

Just got things working a bit on Friday, we'll see how the board works next week.

My keyboard has a sticky "B" key - don't know what I can do about this just yet...

Thank you for providing the firmware for us!

I'm going to look into your source code to see how the layer switching works.

Cheers,
nodnerb
Ergodox, Kinesis contoured (ps/2), Sanwa vertical mouse

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #43 on: Sat, 29 October 2011, 07:59:33 »
nodnerb,
Thank you for your feedback! This is good to know.


Quote from: nodnerb;441636

I had some problems with a Datadesk Smartboard, and it wasn't until I got it on an oscilloscope that I found out why...
For some reason, this keyboard sends a '1' as a stop bit (which is against the ADB standard... how did this keyboard ever work on a Mac?).
Also, the timing of the signals is a bit screwy,
__~~~ after 35 us for '1'
___~~ after 56 us for a '0' (This should be 65 us!) - this one is causing random bit-swapping with the default 55 us delay before reading the bit value.
So, for this board, I've changed the read delay to 45 us and disregard the value of the stop bit.

Your keyboard might be compliant for ADB spec though it is not good implementation without enough margin.
If my code could read a bit exactly after 55us it seems to has no problem.  My code intends to read a bit after 55us delay,
but delay time is not so accurate because the code is written in C as you know. It may be imposed a few excess micro seconds in addition to the 55us.


Quote from: nodnerb;441636

I'm going to look into your source code to see how the layer switching works.

Ah, it is a very confusing and chaotic part of my firmware :(
and its broken English comment doesn't work even for me :)
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline CyberDave

  • Posts: 36
ADB to USB keyboard converter for Teensy
« Reply #44 on: Wed, 21 December 2011, 03:41:54 »
Thanks so much for this! I'm modding an Apple Extended Keyboard II with an internal Teensy adapter as a Christmas gift for my brother.


It's working great, except for one thing...the power button isn't doing anything on my Mac. Yes, it is wired up correctly...the Teensy is seeing the key up/down, but seemingly not doing anything. Here's what hid_listen.mac shows for debugging output:


Code: [Select]
r/c 01234567
00: 00000000
01: 00000000
02: 00000000
03: 00000000
04: 00000000
05: 00000000
06: 00000000
07: 00000000
08: 00000000
09: 00000000
0A: 00000000
0B: 00000000
0C: 00000000
0D: 00000000
0E: 00000000
0F: 00000001
ignore keycode: B0
keys: 00 00 00 00 00 00  mods: 00
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
ignore keycode: B0
adb_host_kbd_recv: FFFF


I'm not sure what the "ignore keycode" is all about. Will take another look tomorrow when I'm not half asleep. Until then, any ideas?

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #45 on: Wed, 21 December 2011, 11:25:05 »
Hi, CyberDave. Thanks for your feedback.

Quote from: CyberDave;475045
Thanks so much for this! I'm modding an Apple Extended Keyboard II with an internal Teensy adapter as a Christmas gift for my brother.

Wow, AEKII for gift?! Your brother is so lucky :)


Quote
It's working great, except for one thing...the power button isn't doing anything on my Mac. Yes, it is wired up correctly...the Teensy is seeing the key up/down, but seemingly not doing anything. Here's what hid_listen.mac shows for debugging output:


Oops, this is a bug. I fixed this bug and pushed the commit to github, try latest sources.

With default keymap you can send a power down event to OS with the power button, Mac's reaction to the event depends on your OS setting. I think Mac will display a sleep/shutdown dialog or sleep immediately without warn.
By pushing power button you will be able to wake your sleeping Mac as well.
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline CyberDave

  • Posts: 36
ADB to USB keyboard converter for Teensy
« Reply #46 on: Wed, 21 December 2011, 18:42:47 »
Quote from: hasu;475239
Hi, CyberDave. Thanks for your feedback.

Wow, AEKII for gift?! Your brother is so lucky :)

Oops, this is a bug. I fixed this bug and pushed the commit to github, try latest sources.

With default keymap you can send a power down event to OS with the power button, Mac's reaction to the event depends on your OS setting. I think Mac will display a sleep/shutdown dialog or sleep immediately without warn.
By pushing power button you will be able to wake your sleeping Mac as well.

He's an editor at a small book publisher, and an aspiring writer. We've been Mac users since we were kids...I've Retr0brighted the keyboard and cleaned it up. I hope he gets a kick out of seeing it restored to its original platinum glory (and that I can get the thing finished before I head home for the holidays (currently I need to figure out how I'm going to install the USB port in this thing so it can look as much like a stock keyboard as possible).

Thanks for the quick fix...I will test it out tonight. Ideally, I'd like it to just pop up the Mac's regular shutdown dialog box. Wake from sleep would be a nice side benefit as well.

Offline CyberDave

  • Posts: 36
ADB to USB keyboard converter for Teensy
« Reply #47 on: Thu, 22 December 2011, 02:44:17 »
Update: the power button now brings up the Mac's standard sleep/restart/shutdown dialog, and also wakes my MacBook Pro from sleep. The keyboard is reassembled and looks great. Now I just have to get to work on another one or two of these for myself...

hasu, this is awesome. If you're ever in Seattle, the first beer or two is on me.

Offline hasu

  • Thread Starter
  • Posts: 1467
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
ADB to USB keyboard converter for Teensy
« Reply #48 on: Thu, 22 December 2011, 21:02:39 »
Cool. Happy Christmas!
⚠ My Engrish is broken.  TMK firmware  ⌨ HHKB Alt controller

Offline blargg

  • Posts: 45
    • My github
ADB to USB keyboard converter for Teensy
« Reply #49 on: Tue, 10 January 2012, 14:58:24 »
HUGE thanks for this! I've been using an old PowerMac with ADB Extended Keyboard for the last 15 years for coding, and hate all the cheap keyboards for my newer USB-based machines. I just got a Teensy++ 2.0 and figured I'd try this as the first project. Code built without a hitch, wiring just as shown on the page, and it works perfectly. I've saved up several Apple Extended Keyboard IIs and this will make my slow transition to newer machines so much more pleasant. Thank you!