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

0 Members and 2 Guests are viewing this topic.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #100 on: Tue, 11 December 2012, 19:03:59 »
Just merged blargg's patch into the repository.  Thanks.

Offline blargg

  • Posts: 45
    • My github
Re: ADB to USB keyboard converter for Teensy
« Reply #101 on: Wed, 12 December 2012, 19:49:11 »
OK, nevermind, MATRIX_HAS_LOCKING_CAPS works properly. For some reason the OS only now apparently started doing the caps lock LED properly when I didn't have my modified .xmodmap invoked.
« Last Edit: Wed, 12 December 2012, 20:04:09 by blargg »

Offline wogdog

  • Posts: 11
Re: ADB to USB keyboard converter for Teensy
« Reply #102 on: Tue, 18 December 2012, 20:39:09 »
Quote
Connect ADB keyboard to Teensy by 3 lines(Vcc, GND, Data). By default Data line uses port F0. This converter uses AVR's internal pull-up, but it seems to be too weak, in particular when you want to use a long or coiled cable. The external pull-up resistor(1K-10K Ohm) on Data is strongly recommended

A few questions... This is my first project of this sort, so sorry if they are stupid questions...
The instruction listed above was taken from the GitHub page. In all of the pictures I see 4 lines going to the Teensy (I have Teensy 2.0). So what is the other line from/for?

Also, how do I add the pull up resistor? Does it go inline between the data line on the Teensy?

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #103 on: Tue, 18 December 2012, 22:05:15 »
Quote
Connect ADB keyboard to Teensy by 3 lines(Vcc, GND, Data). By default Data line uses port F0. This converter uses AVR's internal pull-up, but it seems to be too weak, in particular when you want to use a long or coiled cable. The external pull-up resistor(1K-10K Ohm) on Data is strongly recommended

A few questions... This is my first project of this sort, so sorry if they are stupid questions...
The instruction listed above was taken from the GitHub page. In all of the pictures I see 4 lines going to the Teensy (I have Teensy 2.0). So what is the other line from/for?
You can omit Power Switch line connected to port F1. ADB has this line to power Mac system up, but current version of the converter doesn't use this line any more. Without connecting power switch line you can still use power switch on keyboard with this converter.
After all you need to connect only three lines: Vcc, Gnd and Data.


Quote
Also, how do I add the pull up resistor? Does it go inline between the data line on the Teensy?
You should connect a resistor(any of 1k-10kOhm) between Vcc(5V) and data, not inline on data line.

Offline wogdog

  • Posts: 11
Re: ADB to USB keyboard converter for Teensy
« Reply #104 on: Tue, 18 December 2012, 22:42:23 »
Thanks hash for the help, and for figuring this out to begin with! I have a little over two weeks off starting Thursday and can't wait to get started on this! Thanks again!

P.s. once I get it done, I will post a status update here for you all.

Offline SmallFry

  • ** Moderator Emeritus
  • Posts: 3887
  • Location: Wisconsin, USA
  • Leaving 6/15; returning 6/22 or so.
Re: ADB to USB keyboard converter for Teensy
« Reply #105 on: Tue, 18 December 2012, 23:07:16 »
His name is Hasu;)

Offline wogdog

  • Posts: 11
Re: ADB to USB keyboard converter for Teensy
« Reply #106 on: Tue, 18 December 2012, 23:41:42 »
Stupid iOS autocorrect.... TMSAISTI

Offline wogdog

  • Posts: 11
Re: ADB to USB keyboard converter for Teensy
« Reply #107 on: Fri, 21 December 2012, 14:57:26 »
If I understand correctly, I am supposed to run the make command from within the adb_usb directory. This directory contains config.h, keymap.c, led.c, Makefile, matrix.c, and README.md. When I do that though, I get the following:

The system cannot find the path specified.
The system cannot find the path specified.
ECHO is off.
-------- begin --------
Process_begin: CreateProcess(NULL, avr-gcc --version, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [gccversion] Error 2

I am smart enough to figure out there is an error... But not smart enough to figure out what the error is. Any ideas?

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #108 on: Fri, 21 December 2012, 20:05:18 »
It looks like your system could not find path of your toolchain :)

What is you system? Windows, Mac or else?
Which toolchain are you using? WinAVR or Atmel Toolchan?
Did you add directory including binaries to environment variable PATH(Path)?

Offline wogdog

  • Posts: 11
Re: ADB to USB keyboard converter for Teensy
« Reply #109 on: Sat, 22 December 2012, 11:10:00 »
You sir are a scholar and a gentleman. Not wanting to do things the easy way, I went and tried to use just gcc make. It evidently didn't have everything I needed. I then got WinAVR And that worked perfectly. Thank you!

Now... I am able to get input from the keyboard, but it seems a little slow, meaning when I type words with a repeating letter, it only registers one of them. Any tips on getting that changed?

I do have some more work to soon my wiring. For now it has a USB connected through the hole that the ADB connected used to be located at, directly to the Teeensy USB port. I had planned on putting a USB-B port where the ADB port was, but need to redo my first wiring attempt.

Another question... Do I need to keep the original controller in its connector? That seems like a good place to hot-glue my Teensy, but it is too tall with that chip in there.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #110 on: Sun, 23 December 2012, 07:11:07 »
Current polling rate seems to be too slow to catch ADB signal in case of high speed typing. I'll work on this problem later.

From first post.
Quote
WARNING
ADB-USB converter misses keystrokes
Currently my ADB converter has this unsolved issue: https://github.com/tmk/tmk_keyboard/issues/14
One of work around is using old repository commit:33d58c2b5647623d2b.

AppleIIGS keyboard and M0116 suffer severely from this issue, while Extended keyboards M0115 and M3501 doesn't seem like so bad. Though it may depend on your type speed. In my speed 50-60wpm with Extended keyboard I don't feel big problem.

Offline wogdog

  • Posts: 11
Re: ADB to USB keyboard converter for Teensy
« Reply #111 on: Sun, 23 December 2012, 09:22:46 »
Once again, I am an idiot. I can't tell you how many times I read through this thead. Didn't make the connection. I will try the listed commit. Thanks again for the help and patiently answering the numerous stuid questions.

I did get the keys and board cleaned up. Looks nice :)
Just need to retr0bright the space bar, and it should be good. 

Offline Snipeye

  • Posts: 20
Re: ADB to USB keyboard converter for Teensy
« Reply #112 on: Tue, 25 December 2012, 23:40:05 »
I got an Apple Extended Keyboard (I) for christmas - I've been working all day to clean it - alcohol q-tips down under the keys, ran the keys themselves through the dishwasher (worked wonders) and I struggled valiantly with getting a good enough version of avr-gcc to compile the teensy hex - finally FINALLY got that just barely - and now I'm having a couple issues with the keymap.  I'm trying to map it so there's a right "command" key, but that doesn't show up in the keymap file, and when I try to add it in, the make command gets mad at me for trying to pass 105 arguments into the keymap macro instead of the requisite 104.  Help?\\


EDIT:  I messed around with the code a little more, and it's ALMOST working right - I still can't get it to register differing commands for left and right command (apple) and both left and right control are mapped to left control only, and my right alt/option isn't working at all.  Are there options I need to change around to get those working right?  I'll post my current keymap.h, and I also had to change a single line of code in my keycode.h to get right-command mapped to command rather than control.  here's the line I changed there:

Code: [Select]
#define IS_MOD(code)             (KC_LCTRL     <= (code) && (code) <= KC_RCTRL
I changed that "KC_RGUI" to the "RCTRL" you see at the end of the line now.  Wouldn't compile if I just deleted the line.

As for my keymap.h,:

Code: [Select]
/*
Copyright 2011 Jun Wako <wakojun@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * Keymap for ADB keyboard
 */
#include <stdint.h>
#include <stdbool.h>
#include <avr/pgmspace.h>
#include "usb_keyboard.h"
#include "keycode.h"
#include "print.h"
#include "debug.h"
#include "util.h"
#include "keymap.h"


#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)]))

// Convert physical keyboard layout to matrix array.
// This is a macro to define keymap easily in keyboard layout form.
/* Apple Extended Keyboard */
#define KEYMAP( \
    K35,  K7A,K78,K63,K76, K60,K61,K62,K64, K65,K6D,K67,K6F, K69,K6B,K71,              K7F, \
    K32,K12,K13,K14,K15,K17,K16,K1A,K1C,K19,K1D,K1B,K18,K33, K72,K73,K74,  K47,K51,K4B,K43, \
    K30,K0C,K0D,K0E,K0F,K11,K10,K20,K22,K1F,K23,K21,K1E,K2A, K75,K77,K79,  K59,K5B,K5C,K4E, \
    K39,K00,K01,K02,K03,K05,K04,K26,K28,K25,K29,K27,    K24,               K56,K57,K58,K45, \
    K38,K06,K07,K08,K09,K0B,K2D,K2E,K2B,K2F,K2C,        K7B,     K3E,      K53,K54,K55,     \
    K36,K3A,K37,        K31,                K80,K7C,K7D,     K3B,K3D,K3C,  K52,    K41,K4C  \
) { \
    { KC_##K00, KC_##K01, KC_##K02, KC_##K03, KC_##K04, KC_##K05, KC_##K06, KC_##K07 }, \
    { KC_##K08, KC_##K09, KC_NO,    KC_##K0B, KC_##K0C, KC_##K0D, KC_##K0E, KC_##K0F }, \
    { KC_##K10, KC_##K11, KC_##K12, KC_##K13, KC_##K14, KC_##K15, KC_##K16, KC_##K17 }, \
    { KC_##K18, KC_##K19, KC_##K1A, KC_##K1B, KC_##K1C, KC_##K1D, KC_##K1E, KC_##K1F }, \
    { KC_##K20, KC_##K21, KC_##K22, KC_##K23, KC_##K24, KC_##K25, KC_##K26, KC_##K27 }, \
    { KC_##K28, KC_##K29, KC_##K2A, KC_##K2B, KC_##K2C, KC_##K2D, KC_##K2E, KC_##K2F }, \
    { KC_##K30, KC_##K31, KC_##K32, KC_##K33, KC_NO,    KC_##K35, KC_##K36, KC_##K37 }, \
    { KC_##K38, KC_##K39, KC_##K3A, KC_##K3B, KC_##K3C, KC_##K3D, KC_##K3E, KC_NO    }, \
    { KC_NO,    KC_##K41, KC_NO,    KC_##K43, KC_NO,    KC_##K45, KC_NO,    KC_##K47 }, \
    { KC_NO,    KC_NO,    KC_NO,    KC_##K4B, KC_##K4C, KC_NO,    KC_##K4E, KC_NO    }, \
    { KC_NO,    KC_##K51, KC_##K52, KC_##K53, KC_##K54, KC_##K55, KC_##K56, KC_##K57 }, \
    { KC_##K58, KC_##K59, KC_NO,    KC_##K5B, KC_##K5C, KC_NO,    KC_NO,    KC_NO    }, \
    { KC_##K60, KC_##K61, KC_##K62, KC_##K63, KC_##K64, KC_##K65, KC_NO,    KC_##K67 }, \
    { KC_NO,    KC_##K69, KC_NO,    KC_##K6B, KC_NO,    KC_##K6D, KC_NO,    KC_##K6F }, \
    { KC_NO,    KC_##K71, KC_##K72, KC_##K73, KC_##K74, KC_##K75, KC_##K76, KC_##K77 }, \
    { KC_##K78, KC_##K79, KC_##K7A, KC_##K7B, KC_##K7C, KC_##K7D, KC_##K80, KC_##K7F }  \
}


// Assign Fn key(0-7) to a layer to which switch with the Fn key pressed.
static const uint8_t PROGMEM fn_layer[] = {
    0,              // Fn0
    0,              // Fn1
    0,              // Fn2
    0,              // Fn3
    0,              // Fn4
    0,              // Fn5
    0,              // Fn6
    0               // Fn7
};

// Assign Fn key(0-7) to a keycode sent when release Fn key without use of the layer.
// See layer.c for details.
static const uint8_t PROGMEM fn_keycode[] = {
    KC_NO,          // Fn0
    KC_NO,          // Fn1
    KC_NO,          // Fn2
    KC_NO,          // Fn3
    KC_NO,          // Fn4
    KC_NO,          // Fn5
    KC_NO,          // Fn6
    KC_NO           // Fn7
};

static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    /* Default Layer: plain keymap
     * ,---.   ,---------------. ,---------------. ,---------------. ,-----------.             ,---.
     * |Esc|   |F1 |F2 |F3 |F4 | |F5 |F6 |F7 |F8 | |F9 |F10|F11|F12| |PrS|ScL|Pau|             |Pwr|
     * `---'   `---------------' `---------------' `---------------' `-----------'             `---'
     * ,-----------------------------------------------------------. ,-----------. ,---------------.
     * |  `|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|Backspa| |Ins|Hom|PgU| |NmL|  =|  /|  *|
     * |-----------------------------------------------------------| |-----------| |---------------|
     * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|    \| |Del|End|PgD| |  7|  8|  9|  -|
     * |-----------------------------------------------------------| `-----------' |---------------|
     * |CapsLo|  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|Return  |               |  4|  5|  6|  +|
     * |-----------------------------------------------------------|     ,---.     |---------------|
     * |Shift   |  Z|  X|  C|  V|  B|  N|  M|  ,|  ,|  /|Shift     |     |Up |     |  1|  2|  3|   |
     * |-----------------------------------------------------------| ,-----------. |-----------|Ent|
     * |Ctrl |Gui |Alt |         Space           |     |    |      | |Lef|Dow|Rig| |      0|  .|   |
     * `-----------------------------------------------------------' `-----------' `---------------'
     */
    KEYMAP(
    ESC, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12,           PSCR,SLCK,PAUS,                   PWR,
    GRV, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC,     INS, HOME,PGUP,    NLCK,EQL, PSLS,PAST,
    TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSLS,     DEL, END, PGDN,    P7,  P8,  P9,  PMNS,
    CAPS,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,     ENT,                         P4,  P5,  P6,  PPLS,
    LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,          RSFT,          UP,           P1,  P2,  P3,
    LCTL,LALT,LGUI,          SPC,                          RALT,RGUI,RCTL,     LEFT,DOWN,RGHT,    P0,       PDOT,PENT
    ),
};


uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col)
{
    return KEYCODE(layer, row, col);
}

uint8_t keymap_fn_layer(uint8_t index)
{
    return pgm_read_byte(&fn_layer[index]);
}

uint8_t keymap_fn_keycode(uint8_t index)
{
    return pgm_read_byte(&fn_keycode[index]);
}

So I've not changed much around.  Am I clear on what I need help with and what's not working?  I feel like my post is a bit jumbled.  Thanks!
« Last Edit: Wed, 26 December 2012, 00:19:03 by Snipeye »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #113 on: Wed, 26 December 2012, 03:31:35 »
ADB has no distinct keycode for right command key, so you can't map different key to it.
Right command key always behave as same as left one.

Offline Snipeye

  • Posts: 20
Re: ADB to USB keyboard converter for Teensy
« Reply #114 on: Wed, 26 December 2012, 12:16:54 »
I've been needing the right control/Alt/etc. keys for Linux programs which give these special meanings. I read in the ADB tech note (untold story) that the keyboard's handler ID can be changed from 2 to 3, causing it give distinct codes for left and right modifiers. This would be a really useful fix.

...well, that went smoothly on the first try. I just implemented the above on the latest source. I've atteched the patch (I'm not familiar enough with git to submit it myself, sorry). Currently it only sets the keyboard device handler to 3 on USB init, so if you unplug the ADB and plug it back into the keyboard, right modifiers won't be differentiated until you unplug and plug ADB back in. I broke out an adb_host_listen() function since it has the same guts as used by the led-setting function and my device handler setting in matrix_init().

Note that even with this, the Extended Keyboard II (and maybe all the others) still don't differentiate between left and right Command (Alt), so that both are reported as the left one. :(


That post lead me to believe that ADB, if the handler ID was 3, could differentiate between left and right command/control/alt.  Of course, I don't know if that's the case with the hardware on the AEK, care to enlighten?

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #115 on: Wed, 26 December 2012, 12:34:58 »
You can distinguish between right and left of shift/control/option(alt) with ID3 method. But not command(apple) key.
Both AEK1 and AEK2 doesn't have distinct code for right command key. I don't know why.
I'm not 100% sure, but I believe it doesn't exist a way to distinguish right command key on ADB keyboard.

Offline Snipeye

  • Posts: 20
Re: ADB to USB keyboard converter for Teensy
« Reply #116 on: Wed, 26 December 2012, 12:50:03 »
Alright, well that clears things up - thank you very much!  Could you help me get the code set up for distinguishing between right and left control and alt, at least, and then command can both be left?  The keymap default included in the adb_usb folder doesn't appear to have any sort of command key on the right.... and I don't know if I need to change anything to set up the handler as ID 3 instead of default.  Thanks!

Offline tufty

  • Posts: 347
  • Location: French Alps
Re: ADB to USB keyboard converter for Teensy
« Reply #117 on: Wed, 26 December 2012, 13:25:17 »
Well, you'll need to send a "Listen Register 3" to the keyboard telling it to go to handler 3, at which point you get  separate left and right modifiers.  They are as follows:

Left Control : 0x36
Command : 0x37
Left Shift: 0x38
Left Option : 0x3A
Right Shift : 0x7B
Right Option : 0x7C
Right Control : 0x7D

The message you need to send is, if I've got this right:

0x2B 0x62 0x03

In theory you should do this as part of bus deambiguation, but as we're talking about a specific situation with only one device at its default address, we can explicitly code in the address (the 2s in the first two bytes)

You'll then need to modify keymap.c in order to graft in the keycodes above and what you want to map them to.

Offline concept10

  • Posts: 1
Re: ADB to USB keyboard converter for Teensy
« Reply #118 on: Wed, 26 December 2012, 14:43:25 »
Hello All,

I recently found a stash and bought 2 of the Apple Extended Keyboards (Model 2) and instead of purchasing the Griffin iMate and running into this thread, I decided to try and adapt this project to an Arduino UNO board (ATmega328p) that I haven't found a purpose for yet.

I have attempted to compile the project with no luck so far.  Anyone have any suggestions or advice on what I need to change?  My current thought is to loose the pjrc usb library and use the lufa or v-usb library instead.  At this point, I am not sure of the proper modifications I need to make.  Any help welcome.

Thanks.

Offline Snipeye

  • Posts: 20
Re: ADB to USB keyboard converter for Teensy
« Reply #119 on: Wed, 26 December 2012, 15:46:56 »
Well, you'll need to send a "Listen Register 3" to the keyboard telling it to go to handler 3, at which point you get  separate left and right modifiers.  They are as follows:

Left Control : 0x36
Command : 0x37
Left Shift: 0x38
Left Option : 0x3A
Right Shift : 0x7B
Right Option : 0x7C
Right Control : 0x7D

The message you need to send is, if I've got this right:

0x2B 0x62 0x03

In theory you should do this as part of bus deambiguation, but as we're talking about a specific situation with only one device at its default address, we can explicitly code in the address (the 2s in the first two bytes)

You'll then need to modify keymap.c in order to graft in the keycodes above and what you want to map them to.

... K.  I'm not that advanced.  Haha, I appreciate the effort, mind dumbing it down for me a little bit?  What/where do I need to change?  And as for the separate keys - I've grafted them in, I believe correctly, but I don't know how to apply the message you said I needed to send in order to initiate with ID of 3....

In adb.c, I've found something like what you're talking about - I've found a command that's already there, "adb_host_listen(0x2B,0x02,0x03)" and the comments say that's telling the keyboard to listen on register 3.  Then later (in adb_host_kbd_recv(void)) a byte (0x2c) is sent, telling the keyboard to talk on register 0.  Changing that to 0x2f to tell it to talk on register 3 screwed things up, so I changed that back.

Basically, it looks like it's already being told to listen on register 3, and it's still not differentiating between left or right control, alt, or shift.  Hmm... am I doing something wrong?

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
Re: ADB to USB keyboard converter for Teensy
« Reply #120 on: Wed, 26 December 2012, 16:11:14 »
I'm just guessing, but try changing:
Code: [Select]
adb_host_listen(0x2B,0x02,0x03)
to:
Code: [Select]
adb_host_listen(0x2B,0x62,0x03)
BTW, 'talk' and 'listen' are just Woz-speak for 'read' and 'write', so sending e.g. a 'listen on register 3' command means that the keyboard will write the next 2 bytes sent to it into register 3.

Offline Snipeye

  • Posts: 20
Re: ADB to USB keyboard converter for Teensy
« Reply #121 on: Wed, 26 December 2012, 16:42:37 »
That doesn't seem to work - tried it, no difference.  But the fact that there's no difference when I send a binary "1100010" rather than a "10" - no error or ANYTHING - means that perhaps the command isn't doing anything at all.  I'm pretty sure the '10' is what it's looking for, as 11 is talk.  Reading some more on how it's initialized right now, but doubt it'll help much.  Any other suggestions?


OK, I read the ADB spec more and looked at the adb.c protocol some more, and found some dependencies - primarily in the "adb_host_listen" and "attention" commands.  The protocol is default set up to send "0x2B,0x02,0x03" through adb_host_listen on initiation.  However, the adb protocol states the first 4 bits of the upper byte are reserved - should be "0000" - then the next 4 bits are the device address - a keyboard defaults to "2", which is (correct me if I'm wrong) "0010".  The next two, 4-bit chunks should be the command (listen, "0010") and the register, ("0011").  So, the "0x2B" should in fact be 0x02, right?  I tried changing it, and it's had no effect thus far.

In the "adb_host_listen" function, it calls "attention()" - the adb spec for that says an attention signal is 776-824 us low, and after the attention signal should come a 70us sync signal, high.  The attention() function was delaying for 700us, then placing a 1-bit (35us low, 65 high) - effectively providing 735us low, which is not a valid length for the attention signal, then 65us high, which is probably long enough.  I changed the attention function to bring the data line low for 800us, then high for 70, and then whatever functions take place after that should work properly.  I have seen no change in effect on the keyboard functionality.

Regardless, I don't think the attention signal was getting through, as the adb_host_listen command that occurs in the adb_host_init doesn't appear to DO anything -- commenting it out has no effect on the functionality of the keyboard whatsoever.  However, I'm unable to make it work - my modified attention() function doesn't appear to work any better.  Does anybody have the right/left control/alt/shift differentiated on an AEKv1?

Please, keep throwing suggestions my way.  I'm learning and becoming a little more capable.  :P
« Last Edit: Wed, 26 December 2012, 17:31:53 by Snipeye »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #122 on: Wed, 26 December 2012, 20:19:51 »
Snipeye,
Handler ID 3 is enabled by default now with patch from blargg. https://github.com/tmk/tmk_keyboard/commit/cf1eb8fbc6789776d3b3457dd5cf4ed84815e8b3
And keymap.c already has distinct keycodes for right and left shift/control/gui(apple or windows key). With default keymap Alt is mapped to command key.
What is your problem then?

Concept10,
While dealing with V-USB to handle ADB signal is very difficult, at least I tried this and failed to make it work. V-USB consumes quite a bit of time to handle USB.
Instead, I think you can load LUFA stack into ATMega16u2 and handle ADB with ATMega328p, then let two controllers communicate with UART line.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #123 on: Wed, 26 December 2012, 20:43:06 »
Which spec are you referring? ADB spec has some ancient source but each and all doesn't explain protocol enough :)
Yes, my code is not completely conforming with spec to keep code simple for reference purpose.

I mainly use these as spec.
ADB - The Untold Story: Space Aliens Ate My Mouse
    http://developer.apple.com/legacy/mac/library/#technotes/hw/hw_01.html
Apple IIgs Hardware Reference Second Edition [p80(Chapter6 p121)]
    ftp://ftp.apple.asimov.net/pub/apple_II/documentation/Apple%20IIgs%20Hardware%20Reference.pdf



OK, I read the ADB spec more and looked at the adb.c protocol some more, and found some dependencies - primarily in the "adb_host_listen" and "attention" commands.  The protocol is default set up to send "0x2B,0x02,0x03" through adb_host_listen on initiation.  However, the adb protocol states the first 4 bits of the upper byte are reserved - should be "0000" - then the next 4 bits are the device address - a keyboard defaults to "2", which is (correct me if I'm wrong) "0010".  The next two, 4-bit chunks should be the command (listen, "0010") and the register, ("0011").  So, the "0x2B" should in fact be 0x02, right?  I tried changing it, and it's had no effect thus far.

In the "adb_host_listen" function, it calls "attention()" - the adb spec for that says an attention signal is 776-824 us low, and after the attention signal should come a 70us sync signal, high.  The attention() function was delaying for 700us, then placing a 1-bit (35us low, 65 high) - effectively providing 735us low, which is not a valid length for the attention signal, then 65us high, which is probably long enough.  I changed the attention function to bring the data line low for 800us, then high for 70, and then whatever functions take place after that should work properly.  I have seen no change in effect on the keyboard functionality.

Offline Snipeye

  • Posts: 20
Re: ADB to USB keyboard converter for Teensy
« Reply #124 on: Wed, 26 December 2012, 21:32:02 »
I was referring to this:

http://www.eetasia.com/ARTICLES/2000JUN/2000JUN02_CT_AN8.PDF

But upon closer inspection, it appears that my right and left control/alt/shift ARE, in fact, being differentiated.  I'm in OSX, was going to the "keyboard viewer" to determine what keys were being pressed, and it was showing both left and right control/alt/shift as only 1 - but that is not, in fact, the case.  Any suggestions for applications to determine what keys are being pressed with a little more accuracy?  It's working perfectly and is ready to go for my project (if I remember I'll post a link when I'm finished, but I'm installing a USB hub and giving it a nice paintjob.  Should be pretty cool.)  Thank you all for all the help - wouldn't have been possible without you guys.  Perhaps another dumb question - though all my keycaps are off right now (cleaning and painting) so I can't see the names of the switches, but the only LED I can get to turn on is for caps lock.  What key combos on the AEKv1 should activate the other LEDs?  Bear in mind I'm in OSX.  Thanks!

Offline tufty

  • Posts: 347
  • Location: French Alps
Re: ADB to USB keyboard converter for Teensy
« Reply #125 on: Fri, 28 December 2012, 01:25:05 »
IIRC, under OS9, scroll lock was F14, and numlock was shift-clear

Offline wogdog

  • Posts: 11
Re: ADB to USB keyboard converter for Teensy
« Reply #126 on: Mon, 07 January 2013, 09:58:32 »
Current polling rate seems to be too slow to catch ADB signal in case of high speed typing. I'll work on this problem later.

From first post.
Quote
WARNING
ADB-USB converter misses keystrokes
Currently my ADB converter has this unsolved issue: https://github.com/tmk/tmk_keyboard/issues/14
One of work around is using old repository commit:33d58c2b5647623d2b.

AppleIIGS keyboard and M0116 suffer severely from this issue, while Extended keyboards M0115 and M3501 doesn't seem like so bad. Though it may depend on your type speed. In my speed 50-60wpm with Extended keyboard I don't feel big problem.

How would I go about using that commit? I cant seem to find it up on Git.  I also scanned through the code and did not see a place to modify the polling rate

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #127 on: Mon, 07 January 2013, 10:17:49 »
Here: https://github.com/tmk/tmk_keyboard/tree/33d58c2b5647623d2b07a210ef97a27920e5563e
No scan rate config option. Somewhere in codes takes too long :) you have to tune code.

Offline wogdog

  • Posts: 11
Re: ADB to USB keyboard converter for Teensy
« Reply #128 on: Mon, 07 January 2013, 10:41:29 »
Works perfectly now!! Thanks!! Both for your patience and knowledge. This forum is great! I have learned a lot already from the short time I have been here, and look forward to learning more. I have found some additional mechanical keyboards around the building that I have been able to 'acquire'. Now I just need to get them to USB also, and I am good to go.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #129 on: Tue, 09 April 2013, 01:08:36 »
Fixed missing key stoke problem finally. https://github.com/tmk/tmk_keyboard/issues/14

Offline ryemac3

  • Posts: 1
Re: ADB to USB keyboard converter for Teensy
« Reply #130 on: Wed, 10 April 2013, 12:34:14 »
I have a few bare bones Arduino boards that I made with some Atmega328s.



They would be perfect for this project. Does anyone know how to port this code over to Arduino?
« Last Edit: Wed, 10 April 2013, 12:35:48 by ryemac3 »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #131 on: Wed, 10 April 2013, 17:25:28 »
You need V-USB to support USB  on ATmega328 but V-USB and my ADB code are incompatible unfortunately. My ADB code use busy wait polling method to implement the protocol and V-USB interrupts and screw up ADB code with up to 50us block, IIRC. My code needs hardware engine on USB AVR like ATmega32U4 or AT90USB1286 instead of software V-USB at the moment.

To port this converter into ATmega328 I think you have to rewrite ADB code with timer interrupt or other method at least, but I'm not sure.

Offline tufty

  • Posts: 347
  • Location: French Alps
Re: ADB to USB keyboard converter for Teensy
« Reply #132 on: Thu, 11 April 2013, 00:35:43 »
Fixed missing key stoke problem finally. https://github.com/tmk/tmk_keyboard/issues/14

Hey hasu.

That's fantastic, finally makes my M0116 work properly without missing keys.  I just put a pull request up - feel free to merge my M0116 layout into your master.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #133 on: Fri, 12 April 2013, 00:11:16 »
tufty,
merged your support for eject key and M0116 layout. Thanks.

Offline oryhara

  • Posts: 1
Re: ADB to USB keyboard converter for Teensy
« Reply #134 on: Thu, 06 June 2013, 20:32:01 »
What would one need to do to make this work with teensy 3.0?

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #135 on: Thu, 06 June 2013, 21:44:05 »
Physically, some components for 5-3.3 voltage shifter.
To handle ADB 5V signal Teensy 3.0 will need this because its I/O ports are not 5V tolerant, I think.

And knowledge of Cortex architecture and C language. That's all.

Offline oxalyn

  • Posts: 5
Re: ADB to USB keyboard converter for Teensy
« Reply #136 on: Tue, 11 June 2013, 23:59:21 »
This is probably my inexperience, but:

Is anybody compiling this on OS X 10.7.5 using the CrossPack avr-gcc package? No matter which version of CrossPack I install, I get a number of compiler errors when compiling:

...

Assembling: ../../common/xprintf.S
avr-gcc -c -mmcu=atmega32u4        -x assembler-with-cpp -DF_CPU=16000000 -DBOOTLOADER_SIZE=4096 -DPROTOCOL_PJRC -DNO_PRINT -DNO_DEBUG -Wa,-adhlns=obj_adb_usb/common/xprintf.lst,-gstabs,--listing-cont-lines=100 -I. -I../.. -I../../protocol/pjrc -I../../protocol -I../../common -include config.h  ../../common/xprintf.S -o obj_adb_usb/common/xprintf.o
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h: Assembler messages:
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:121: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:122: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:123: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:124: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:125: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:126: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:128: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:129: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:142: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:147: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:159: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:164: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:169: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:174: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:179: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:184: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:192: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:199: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:213: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:218: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:223: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:228: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:233: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:238: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:246: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:253: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:273: Error: unknown opcode `typedef'
/opt/local/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h:278: Error: unknown opcode `typedef'
../../protocol/adb.h:56: Error: unknown opcode `void'
../../protocol/adb.h:57: Error: unknown opcode `_bool'
../../protocol/adb.h:58: Error: unknown opcode `uint16_t'
../../protocol/adb.h:59: Error: unknown opcode `void'
../../protocol/adb.h:60: Error: unknown opcode `void'
../../common/matrix.h:26: Error: unknown opcode `typedef'
../../common/matrix.h:39: Error: unknown opcode `uint8_t'
../../common/matrix.h:41: Error: unknown opcode `uint8_t'
../../common/matrix.h:43: Error: unknown opcode `void'
../../common/matrix.h:45: Error: unknown opcode `uint8_t'
../../common/matrix.h:47: Error: unknown opcode `_bool'
../../common/matrix.h:49: Error: unknown opcode `_bool'
../../common/matrix.h:51: Error: unknown opcode `matrix_row'
../../common/matrix.h:53: Error: unknown opcode `void'
make: *** [obj_adb_usb/common/xprintf.o] Error 1

I appreciate any help provided.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #137 on: Wed, 12 June 2013, 01:39:59 »
try this patch.

Code: [Select]
/* key combination for command */
+#ifndef __ASSEMBLER__
 #include "adb.h"
 #include "matrix.h"
 #define IS_COMMAND() ( \
     matrix_is_on(MATRIX_ROW(ADB_POWER), MATRIX_COL(ADB_POWER)) \
 )
+#endif

Offline oxalyn

  • Posts: 5
Re: ADB to USB keyboard converter for Teensy
« Reply #138 on: Wed, 12 June 2013, 10:30:11 »
Thank you, that did the trick!

Offline oxalyn

  • Posts: 5
Re: ADB to USB keyboard converter for Teensy
« Reply #139 on: Thu, 13 June 2013, 23:23:18 »
OK, I got everything working and wired up. Of note, the default 'keymap.c' file has the Option and Command keys swapped. I fiddled with it until it worked:

Code: [Select]
static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    KEYMAP_EXTENDED_US(
    ESC, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12,           PSCR,SLCK,PAUS,                   PWR,
    GRV, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSPC,     INS, HOME,PGUP,    NLCK,PEQL,PSLS,PAST,
    TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSLS,     DEL, END, PGDN,    P7,  P8,  P9,  PMNS,
    LCAP,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,     ENT,                         P4,  P5,  P6,  PPLS,
    LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,          RSFT,          UP,           P1,  P2,  P3,
    LCTL,LALT,LGUI,          SPC,                               RALT,RCTL,     LEFT,DOWN,RGHT,    P0,       PDOT,PENT
    ),
};

On the last line, LALT and LGUI are swapped in the default file, and the RALT is a RGUI in the default file.

Offline oxalyn

  • Posts: 5
Re: ADB to USB keyboard converter for Teensy
« Reply #140 on: Fri, 14 June 2013, 00:19:07 »
Also, no matter what I do, I can't get the Power key to work. I wonder if it's due to the patch you gave me above, which may not be defining IF_COMMAND()?

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #141 on: Fri, 14 June 2013, 00:53:01 »
I think it is not due to that patch.

Power key is used as 'Magic key' to run Magic commands. IS_COMMAND() macro defines 'Magic key' and which cannot be used as normal key for typing.
To use Power key as normal key define IS_COMMAND() with other key or comment out COMMAND_ENABLE in Makfile.
https://github.com/tmk/tmk_keyboard#magic-comannds

Offline oxalyn

  • Posts: 5
Re: ADB to USB keyboard converter for Teensy
« Reply #142 on: Sat, 15 June 2013, 00:28:27 »
Hmm. I compiled with both COMMAND_ENABLE = yes and #COMMAND_ENABLE = yes, and got identical results: the system acts as though nothing had been pressed when I hit the power button. I even got the same results with a different keyboard.

Here is the relevant section of MAKEFILE:

Code: [Select]
# Build Options
#   comment out to disable the options.
#
#BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
#MOUSEKEY_ENABLE = yes # Mouse keys(+5000)
#EXTRAKEY_ENABLE = yes # Audio control and System control(+600)
#CONSOLE_ENABLE = yes    # Console for debug
#COMMAND_ENABLE = yes    # Commands for debug and configuration
#SLEEP_LED_ENABLE = yes  # Breathing sleep LED during USB suspend
#NKRO_ENABLE = yes # USB Nkey Rollover(+500)

I did spend all day using this system, and other than the power key it performs flawlessly. I'm a speed typist, and it keeps up quite well.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter for Teensy
« Reply #143 on: Sat, 15 June 2013, 05:42:09 »
Hmm. I compiled with both COMMAND_ENABLE = yes and #COMMAND_ENABLE = yes, and got identical results: the system acts as though nothing had been pressed when I hit the power button. I even got the same results with a different keyboard.

Hmm, 'make -f ... clean' may be needed before 'make -f ...' when you change config.h. Try 'make clean'.
If this makes no difference let me know again. I'll look into my code more.

EDIT: Or maybe your system doesn't recognize 'System Power' keycode(PWR). you can try another keycode.
For example use 'A' instead of 'PWR' in your keymap, you will see 'a' when pressing Power key.

Quote
I did spend all day using this system, and other than the power key it performs flawlessly. I'm a speed typist, and it keeps up quite well.

Great. It is exactly what I want to hear!
Post here if you come across any problem.
« Last Edit: Sat, 15 June 2013, 05:55:12 by hasu »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter
« Reply #144 on: Tue, 18 June 2013, 19:24:37 »
My new DIY ADB converter! I did this instead of buying extra Teensy's from PJRC.



http://deskthority.net/workshop-f7/teensy-2-0-alternatives-atmega32u4-t4253-30.html#p112185
« Last Edit: Tue, 18 June 2013, 19:26:18 by hasu »

Offline TheFlyingRaccoon

  • HHKB Pro
  • * Maker
  • Posts: 666
  • Location: Texas
  • Cable maker and future engineer
Re: ADB to USB keyboard converter
« Reply #145 on: Tue, 18 June 2013, 20:59:07 »
My new DIY ADB converter! I did this instead of buying extra Teensy's from PJRC.

Show Image


http://deskthority.net/workshop-f7/teensy-2-0-alternatives-atmega32u4-t4253-30.html#p112185

This looks awesome! What was the total cost of materials?
HHKB Pro 2   SmallFry Keyboard

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter
« Reply #146 on: Wed, 19 June 2013, 02:22:05 »
Around $10. Not so cheap.

PCB $1.5
MCU $5
Connector $2
Xtal $0.5
R,C,etc $1.5

Offline Captain Hammer

  • Posts: 1
Re: ADB to USB keyboard converter
« Reply #147 on: Mon, 15 July 2013, 01:22:45 »
I was having the same problem as oxalyn (10.8 with CrossPack), but after trying Hasu's suggestion, I now get these errors:

In file included from <command-line>:0:0:
./config.h:62:1: error: expected identifier or '(' before '+' token
./config.h:62:1: error: stray '#' in program
In file included from /usr/local/CrossPack-AVR-20130212/lib/gcc/avr/4.6.2/include/stdint.h:3:0,
                 from ../../protocol/adb.h:41,
                 from ./config.h:63,
                 from <command-line>:0:
/usr/local/CrossPack-AVR-20130212/lib/gcc/avr/4.6.2/../../../../avr/include/stdint.h:159:1: error: unknown type name 'int8_t'
/usr/local/CrossPack-AVR-20130212/lib/gcc/avr/4.6.2/../../../../avr/include/stdint.h:213:1: error: unknown type name 'int8_t'
In file included from <command-line>:0:0:
./config.h:68:1: error: expected identifier or '(' before '+' token
./config.h:68:1: error: stray '#' in program
make: *** [obj_adb_usb/keymap.o] Error 1

These problems also appeared with attempting to compile on Ubuntu with gcc-avr and libc-avr.
Any help would be greatly appreciated.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: ADB to USB keyboard converter
« Reply #148 on: Mon, 15 July 2013, 09:28:46 »
Hmm, this patch works for me.
http://geekhack.org/index.php?topic=14290.msg926590#msg926590

It seems your failed to patch. You copied the line from the patch including '+'? You don't need '+'.
Quote
./config.h:68:1: error: expected identifier or '(' before '+' token

Actually the source should look like this. Preceding '+' is not needed to copy.
Quote
/* key combination for command */
#ifndef __ASSEMBLER__
#include "adb.h"
#include "matrix.h"
#define IS_COMMAND() ( \
    matrix_is_on(MATRIX_ROW(ADB_POWER), MATRIX_COL(ADB_POWER)) \
)
#endif

Offline arfink

  • Posts: 66
Re: ADB to USB keyboard converter
« Reply #149 on: Sun, 29 September 2013, 16:16:18 »
I'm going to try this out on my IIgs keyboard. This looks very promising! I'll report back how it goes when I'm done.