geekhack

geekhack Projects => Making Stuff Together! => Topic started by: Smasher816 on Fri, 11 April 2014, 23:32:40

Title: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Fri, 11 April 2014, 23:32:40
Intro:

Hey it's Smasher816. I found Geekhack earlier this year after researching mechanical keyboards and quickly "fell down the rabbit hole" and purchased a HHKB (Type-S). After a lot of reading and talking with Hasu I have successfully replaced my HHKB controller with a Teensy allowing me to use custom firmware (such as TMK) to bring extra features (http://geekhack.org/index.php?topic=57008.msg1292479#msg1292479) to this wonderful keyboard. If your interested in this project then keep reading on, if your not then feel free to pass by - I won't be offended.

Before you begin there are a few things you should know about the DIY mod.

Because the HHKB has a fairly modular design you can actually detach the original daughter controller board and connect in your own. You simply build the new controller on its own and plug it in once completed. You can then swap between the stock and custom one as much as you want. This makes it a fairly low risk mod. The only problem I could foresee is soldering the 5V power pin to some data pin which could damage the electronics.

By using the TMK firmware you can gain many great features including multiple layers, mouse keys, and dual role keys. What's even better is that everything you do is saved on the keyboard. Unlike software solutions which only apply to one computer this hardware mod will bring your changes to any computer you use it with. With the HHKB being such a small and light keyboard it makes a great travel companion for the mobile keyboard geek.

For all the perks there are some down sides. You will lose the USB hub on the back (unless you find some way to throw your own one inside). You will also lose the DIP switches (but that isn't a big deal since you can make up for it in your own layouts).

Without further adieu lets begin. Edit: As I write this I have noticed that it is turning out much longer than I expected it to. I hope I didn't ramble on too much.


Hardware:

DISCLAIMER: I am a software guy not a hardware guy. Everything that follows is my own personal thoughts which may very well be flawed.

----- Materials -----
 - Teensy 2.0 (http://www.pjrc.com/store/teensy.html)
 - HHKB header (http://www.digikey.com/product-detail/en/B13B-ZR(LF)(SN)/455-1668-ND/926575)
 - 13 pin ribbon cable
 - Wire strippers
 - Soldering Iron
 - SMALL solder
 - Heat shrink (+heat source)
 - Helping hands

If you want you could use a Teensy or Teensy++ 2.0 but note that if you do decide to you will have to make different changes when setting up the software. Make sure that you don't get one with pins installed as it won't be able to fit in the case. Also, the newer Teensy 3.0 is available but I did not use it because there are not many firmwares developed for it yet.

The HHKB header is what will let you swap between the teensy and the original controller with ease. Without it you would have to cut the original wires or make some other non-reversible hardware mod. These are really cheap if you can get them in stock, it's practically just the cost of shipping - so see if you can buy some other things at the same time. Hasu might still have some extras and be willing to sell them, check with him - http://geekhack.org/index.php?topic=57008.msg1329340#msg1329340

You can find 13 pin cables on many electronic stores online (such as mouser), but there is an alternative. I got an old IDE cable that was lying around and used some scissors to chop off the ends. I then used my fingers to separate the wires. You can keep them together if you want to but I found it easier if I ripped them all apart so I could work with them individually.

You will want small wire strippers to expose the metal inside your cables. The wires I am using are 26 awg (you don't want to get much bigger). A lot of wire strippers don't cover wires this small so double check yours will work. I picked up these (http://www.homedepot.com/p/Klein-Tools-Kurve-Wire-Stripper-Cutter-for-20-30-AWG-Solid-and-22-32-AWG-Stranded-Wire-11057/100352112) at Home Depot for around $20. You can probably return them after you are done if you don't want to keep them and get some money back.

I had a ****ty Weller SP23L laying around and it "worked" alright. If you have anything fancier then please use that. If not think about investing in a good one or borrowing one from a friend.

The header has a 1.5mm pitch (.059" gap between pins), which turns out to be very small when you see it in person. Each pin is tiny and they are fairly close to each other. Home Depot / Lowes / Etc only carry .062" solder which is just too large, there is no way you will be able to get a small enough and controlled solder joint. Please, find the smallest solder you possibly can. I used .025" which worked alright but even smaller would be better. 60/40, a rosin core, and all that jazz are always good. See if you can find a local electronic supply company that has something like that - if not you can always order some Kester online from somewhere like Amazon. Ohh a flux pin and solder wick might come in handy if you mess up.

The heatshrink tubing is technically optional but I highly encourage it. After I plugged my Teensy in I had many issues such as pressing "q" typed "q4", keys that didn't work, and random presses. All this was due to exposed wires that potentially touched each other. Once I covered the ends with some plastic it fixed everything and I have yet to have more problems. For what it's worth I have typed this whole post using my modded HHKB. My tubing looked thin but after it shrunk it ended up becoming too big for me to push all the way down due to the close pins. Hopefully you can find something that will work a little better. If you don't have a heat gun a hairdryer works fine so go find some female friend who owns one. I have also heard that lighters will work in a pinch but it could be hard to control and you might burn your fingers so I would advise against it.

You WILL also want to get some "helping hands". They are invaluable as you line up the small wires and pins. They keep everything still so your hands can focus on the iron and solder. Any cheap one should do. I did not need the included magnifying glass because the pins are still big enough to see fine with the naked eye. Without a pair of helping hands I'm not sure how you could keep everything lined up perfectly as you solder (Having a friend hold the cable or something will not work).

I think that's everything you need. The Teensy is only $16 and everything is possible that you have lying around (if you like to dabble in electrical work). Considering everything else keyboard enthusiasts buy this mod isn't too pricey.

----- Preliminary Info ------

The original controller looks like this
More
(http://i.imgur.com/suQytIEl.jpg)

Notice how it has a connector in the bottom left corner. Our goal is to make something that will be compatible with that. The finished product should look something like this (Thank Soarer) (http://deskthority.net/resources/image/4776)

Once it's connected it should look something like this -
More
(http://i.imgur.com/1Y5fpl.jpg)

As you can see we will be wiring the header to the teensy with a bit of ribbon wire in between. This is the pinout I used. You might want to print it out or put it up on a big screen, it will help to have it handy. (http://deskthority.net/resources/image/5174)

Before you do any wiring you will want to plug the Teensy into your computer and program it with some firmware. This will come in handy for testing your solder job later. See the software section for more information. Here is a premade hex file to flash - http://geekhack.org/index.php?topic=57008.msg1332045#msg1332045. If you want a graphical program to flash this then look here - http://www.pjrc.com/teensy/loader.html

This is the Teensy 2.0 pinout. If you chose to wire yours up differently this page may be helpful - https://www.pjrc.com/teensy/pinout.html

----- Soldering - Header -----
This was actually my first soldering job so I'm pleasantly surprised that everything went well (especially with something so small). Hopefully it also means that everyone else can do it too. Note: I'm only 18 so I still have pretty good eyesight and a stable hand which did help.

Find a good working place and get yourself all set up. You will want to have a bit of time and patience as it is difficult to work with something so small if you don't have much experience.

I found one of the easier ways to accomplish this task is to use the helping hands to put a little over 1mm of your wire under the pin, then use your soldering iron to push the wire into the pin (make sure it doesn't move, there isn't much room for error), then add a tiny dab of solder from the top.

See this Imgur gallery from Janner for more images on what the soldering job looks like - https://imgur.com/gallery/lk7IU/new

If you don't add enough solder you can always heat it up and add more. If you add to much then you can try to remove some with your soldering iron (or some wick). Be careful that you only heat up the pin you are working on, you don't want to accidentally detach one of the previous pins. If you detach a pin then add some more flux and try to reflow the connection. Messing with the pins and trying to make everything perfect seemed pretty futile to me so make sure they are physically connected but don't worry about it too much.

----- Soldering - Teensy -----

This part is pretty easy since it is just your standard through hole soldering. The holes are fairly large and are separated enough that you don't have to worry about bridging or anything like that.

Mount your Teensy upside-down with one helping hand. Add your heatshrink tubing (DON'T FORGET). Then insert the wire through the hole (from the bottom) and secure it in place with the other helping hand. You can then use your iron and solder on the top of the teensy. Just touch the soldering iron to both the wire and hole and add solder until it looks good.

Note: Don't forget about the heat shrink tubing. If you solder both sides of the wire, then you will have to unsolder one of them to insert it.

Once your done slide the heatshrink tubing over the pins of the header and use your heat source (heat gun, hair dryer, lighter, etc) to shrink them. My heatshrink tubing was too thick so I ended up covering ever other pin and then sliding the rest down as much as I could - that should be enough to stop any electrical contact.

----- Installation -----

Now it's time to open up your precious keyboard. If you have already modded it (lube, 55g domes, silencing, etc) then you will know how it goes. For those that don't simply flip the board over and remove the 3 screws at the back (don't worry they are easy to find). Flip the board right side up again and then open it like a book (the spine would be at the bottom towards you). As you open it make sure to unplug the cable going to the original controller. You can now separate the two halves. See these two pictures (thanks mikelanding).

More
(http://img.photobucket.com/albums/v367/mikelanding/HHKB%20O%20Ring%20Mod/Oring0.jpg)
(http://img.photobucket.com/albums/v367/mikelanding/HHKB%20O%20Ring%20Mod/oring1a.jpg)


Plug your new teensy controller into the cable inside of the HHKB (Make sure it is the right direction). The red,orange,yellow side should be heading towards the 5V side of the teensy, and the black,brown,red side towards ground. If you forgot to program your Teensy then do that now (you don't need to do any fancy layouts yet, you just want to know it works). Plug the teensy into your computer and fire up AquaKeyTest or something similar and make sure everything is going ok. You might need to double check a solder joint, or ensure that the cables are sufficiently insulated.

Note: Double check you plugged it in the right direction before plugging it into your computer. I'm not sure what happens if it's backwards but I don't believe plugging the power pin into a data pin would be good.

Once you know your new controller works fine you can remove the original one. There is a screw in the top right corner of the pcb that must be removed, it can then simply be slid out. Plug your Teensy into the computer using the usb hole in the back of the case, just like the original one. A sticky pad can help keep it in place (otherwise it will fall back into the case once you unplug it from your computer).

Close everything up and pat yourself on the back. Now it's time to go to the computer and reprogram this bad boy. Take a look at the Customization section below.


Software:
NOTE: This was written on April 11th 2014 and is current at such time. The TMK firmware may (and most likely will) change in the future so avoid simply copy and pasting. The general ideas covered below should not change too much

There are a a lot of parts I could go into more detail about however they are either difficult to explain, vary widely (based on your setup), or are already explained well. Hopefully what follows is understandable to the non-programming mortals out there. If you make any mistakes then the compiler should throw an error message which you can give to someone for help. Knowing C syntax is very helpful.

----- Setup -----

You will need avr-gcc and avr-libc to compile the code, and teeny_loader_cli to program the board. If you run Linux like I do then these packages are probably in your favorite distribution's package manager. If you're running Windows then you can setup WinAVR and get the graphical teensy loader program.

Clone Hasu's wonderful tmk github repo (https://github.com/tmk/tmk_keyboard) and navigate to "keyboards/hhkb" as that is where we will be doing all our work. (For those who don't know you can download a zip/tarball from the github website, or run a command like "git clone https://github.com/tmk/tmk_keyboard.git")

Now that we have all the code we must make a few changes. Hasu's code is designed for a custom made PCB using at Atmega32u4 which has a few differences from our teensy setup.

We must edit the matrix code to match with the wiring job. If you used the same pinout as I did then you can simply copy and paste. If you did not then try to change the code to match the pins you used.

Open matrix.c and scroll down to this line "#elif defined(__AVR_ATmega32U4__)".

Replace the original init block
Code: [Select]
#define KEY_INIT()              do {    \
    DDRB  = 0xFF;                       \
    PORTB = 0x00;                       \
    DDRD  &= ~0x80;                     \
    PORTD |= 0x80;                      \
    /* keyswitch board power on */      \
    DDRD  |=  (1<<4);                   \
    PORTD |=  (1<<4);                   \
    KEY_UNABLE();                       \
    KEY_PREV_OFF();                     \
} while (0)

with

Code: [Select]
#define KEY_INIT()              do {    \
    DDRB  = 0xFF;                       \
    PORTB = 0x00;                       \
    DDRF |= (1<<1);                     \
    DDRF &= ~(1<<0);                    \
    PORTF |= (1<<0);                    \
    KEY_UNABLE();                       \
    KEY_PREV_OFF();                     \
} while (0)

This changes port PD7 to PF0 and PB7 to PF1 and removes the code for the PD* pins.

You will also have to replace
Code: [Select]
#define KEY_STATE()             (PIND & (1<<7))
#define KEY_PREV_ON()           (PORTB |=  (1<<7))
#define KEY_PREV_OFF()          (PORTB &= ~(1<<7))

with

Code: [Select]
#define KEY_STATE()             (PINF & (1<<0))
#define KEY_PREV_ON()           (PORTF |=  (1<<1))
#define KEY_PREV_OFF()          (PORTF &= ~(1<<1))

to correspond with the pin changes.

Next you have to open the Makefile and change

Code: [Select]
OPT_DEFS += -DBOOTLOADER_SIZE=4096

to

Code: [Select]
OPT_DEFS += -DBOOTLOADER_SIZE=512

as the Teensy (halfkay) bootloader is only 512 bytes long (not 4096 like the Atmel one). This will let us easily reboot into the bootloader.

----- Compiling -----

run "make clean" to ensure there are no leftover files.

Then run "make KEYMAP=hhkb" to generate an installable hex file. If you do not specify the hhkb layout you will get Hasu's custom one.

Note: if you are using Windows 8.1 and receive an error about avr-gcc.exe, then check out this thread, it may help you (Thanks to GetzTheGoldfish).
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=1118778

Then run "make teensy" which will attempt to program the controller. You should plug the teensy into your computer with a usb cable and then press the small button on it. The program should quickly recognize the controller and begin programming it.

Note: You may need to run the above command as root (ex: with sudo) if it detects the device but does not have permission to communicate with it. (If your on Windows you might need to run it as administrator or double check your drivers, I'm not sure)

If you made it this far then congratulations, you should now have a fully working HHKB running Hasu's powerful TMK firmware.

From now on you should be able to use the "Magic" key combo to reboot into the bootloader (so you won't have to open the case and press the button on the teensy). By default this combo is LShift+RShift+Pause. However, the pause key is accessed with the function layer on the HHKB (FN+P). This makes the combo "Left Shift + Right Shift + FN + P". Once all the keys have been pressed at the same time the keyboard will reboot into its bootloader and wait to be reprogrammed. During this time it will not respond to any keypresses so it might be smart to have another keyboard lying around. A quick word for the wise - If you run "make teensy" before doing this then it will recognize the keyboard as soon as you press the combo. The board will then be programmed and reboot into a usable state. This means that you can flash your firmware with only one keyboard.

----- Customization -----

Copy one of the default layouts (keymap_hhkb.c, keymap_hasu.c, or keymap_spacefn.c) and rename it to something else. Make sure to use the new name when you are building.

For example: If you copy keymap_hhkb.c and rename it to keymap_gh.c then you will change the command to "make KEYMAP=gh". (You can also edit the Makefile to change the default keymap if you are lazy and know how to).

Open the new file and find the big KEYMAP() section. It should look something like this.

Code: [Select]
           KEYMAP(ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, BSLS,GRV,   \
           TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSPC,       \
           LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,ENT,             \
           LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT,FN0,             \
                LGUI,LALT,          SPC,                RALT,RGUI),

This is where you will change what each key does. You can also paste in another keymap section if you would like to add another layer (just make sure to add a way to switch to it). For a very dry, in depth, and possibly confusing explanation of layers and functions see https://github.com/tmk/tmk_keyboard/blob/master/doc/keymap.md (https://github.com/tmk/tmk_keyboard/blob/master/doc/keymap.md). For my help I would look on google for a guide dedicated to creating your own layouts, or create a post in the TMK thread asking for help (link at the end of this post).

----- More -----

If your still following along then thank you. It took a bit of time to write this guide so I hope it helps some other people out there. Having a keyboard set up exactly as you like is a very nice feeling :thumb:

Here are some additional links that may be of help or are interesting.

http://deskthority.net/workshop-f7/hardware-dvorak-hhkb-t3415.html - The "original" DT thread that got me interested in this mod. Contains many pictures you will want to see.

http://geekhack.org/index.php?topic=41989.msg841759#msg841759 - The official thread for Hasu's firmware. The people there are friendly so look there for all your questions and information.

http://geekhack.org/index.php?topic=12047.0 - An "Alternative Controller for HHKB". Like this teensy mod but an actual professional looking PCB, plus it may get bluetooth support sometime in the distant future.

http://grumpylemming.com/blog/2012/12/24/hacking-a-happy-hacking-keyboard/ - A blog post (similar to this) which covers using a Teensy as a HHKB controller. Note: He does cut the cables so you can not easily switch back to the original controller (ex: if you want to sell it stock, or something bad happens).

http://nathankot.com/blog/2013/09/05/modding-the-happy-hacking-keyboard/ - A blog post using Hasu's alternative controller board. Describes some possible layout tweaks.

http://grumpylemming.com/blog/2013/10/02/hacking-a-happy-hacking-keyboard-revisited/ - Another blog post. Goes over the features of the TMK firmware and his personal layout.

http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#controlescape - A very long and informative blog post by a man who wants to have the best typing experience. There are many ideas presented that you might want to try out.
Title: Re: Teensy HHKB Controller (Writeup)
Post by: SpAmRaY on Sat, 12 April 2014, 00:08:58
Awesome, awesome...did I say awesome...write up! Thank you for sharing.
Title: Re: Teensy HHKB Controller (Writeup)
Post by: RESPRiT on Sat, 12 April 2014, 01:51:54
This is a fantastic write up, keep up the excellent work!
Title: Re: Teensy HHKB Controller (Writeup)
Post by: mashby on Sat, 12 April 2014, 07:35:38
Wow... just... wow.

Great write up. Thank you for providing so much detail for newbs like me to easily understand.  :thumb:
Title: Re: Teensy HHKB Controller (Writeup)
Post by: Smasher816 on Sat, 12 April 2014, 08:10:35
Thanks for all the kins words.

I wrote this pretty late at night and when skimming over it this morning noticed that there are a bit of typos. Once I get home I'll see if I can read through it again and make sure all the sentences make sense.

If any of you decide to try this then be sure to post here with your progress. If you have any problems I'll see if I can help - no promises though.

If you have soldering equipment already lying around then the most expensive part is a teensy - so it's not a big investment. You can assemble the new controller on its own before you ever open your HHKB making it pretty safe. The most difficult part was soldering on the header but with the right hardware and some patience it is doable.
Title: Re: Teensy HHKB Controller (Writeup)
Post by: riotonthebay on Sat, 12 April 2014, 08:15:29
Thanks for the incredibly write-up, Smasher!

I have almost all of the "big parts" required for this – HHKB (duh), Teensy 2.0, soldering equipment and small solder, etc. The only question in my mind is what I might do with my new programmable controller… I basically love the HHKB layout already. What kinds of changes are being made to the layout? (Or for most of us without programmable HHKB's, what changes do you want to see?)
Title: Re: Teensy HHKB Controller (Writeup)
Post by: Smasher816 on Sat, 12 April 2014, 10:21:04
The only question in my mind is what I might do with my new programmable controller… I basically love the HHKB layout already. What kinds of changes are being made to the layout? (Or for most of us without programmable HHKB's, what changes do you want to see?)

Read the last few links I posted. There are many ideas presented - some of them you might find you want to use. I'll write out some of these ideas below, not all of them will apply to you since you love the HHKB layout (but someone else might not).

One nice thing is dual role keys. For instance you can make tapping the Control key act as escape, making it even closer (it's very nice if you use vim). If you can get used to it you can try turning it into a Backspace dual role key (like colemak).

If your a programmer you can try turning taps on the Shift keys into parentheses.

If you use another keyboard layout like Dvorak or Colemak you can embed that in the keyboard so it will work on any computer without having to get the language setup.

If you don't like the HHKB arrow keys you can move them. For instance you can use WASD if you are used to that from gaming or HJKL if you use vim. You can also create a FN-Lock key so you don't have to hold the function key down if you will be navigating a lot.

There are other things you can do. You could add a numpad type layer. Maybe add some mouse keys if you are into that.

TMK brings a lot of possibilities to the table.
Title: Re: Teensy HHKB Controller (Writeup)
Post by: CPTBadAss on Sat, 12 April 2014, 10:24:43
Finally, a DIY/How-To writeup that realizes that not everyone inherently understands code and firmware. Thanks for posting this.
Title: Re: Teensy HHKB Controller (Writeup)
Post by: AKIMbO on Sat, 12 April 2014, 10:45:08
Finally, a DIY/How-To writeup that realizes that not everyone inherently understands code and firmware. Thanks for posting this.

I know right?!  Awesome job!
Title: Re: Teensy HHKB Controller (Writeup)
Post by: dsc. on Sat, 12 April 2014, 14:30:23
This is great, thanks for posting!
Title: Re: Teensy HHKB Controller (Writeup)
Post by: Glissant on Sun, 13 April 2014, 09:12:50
(http://img.pandawhale.com/post-39638-Arnold-Schwarzenegger-YES-chan-RKPb.gif)

Excellent writeup! Thank you very much for taking the time and effort. I will assuredly try this project with the awesome information you provided.
Title: Re: Teensy HHKB Controller (Writeup)
Post by: osi on Sun, 13 April 2014, 09:30:30
Great writeup!! Will reference this if I ever get to this point. My biggest fear is gaming the tabs while opening up the hhkb case  :blank: ha
Title: Re: Teensy HHKB Controller (Writeup)
Post by: Smasher816 on Sun, 13 April 2014, 10:29:35
My biggest fear is gaming the tabs while opening up the hhkb case  :blank: ha

I woudn't worry about it too much. The HHKB is very easy to open. You don't have to unscrew the PCB and dig into all the internals - just get it open with the 3 screws on the back. Once you got it unscrewed and right side up then just grab the back of the upper piece and lift it towards you. To close it line up the 3 tabs at the bottom then lower the back. It should rest closed just fine if it doesn't then try to re-set it. Everything should go together easily - don't try to force anything.

Perhaps someone could upload a video to youtube. I have a bad camera and don't have a channel so I don't think I should. Perhaps it could be picked up by geekhackers or something.

Check out these two pictures from mikelanding's dental mod thread. It's really is simple.
(http://img.photobucket.com/albums/v367/mikelanding/HHKB%20O%20Ring%20Mod/Oring0.jpg)
(http://img.photobucket.com/albums/v367/mikelanding/HHKB%20O%20Ring%20Mod/oring1a.jpg)
Title: Re: Teensy HHKB Controller (Writeup)
Post by: duq on Sun, 13 April 2014, 10:54:43
!!! Once again. Best community. Great job and thanks for taking he time.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Fri, 18 April 2014, 11:04:54
Once again thanks for all the kind words. I really do appreciate it.

I finally went back and corrected some typo's in the OP. I also added links to a few more pictures (such as how to open the case), and a few more notes (such as how to use the magic combo to flash).

I also added a little bit more to my reply to riotonthebay. Some of the possible features of this mod are outlined there so you don't have to dig around in the linked pages.

Ohh and Osi, take a look at the the pictures I put in the OP and my last reply to you. Hopefully it should show you that opening up the HHKB isn't too scary.
Title: Re: Teensy HHKB Controller (Write up)
Post by: sublime on Mon, 21 April 2014, 09:33:20
I've been longing for a tutorial like this for quite some time. Thank you so much for providing such detail
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Mon, 21 April 2014, 12:09:55
Well I'm glad you found a tutorial, hopefully it can help you some.

I ended up cutting up a Command strip to stick the teensy to the bottom of the case. I was a little worried that it might still slide left and right so I made a cardboard cutout to fill the rest of the space the original controller took. It's not perfectly lined up with the hole but it has stayed in place after a couple of disconnects.
 
(http://i.imgur.com/BBY4lBW.jpg)

I also took another piece of cardboard and covered a side with black electrical tape. I then tacked it to the side so it would cover up the two usb port holes. I have to say it actually looks pretty good from the outside.

(http://i.imgur.com/HRQpgtS.jpg)

Now that everything is fairly "finalized" I have screwed the case back together and restored the wonderful thock sound. If any of you want more pictures then I would be happy to open it back up again and take some more. Unfortunately I did not take any pictures while I was soldering everything together :(
Title: Re: Teensy HHKB Controller (Write up)
Post by: abjr on Tue, 22 April 2014, 16:44:45
This is really cool, but one thing is confusing me. How does the HHKB matrix work with only 13 pins?  :confused:
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Tue, 22 April 2014, 17:10:39
This is really cool, but one thing is confusing me. How does the HHKB matrix work with only 13 pins?  :confused:

Take a look at Hasu's github page. He did a good job documenting all of his discoveries.
https://github.com/tmk/tmk_keyboard/tree/master/keyboard/hhkb/doc

Quote

pro2           Description                               Teensy++ pins
----------------------------------------------------------------------
1   Vcc(5V)                                              5V
2   Vcc(5V)                                              5V
3   TP1684     KEY: Low(0) when key pressed              PE6 input(with pullup)
4   TP1684     KEY_PREV: make threshold                  PE7 output
5   HC4051     A(bit0)\                                  PB0 output
6   HC4051     B(bit1) > select row(0 to 7)              PB1 output
7   HC4051     C(bit2)/                                  PB2 output
8   LS145      A(bit0)\                                  PB3 output
9   LS145      B(bit1) > select column(0 to 7)           PB4 output
10  LS145      C(bit2)/                                  PB5 output
11  LS145      D(enable) Low(0) enables selected column  PB6 output
12  GND                                                  GND
13  GND                                                  GND

Looking at that, pins 5-7 form a 3 bit number for the row (7 8 possible values, 0-7), and similarly pins 8-10 form the column. Each of the keys then fits into a 7x7 8x8 matrix.

Quote

   COL 0     1       2       3       4       5       6       7
ROW -------------------------------------------------------------
   0|  2     q       w       s       a       z       x       c
   1|  3     4       r       e       d       f       v       b
   2|  5     6       y       t       g       h       n             
   3|  1     Esc     Tab     Control LShift  LAlt    LMeta   Space
   4|  7     8       u       i       k       j       m             
   5|  \     `       Delete  Return  Fn      RShift  RAlt    RMeta
   6|  9     0       o       p       ;       l       ,             
   7|  -     +       ]       [       '       /       .             

Hopefully that answers your question :thumb:
Title: Re: Teensy HHKB Controller (Writeup)
Post by: hjkl_over_wasd on Tue, 22 April 2014, 17:47:16

One nice thing is dual role keys. For instance you can make tapping the Control key act as escape, making it even closer (it's very nice if you use vim). If you can get used to it you can try turning it into a Backspace dual role key (like colemak).

This is my entire reason for getting involved with the keyboard scene in the first place. Xcape is really nice, but it still lags a bit when you're using caps as escape and having to wait a slight moment for the signal to get to Vim. Having this done at the firmware level is exactly what I've wanted ever since I saw the Coding Horror keyboard and learned that crl/caps switching could be done with a DIP switch. Now I see it's possible, but I have to pay 350$ not including shipping and the absurd toll fee I would have to add to that.

I'm glad I've found that this is possible, but I'm also saddened by how much this is going to cost me as I'm still in Uni and currently without a job.

If your a programmer you can try turning taps on the Shift keys into parentheses.

Obviously, this would be a killer feature for LISP-like functional languages, but I wonder how much I'd like it when coding in C or Python.


Thank you so much for sharing this information. I cannot wait until I get to actually use it.
Title: Re: Teensy HHKB Controller (Write up)
Post by: abjr on Wed, 23 April 2014, 11:40:53
Looking at that, pins 5-7 form a 3 bit number for the row (7 possible values), and similarly pins 8-10 form the column. Each of the keys then fits into a 7x7 matrix.

Not to nit-pick, but 3 bits is 8 possible values, so we'd have an 8x8 matrix. 7x7 would be too small to cover all 60 keys on the HHKB. ;)

Quote
Hopefully that answers your question :thumb:

Yes, it does. Thanks a lot! You guys amaze me with all of this stuff you're able to figure out.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Wed, 23 April 2014, 11:44:27
Looking at that, pins 5-7 form a 3 bit number for the row (7 possible values), and similarly pins 8-10 form the column. Each of the keys then fits into a 7x7 matrix.

Not to nit-pick, but 3 bits is 8 possible values, so we'd have an 8x8 matrix. 7x7 would be too small to cover all 60 keys on the HHKB. ;)

Your correct. I neglected the 0 values :P
Title: Re: Teensy HHKB Controller (Write up)
Post by: margo baggins on Thu, 24 April 2014, 03:46:22
This is one of the best posts on GH! Thanks so much!
Title: Re: Teensy HHKB Controller (Write up)
Post by: GetzTheGoldfish on Thu, 24 April 2014, 14:31:22
First of all i must say thanks alot for this writeup since it's just what i needed although I did have a slight problem during the compiling that I'll explain in a second. It appears that people using windows especially windows 8.1 trying to compile will receive an error about avr-gcc.exe and I am just one of those people. The problem was in WinAvr and you can find the fix here http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=1118778
I hope that this will help any other windows users trying to follow this writeup  :)


----- Compiling -----

run "make  clean" to ensure there are no leftover files.

Then run "make KEYMAP=hhkb" to generate an installable hex file. (this is the part where you get the error on Windows 8.1)

Note: If you do not specify the hhkb layout you will get Hasu's custom one.

Then run "make teensy" which will attempt to program the controller. You should plug the teensy into your computer with a usb cable and then press the small button on it. The program should quickly recognize the controller and begin programming it.

Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Thu, 24 April 2014, 15:46:46
Thanks GetzTheGoldfish,

I'll add it to the op when I get home.

Edit: Added. Ohh and welcome to GH ;)
Title: Re: Teensy HHKB Controller (Write up)
Post by: n0rvig on Tue, 29 April 2014, 11:28:11
Nice work Smasher816. Inspiring.
Title: Re: Teensy HHKB Controller (Write up)
Post by: hasu on Wed, 14 May 2014, 11:51:06
Smasher816, great writeup!

For those who want to make thier own;
I have some B13B-ZR header connectors. I can send one to you for $3US(to most part of the world). PM me if you want.
(http://i.imgur.com/wUB87tll.jpg)
left: B13B(right: S13B)
Title: Re: Teensy HHKB Controller (Write up)
Post by: admiralvorian on Fri, 16 May 2014, 11:58:33
Smasher this write-up is excellent!

After I meticulously built everything and flashed the hex to my teensy 2.0, nothing worked.
So, I told Windows to go to hell, grabbed Ubuntu, and compiled on there. Everything works fine now.

In case anyone else has issues with windows, or doesn't feel like messing with all these libraries and code, here's the hex file for the teensy 2.0 with Hasu's layout. If you want a different layout just let me know and I'll see if I can compile one for you!

Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Fri, 16 May 2014, 13:03:40
Having this done at the firmware level is exactly what I've wanted ever since I saw the Coding Horror keyboard and learned that crl/caps switching could be done with a DIP switch. Now I see it's possible, but I have to pay 350$ not including shipping and the absurd toll fee I would have to add to that.

Don't fret so much. There are other ways to get a keyboard with a programmable controller. For instance a QFR Rapid will cost you $80, and "The Frosty Flake" replacement controller is only $20 (if they are still around).

Check out this thread. http://geekhack.org/index.php?topic=46700.0

For those who want to make thier own; I have some B13B-ZR header connectors. I can send one to you for $3US(to most part of the world). PM me if you want.

Take this man up on his offer. It is how I got my header connectors. For what it's worth, Hasu was very kind and responsive in his communication and the goods arrived fine after a while.

The cost of shipping is going to be the most expensive part of getting this ($.50) item. Depending on where you live paying a company like DigiKey to ship internationally to you will probably end up more expensive than Hasu's great $3 offer. At the time I do not remember a cheap USPS option with DigiKey so it would have cost me over $10.

.... Everything works fine now.

In case anyone else has issues with windows, or doesn't feel like messing with all these libraries and code, here's the hex file for the teensy 2.0 with Hasu's layout.

Awesome! :thumb:

So you followed this write up and got your own teensy to work with your HHKB? If you have any pictures or advice for others feel free to share it.

I will be sure to add a link to the hex file to the OP so that others can use it. It's nice to have a premade file just to make sure that everything is working before you start customizing.
Title: Re: Teensy HHKB Controller (Write up)
Post by: admiralvorian on Fri, 16 May 2014, 13:37:29
Quote
So you followed this write up and got your own teensy to work with your HHKB? If you have any pictures or advice for others feel free to share it.

I will be sure to add a link to the hex file to the OP so that others can use it. It's nice to have a premade file just to make sure that everything is working before you start customizing.
pics
More
don't mind the weights, I'm trying to make my hhkb heavy as possible
(http://i.imgur.com/8QE77lc.jpg)
(http://i.imgur.com/wrxd4JP.jpg)


Nothing special - I haven't fixed my teensy to the case yet (3M double sided tape should work well, but I might use hot glue to fix it solidly). I'm having a couple problems, though:



I'm a sometimes-gamer and the space bar works really strangely with this firmware. In minecraft, pressing space doesn't result in jumping. I have to double tap, then double tap again in creative mode to get an actual double-jump. Also, pressing shift results in a minute delay while it decides if I'm holding shift down or just tapping it to get the ( character. Is there a way I can fix the space and shift to act like standard space and shift keys? I looked in main.c and hhkb_layout.c and didn't find anything. I also asked in Hasu's thread but haven't had a reply yet.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Fri, 16 May 2014, 13:44:47
Nothing special - I haven't fixed my teensy to the case yet (3M double sided tape should work well, but I might use hot glue to fix it solidly). I'm having a couple problems, though:

The Command strips that you are supposed to use to hang hooks from walls worked great for me. There might be some better alternatives out there but I had that laying around the house. I would discourage using hot glue because it sounds like a pain to clean up if you ever change your mind.

Regarding the firmware issues. I believe that is because Hasu's layout has "Mousekey layer with Space" (FN6). If you change the keymap to use SPC instead it should act like a normal space key. I also replied about the parenthesis in the TMK thread.

Maybe you should start with the standard HHKB layout and build up from there? "make LAYOUT=hhkb"



Edit: YAY! We made it to page 2
Title: Re: Teensy HHKB Controller (Write up)
Post by: admiralvorian on Fri, 16 May 2014, 13:51:34
Nothing special - I haven't fixed my teensy to the case yet (3M double sided tape should work well, but I might use hot glue to fix it solidly). I'm having a couple problems, though:

The Command strips that you are supposed to use to hang hooks from walls worked great for me. There might be some better alternatives out there but I had that laying around the house. I would discourage using hot glue because it sounds like a pain to clean up if you ever change your mind.

Regarding the firmware issues. I believe that is because Hasu's layout has "Mousekey layer with Space" (FN6). If you change the keymap to use SPC instead it should act like a normal space key. I also replied about the parenthesis in the TMK thread.

Maybe you should start with the standard HHKB layout and build up from there? "make LAYOUT=hhkb"



Edit: YAY! We made it to page 2


When you mentioned that the standard layout doesn't have that I got very confused. I was compiling using 'make KEYMAP=hhkb' which I thought would specify keymap_hhkb.c instead of keymap_hasu.c. What's strange is that some of the changes I made to keymap_hhkb.c were present, but so was hasu's ( and space key setup.

BRB recompiling.
Title: Re: Teensy HHKB Controller (Write up)
Post by: admiralvorian on Fri, 16 May 2014, 14:10:06
ok here's my keymap_hhkb.c

Code: [Select]
/*
 * HHKB Layout
 */
#include "keymap_common.h"


#ifdef KEYMAP_SECTION_ENABLE
const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
#else
const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
#endif
    /* Layer 0: Default Layer
     * ,-----------------------------------------------------------.
     * |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|  \|  `|
     * |-----------------------------------------------------------|
     * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|Backs|
     * |-----------------------------------------------------------|
     * |Contro|  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|Enter   |
     * |-----------------------------------------------------------|
     * |Shift   |  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift |Fn0|
     * `-----------------------------------------------------------'
     *       |Gui|Alt  |         Space         |Alt  |Gui|
     *       `-------------------------------------------'
     */
    KEYMAP(ESC, 1,   2,   3,   4,   5,   6,   7,   8,   9,   0,   MINS,EQL, GRV,BSPC   \
           TAB, Q,   W,   E,   R,   T,   Y,   U,   I,   O,   P,   LBRC,RBRC,BSLS,       \
           LCTL,A,   S,   D,   F,   G,   H,   J,   K,   L,   SCLN,QUOT,ENT,             \
           LSFT,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,RSFT,FN0,             \
                LGUI,LALT,          SPC,                RALT,RGUI),

    /* Layer 1: HHKB mode (HHKB Fn)
     * ,-----------------------------------------------------------.
     * |Pwr| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
     * |-----------------------------------------------------------|
     * |Caps |   |   |   |   |   |   |   |Psc|Slk|Pus|Up |   |Backs|
     * |-----------------------------------------------------------|
     * |      |VoD|VoU|Mut|   |   |  *|  /|Hom|PgU|Lef|Rig|Enter   |
     * |-----------------------------------------------------------|
     * |        |   |   |   |   |   |  +|  -|End|PgD|Dow|      |   |
     * `-----------------------------------------------------------'
     *       |   |     |                       |     |   |
     *       `-------------------------------------------'
     */
    KEYMAP(PWR, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, INS, DEL,   \
           CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS, UP, TRNS, BSPC,      \
           TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT,PENT,            \
           TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PPLS,PMNS,END, PGDN,DOWN,TRNS,TRNS,            \
                TRNS,TRNS,          TRNS,               TRNS,TRNS),
};



/*
 * Fn action definition
 */
#ifdef KEYMAP_SECTION_ENABLE
const uint16_t fn_actions[] __attribute__ ((section (".keymap.fn_actions"))) = {
#else
const uint16_t fn_actions[] PROGMEM = {
#endif
    [0] = ACTION_LAYER_MOMENTARY(1),
};

Then I run
Code: [Select]
make LAYOUT=hhkb
flashing the hex leaves me with hasu's layout. I run
Code: [Select]
make clean before changing things and compiling to ensure I don't have any garbage laying around.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Fri, 16 May 2014, 16:50:41
Ooops. I shouldn't have written that from memory.

You are correct - It's actually "make KEYMAP=hhkb". So use Keymap not layout like I said before.

If you want to change the default value (for when you omit that part) then open up the Makefile and find

Code: [Select]
ifdef KEYMAP
    SRC := keymap_$(KEYMAP).c $(SRC)
else
    SRC := keymap_hasu.c $(SRC)
endif

and change that "keymap_hasu.c" part between the "else" and "endif"



I'm not sure why only some of your changes are applying after doing a clean compile.

How are you flashing the teensy? If you did not change the
Code: [Select]
DBOOTLOADER_SIZE= part like described in the OP then it will not write the changes correctly when using the magic keycombo. In that case I would make sure you use the little reset button on the teensy to make sure you get a clean flash.
Title: Re: Teensy HHKB Controller (Write up)
Post by: feizor on Fri, 16 May 2014, 18:00:51
Why does the original controller have so many more components than the teensy? Are the extra parts just for the USB hub functionality?
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Fri, 16 May 2014, 18:26:57
feizor,

I'll be honest. I have no idea why the original controller has so many extra parts. It may very well be part of the usb hub or dip switch addons. I do know that the main pcb is what takes care of all of the key detection, it then sends that information over the 13 pin cable to the controller we are talking about - which handles informing the computer of the keypresses. By changing the controller we change what is sent to the computer.

I would talk to Hasu since he is the one who reverse engineered this board and is creating his own alternative controller (http://geekhack.org/index.php?topic=12047.0).

(http://i.imgur.com/xKHNxV3.jpg)
Title: Re: Teensy HHKB Controller (Write up)
Post by: feizor on Fri, 16 May 2014, 18:33:35
feizor,

I'll be honest. I have no idea why the original controller has so many extra parts. It may very well be part of the usb hub or dip switch addons. I do know that the main pcb is what takes care of all of the key detection, it then sends that information over the 13 pin cable to the controller we are talking about - which handles informing the computer of the keypresses. By changing the controller we change what is sent to the computer.

I would talk to Hasu since he is the one who reverse engineered this board and is creating his own alternative controller (http://geekhack.org/index.php?topic=12047.0).

Show Image
(http://i.imgur.com/xKHNxV3.jpg)


Thanks for the quick reply. I will be doing this or a similar mod when I get my hhkb, will check with hash then.
Title: Re: Teensy HHKB Controller (Write up)
Post by: admiralvorian on Fri, 16 May 2014, 18:48:59
Ooops. I shouldn't have written that from memory.

You are correct - It's actually "make KEYMAP=hhkb". So use Keymap not layout like I said before.

If you want to change the default value (for when you omit that part) then open up the Makefile and find

Code: [Select]
ifdef KEYMAP
    SRC := keymap_$(KEYMAP).c $(SRC)
else
    SRC := keymap_hasu.c $(SRC)
endif

and change that "keymap_hasu.c" part between the "else" and "endif"



I'm not sure why only some of your changes are applying after doing a clean compile.

How are you flashing the teensy? If you did not change the
Code: [Select]
DBOOTLOADER_SIZE= part like described in the OP then it will not write the changes correctly when using the magic keycombo. In that case I would make sure you use the little reset button on the teensy to make sure you get a clean flash.

Very strange. I tried KEYMAP= and LAYOUT=

I was using make clean to remove all the compilation products and even checking to make sure they weren't there. I went so far as deleting everything, cloning the repo again, and re-modifying everything.

I made all the requisite changes in the makefile and matrix.c every time. The only thing that ended up working was editing keymap_hasu.c
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Fri, 16 May 2014, 18:50:58
As I mentioned in the second half of my post, how are you flashing it?

I had some issues when using the magic keycombo until I made that DBOOTLOADER_SIZE fix. Using the button on the teensy worked fine.
Title: Re: Teensy HHKB Controller (Write up)
Post by: hasu on Fri, 16 May 2014, 19:14:14
feizor,
Topre paid reasonable(or excess?) cost to get clean power supply. They use 'filter'(you can see big green inductor and big capacitors) to clean noise and boost converter to get 5V. Good and stable power supply is key for capacitive sensing, I think.
Pro2 has additional components for internal USB HUB but this is not critical. It is superfluous for keyboard in my opinion :p

EDIT: That big inductor is probably for boost(step-up) voltage converter, not for noise 'filter'. Some componets for surge protection and noise suppression can be found around USB connector. I don't have enough knowledge of analog and power circuit, though.

So far I've never had sensing problems  with my use but I'm just lucky probably. You may have a problem with alt controller if you have cheap HUB/PC with very bad power source or you are in harsh environment like factory with full of powerful machines and noise.

(http://i.imgur.com/RcJEe.jpg?2)
Title: Re: Teensy HHKB Controller (Write up)
Post by: feizor on Fri, 16 May 2014, 22:24:49
feizor,
Topre paid reasonable(or excess?) cost to get clean power supply. They use 'filter'(you can see big green inductor and big capacitors) to clean noise and boost converter to get 5V. Good and stable power supply is key for capacitive sensing, I think.
Pro2 has additional components for internal USB HUB but this is not critical. It is superfluous for keyboard in my opinion :p

So far I've never had sensing problems  with my use but I'm just lucky probably. You may have a problem with alt controller if you have cheap HUB/PC with very bad power source or you are in harsh environment like factory with full of powerful machines and noise.

Show Image
(http://i.imgur.com/RcJEe.jpg?2)


That explains it (in a very detailed way). Thanks!
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Fri, 16 May 2014, 23:17:20
Hasu, was there a big revision to the pro 2 PCB's? Because mine does not look like that.

One big difference is the lack of a big green capacitor on the left side. Also, My dip switches are white and slide instead of flip. Other than that they look pretty similar.

Here is a potato shot. (https://i.imgur.com/Zi8Ph82.jpg?1)
Title: Re: Teensy HHKB Controller (Write up)
Post by: hasu on Sat, 17 May 2014, 03:03:47
Yes, Topre has probably revised desgin and changed components several times.
I guess your controller is manufactured in Oct 9th 2013 and very newer revision '4'.

I'm almost sure 'NA1F2' means Pro2 controller unit and '4' is probably revision number. Other four numbers are product date(last digit of year, month, day) and serial number.

So Topre manufacture code is comprised like: <Unit+revision> <year> <month> <day> <serial>.
Unit code scheme is also not clear but HHKB has following code at least.
NA011 = Pro1 keyboard unit
NA012 = Pro1 Controller unit
NA1F1 = Pro2 keyboard unit
NA1F2 = Pro2 controller unit


And I have another revision '2' contller(2010/Jul).
(http://i.imgur.com/gsLJ2Mfl.jpg)
Title: Re: Teensy HHKB Controller (Write up)
Post by: admiralvorian on Sun, 18 May 2014, 12:07:53
As I mentioned in the second half of my post, how are you flashing it?

I had some issues when using the magic keycombo until I made that DBOOTLOADER_SIZE fix. Using the button on the teensy worked fine.

Flashing through teensy cli via magic keystroke. Made the bootloader change in source before compiling anything.

It's all good now, I have my custom keymap by working around my issues (editing hasus keymap instead of using the keymap_*.c method).

Thanks for the help, by the way! I used some hightemp hot glue to hold the teensy in place, it looks 100% stock from the outside!
Title: Re: Teensy HHKB Controller (Write up)
Post by: Janner on Tue, 27 May 2014, 15:51:33
Hey there,

So I finished my HHKB mod yesterday! Imgur album: http://imgur.com/gallery/lk7IU/new (http://imgur.com/gallery/lk7IU/new)

Immense thanks to hasu for giving me the appropriate header, and OF COURSE for writing the tmk keyboard firmware.

For anyone wanting to try this themselves: I have one B13B header to spare.

@Smasher816: thanks a lot for your original writeup. 'T was very informative.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Tue, 27 May 2014, 16:08:45
Awesome job Janner.

Thanks for taking pictures of the soldering because I neglected to do that. I'll be sure to add it to the OP so that hopefully others will be able to better see what they have to do.

If you want to do more DIY stuff in the future then you might check this out later - http://geekhack.org/index.php?topic=58718.0. I am planning on using the teensy to make my HHKB into a bluetooth keyboard :cool:. Be aware, this one is significantly more expensive (parts are over $80).
Title: Re: Teensy HHKB Controller (Write up)
Post by: qwack on Sat, 14 June 2014, 10:11:39
Wow, this is stellar. Thanks a lot for this awesome write up, it should clear a lot of questions I have about the Teensy.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Sat, 14 June 2014, 11:50:19
No problem. Glad it could help.
Title: Re: Teensy HHKB Controller (Write up)
Post by: jmolino on Sat, 21 June 2014, 02:58:12
Hi Smasher,

Can you help me out here?  I ordered the Teensy 2.0, but for some reason they sent me the Teensy++2.0!  Anyways, I wired it up the same as your diagram (see pic below) with the matching names (the names are a little different, but I think they are the direct related ones).

(http://[attachimg=1])

Note:  I probably should have re-wired it to make it cleaner, but I didn't want to muck with more code changes... and although it looks like a lot of crossing in the image, in the physical world it actually wasn't that bad...

My question is, do I have to change any of the code you posted, and/or is there any other changes I need to implement?  Thank you.  Hopefully this can help other people interested in modd'ing the HHKB Pro2 using the Teensy ++ 2.0 controller.  According to Hasu he prefers this one (I think it is due to the size, or because of bluetooth.. I'm not remembering what he told me... perhaps he will post here and clarify).

Thanks,
John

P.S. why is this image I attached to this post messed up? I can't seem to fix it...
Title: Re: Teensy HHKB Controller (Write up)
Post by: jmolino on Sat, 21 June 2014, 22:43:10
According to Hasu he prefers this one (I think it is due to the size, or because of bluetooth.. I'm not remembering what he told me... perhaps he will post here and clarify).

I received a reply back from Hasu on this and actually, the Teensy ++ 2.0 is not preferred because it does not "install" properly/easily into the HHKB pro 2 due to the standoff (plastic piece where the screw that holds the case top and bottom halves together goes).  You can probably make it work somehow, or if you don't mind it just laying inside your case loose.... but using the Teensy ++ 2.0 will add this extra layer of complexity to your mod.  Probably best to stick w/ the Teensy 2.0.  Here is Hasu's explanation: http://geekhack.org/index.php?topic=12047.msg1373181#msg1373181 (http://geekhack.org/index.php?topic=12047.msg1373181#msg1373181)
Title: Re: Teensy HHKB Controller (Write up)
Post by: jmolino on Sun, 22 June 2014, 00:30:47
My connection is wrong.... PF0 and PF1 should be PE6 and PE7... GRRRR!  I read this page to get that debugged:

https://github.com/tmk/tmk_keyboard/blob/master/keyboard/hhkb/doc/HHKB.txt (https://github.com/tmk/tmk_keyboard/blob/master/keyboard/hhkb/doc/HHKB.txt) Down where it says "Connector Cable"... time to de-solder and re-solder (I've never done either of these! LOL ---- oh what fun it is to try something new!)

I wonder how many people simply stop at switching keycaps, and never get into the meat of things.....maybe that should have been me LOL!
Title: Re: Teensy HHKB Controller (Write up)
Post by: jmolino on Sun, 22 June 2014, 00:36:08
BTW - that "No-Clean" Wick by NTE worked like a charm!  sucked up the solder and let me pull off the mis-connected wires!  (Smasher - sorry to muddy up your thread - I'll start a new one if I feel the need to post for help more).....  Peace!
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Sun, 22 June 2014, 19:20:06
No problem jmolino. Sorry for the late reply I was out camping with the family (so no cell service). You get everything worked out?

Yeah keyboards are a crazy hobby. Just spent 100 on new soldering gear. If you talked to me last year I would have had no interest in it.
Title: Re: Teensy HHKB Controller (Write up)
Post by: jmolino on Mon, 23 June 2014, 01:15:26
For anybody on linux trying to do this, be sure to compile the "teensy_loader_cli" program and install it in a directory on your path (I used /usr/bin) so that when you run "make teensy", it can properly find the  loader program.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Mon, 23 June 2014, 09:15:42
For anybody on linux trying to do this, be sure to compile the "teensy_loader_cli" program and install it in a directory on your path (I used /usr/bin) so that when you run "make teensy", it can properly find the  loader program.

That is a fair point. Make sure you check your distributions package manager, it might already be around for you to install. I used this on Arch Linux https://aur.archlinux.org/packages/teensy_loader_cli/.

If you are on ubuntu this might work "sudo apt-get install teensy-loader-cli" https://launchpad.net/~astraw/+archive/ppa/+build/1916915. If the name stays incorrect like that you can try making a symlink from teensy-loader-cli to teensy_loader_cli.
Title: Re: Teensy HHKB Controller (Write up)
Post by: runcom on Tue, 22 July 2014, 08:18:51
just a quick queston, does someone managed to make something to hold the teensy 2.0 in the hhkb? :)
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Tue, 22 July 2014, 08:32:41
Something like this works well. http://www.radioshack.com/product/index.jsp?productId=2103341
Title: Re: Teensy HHKB Controller (Write up)
Post by: admiralvorian on Tue, 22 July 2014, 10:59:07
The double-sided tape I haven't tried, though it looks like something that would work well. I used some high-temp hot glue, first a small dab underneath the teensy then some lines that rise up on the PCB slightly from the floor of the case. It's held in like a rock and perfectly fits the HHKB hole for the connector.

Title: Re: Teensy HHKB Controller (Write up)
Post by: runcom on Tue, 22 July 2014, 12:58:20
The double-sided tape I haven't tried, though it looks like something that would work well. I used some high-temp hot glue, first a small dab underneath the teensy then some lines that rise up on the PCB slightly from the floor of the case. It's held in like a rock and perfectly fits the HHKB hole for the connector.

Have you applied the glue directly under the pcb also?
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Tue, 23 September 2014, 03:34:44
Here's my first pass at my own mod with added USB hub:

(http://i.imgur.com/ftAtIcD.jpg)

The appropriate response to that hotmelt glue job is "THE HORROR, THE HORROR" in your best Colonel Kurtz.

I had to puzzle out the tmk firmware a bit since it's changed quite a bit since the original thread post. Hasu clearly moves fast. Smasher816's write up (http://geekhack.org/index.php?topic=57008.msg1292217#msg1292217) and this DA post (http://deskthority.net/workshop-f7/how-to-build-your-very-own-keyboard-firmware-t7177.html) helped in getting to a working state (and since I'm typing on it now, I declare initial victory).

I'm running a tweaked (both in terms of timings and layers) SpaceFN layout. Really like it so far.

The one thing I want to add to this board is a feature that LOVE on the Leopold FC660M: Escape takes the place of the grave/tilde key, but Shift-Esc still produces a tilde (lesser used grave is banished to fn-Esc). I'm not entirely sure how to proceed in modifying the TMK firmware to produce this result. I'll continue to explore things, but any TMK pros out there that could weigh in would be appreciated.

Also, for anyone looking at the current TMK firmware and not sure what to mod to match Smasher816's pinout, I'm happy to load the relevant files to up to a gist...
Title: Re: Teensy HHKB Controller (Write up)
Post by: abjr on Tue, 23 September 2014, 12:50:46
Very nice!

The one thing I want to add to this board is a feature that LOVE on the Leopold FC660M: Escape takes the place of the grave/tilde key, but Shift-Esc still produces a tilde (lesser used grave is banished to fn-Esc).

In fact I asked hasu this exact question here (http://geekhack.org/index.php?topic=41989.msg1352497#msg1352497). His reply was 2 posts later. Basically it's doable, but I haven't tried it yet.
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Tue, 23 September 2014, 21:35:51
In fact I asked hasu this exact question here (http://geekhack.org/index.php?topic=41989.msg1352497#msg1352497). His reply was 2 posts later. Basically it's doable, but I haven't tried it yet.

Awesome, thanks! I'll give it a go.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Tue, 23 September 2014, 23:21:00
Here's my first pass at my own mod with added USB hub:

Show Image
(http://i.imgur.com/ftAtIcD.jpg)


The appropriate response to that hotmelt glue job is "THE HORROR, THE HORROR" in your best Colonel Kurtz.

I had to puzzle out the tmk firmware a bit since it's changed quite a bit since the original thread post. Hasu clearly moves fast. Smasher816's write up (http://geekhack.org/index.php?topic=57008.msg1292217#msg1292217) and this DA post (http://deskthority.net/workshop-f7/how-to-build-your-very-own-keyboard-firmware-t7177.html) helped in getting to a working state (and since I'm typing on it now, I declare initial victory).

I'm running a tweaked (both in terms of timings and layers) SpaceFN layout. Really like it so far.

The one thing I want to add to this board is a feature that LOVE on the Leopold FC660M: Escape takes the place of the grave/tilde key, but Shift-Esc still produces a tilde (lesser used grave is banished to fn-Esc). I'm not entirely sure how to proceed in modifying the TMK firmware to produce this result. I'll continue to explore things, but any TMK pros out there that could weigh in would be appreciated.

Also, for anyone looking at the current TMK firmware and not sure what to mod to match Smasher816's pinout, I'm happy to load the relevant files to up to a gist...

Interesting project. It does look pretty horrible - but hey, if it works, then it works. Congrats! Somehow I feel there might be a better way by cannibalizing a usb hub and just plugging the teensy into that instead of hacking into the stock board. I'm not sure about that though.

Would you mind making the gist? I actually haven't updated much since I initially flashed the board, so I am still on an older version of the TMK code. So it would be nice to get updated again and update the OP. I could probably figure it out, but no sense in reinventing the wheel if it has already been done before.
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Wed, 24 September 2014, 00:08:37
Interesting project. It does look pretty horrible - but hey, if it works, then it works. Congrats! Somehow I feel there might be a better way by cannibalizing a usb hub and just plugging the teensy into that instead of hacking into the stock board. I'm not sure about that though.

Would you mind making the gist? I actually haven't updated much since I initially flashed the board, so I am still on an older version of the TMK code. So it would be nice to get updated again and update the OP. I could probably figure it out, but no sense in reinventing the wheel if it has already been done before.

I agree. I thought about alternate controllers that could function as a usb hub, but that's outside my past experience and thought I'd just take the "easy" way out and strip down a usb hub.

FWIW, I originally machined an aluminum plate that fit into the HHKB PCB recess, and then mounted different usb plugs to it. Rock solid and perfectly aligned. Then, at around 3am Saturday one of my mini USB pins failed. I was using an otherwise nice, rugged amphenol connector (http://www.digikey.com/product-detail/en/MUSBB55104/MUSBB55104-ND/1956305) which I screw mounted to the HHKB case... looks good and was secure.

Then the smaller usb2.0 four port hub (http://www.amazon.com/gp/product/B00L2442H0) I was using gave out after surviving transplant.

Anyhow, after the mini usb failed, I was going to just hardwire a cable in but then figured I was either going to make this work or I was going to keep trying until it worked, so I just dremeled it (with vacuum suction and a half face respirator, mind). I don't like cutting off options but in this case was very happy with the results.

So I have a replacement hub and the new amphenol mini usb connector coming in and once they arrive I'm going to clean up the hack job. Will also replace the ribbon cable with one that is thinner.

I do agree that there is probably an even nicer way to mount all these, maybe a circuit board (generic or custom).
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Wed, 24 September 2014, 00:16:36
Ohh, I see. I saw the stock controller still in there and just assumed that it was for the hub. But I guess you are using another board for the actual hub features and just using the stock controller for the plugs. You could probably save some space by just buying two usb ports separately and connecting your wires to that (just tack them down with some tape/glue).
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Wed, 24 September 2014, 00:26:15
Ohh, I see. I saw the stock controller still in there and just assumed that it was for the hub. But I guess you are using another board for the actual hub features and just using the stock controller for the plugs. You could probably save some space by just buying two usb ports separately and connecting your wires to that (just tack them down with some tape/glue).

Yes, that was the original plan... here's a quick shot (low quality and that's a teensy 3, not a 2, just for scale) of the parts I'll be putting in (that skinny guy is usb four port).

(http://i.imgur.com/AqYYqQ3.jpg)

I'll post again here once I get the gists up. I think I'll upload the repo as it stands and will try to point out the specific changes I made as well.
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Sun, 05 October 2014, 15:07:11
Here's revision 2 of my HHKB with usb hub. This is more or less the original version I intended, having installed the replacement parts (usb mini in, usb2 four port hub). This also has a thumb drive internally, keeping both external ports available.

(http://i.imgur.com/QLt8xoQ.jpg?1)

I will post the code I'm working on as mentioned previously. Now that this is back together I want to address one or two bugs and then will get the repo online.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Sun, 05 October 2014, 15:31:17
Looking good fog.
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Sun, 05 October 2014, 21:37:19
Here's a minor revision (quick and dirty shield for cable retention) and a shot of the bottom where I put a hole in to do a hard reset on the teensy (for when magic keys aren't enough).

(http://i.imgur.com/hHPw8AD.jpg?1)

(http://i.imgur.com/XK4zoUS.jpg?1)
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Mon, 06 October 2014, 17:48:17
Here's a repo (https://github.com/altercation/tmk_firrmware_hhkb_teensy2) with the current working configuration. I added some notes at the top of the main README. The customized file list (not all critical changes and there is at least one unused keymap in this commit) are listed in this commit:

https://github.com/altercation/tmk_firrmware_hhkb_teensy2/commit/b1725e96a633bdb5ff54d397260b66210cbedead

The critical changes were in:


Note that the bootloader size in Makefile.pjrc is listed as 2048 in that commit. This is probably not correct. I was testing different values as I couldn't get magic keys to successfully reset to the bootloader (they worked other than that). Still not working. Could be a bootloader offset issue or something else.
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Tue, 07 October 2014, 00:36:57
I've just added a first pass custom function to make Esc function like a Leopold FC660M, where pressing Esc normally does just that, while Shift+Esc produces a tilde.

The function and associated keymaps, etc. are in this commit: https://github.com/altercation/tmk_firrmware_hhkb_teensy2/commit/3d8f4f94b5b489796903660e0f21bb5c3445fd72

I don't think it's perfect yet (I've had a couple weird instances where I feel like there is a stuck modifier) but that might not be due to this function. YMMV.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Tue, 07 October 2014, 00:57:46
Very strange. I remember wiring a reply but I don't see it here anyone. Ohh well, I guess I can try to rewrite it.

You got some serious balls to do permanent case mods like that, but it seems to be turning out well. Congrats.

Thanks for the repo, the hhkb_avr.c file will be useful if I ever update the firmware on mine. As far as the magic boot loader reset combo, it works fine with the normal makefilw and the size set to 512 for me. Have you tried that in your pjrc file yet?
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Tue, 07 October 2014, 01:25:25
Very strange. I remember wiring a reply but I don't see it here anyone. Ohh well, I guess I can try to rewrite it.

You got some serious balls to do permanent case mods like that, but it seems to be turning out well. Congrats.

There was probably a glass of red wine involved. Maybe 1.5 glasses. It was a damn the torpedoes moment.

Thanks for the repo, the hhkb_avr.c file will be useful if I ever update the firmware on mine. As far as the magic boot loader reset combo, it works fine with the normal makefilw and the size set to 512 for me. Have you tried that in your pjrc file yet?

Just tried it again. I was also pretty certain that 512 is the correct value, but when I shift+shift+pause with 'sudo hid_listen' running the device disconnects successfully as though rebooting but it never successfully reboots.

Are you using the lufa bootloader instead of the teensy original halfkay? I suspect that might solve this for me, but just a hunch.

Also, I just added another function for those interested, which makes backspace a dual mode key (when shifted, it returns a pipe). Code in my sample keymap here: https://github.com/altercation/tmk_firrmware_hhkb_teensy2/blob/master/keyboard/hhkb/keymap_es.c
Title: Re: Teensy HHKB Controller (Write up)
Post by: hasu on Tue, 07 October 2014, 01:44:41
Nice mod. We seldom see unreversible modification on HHKB like this here, I like your work!

As for modifier stuck, *basically* you should place same modifier(and Fn) on a key position between layers. This rule comes from current TMK keymap design limitation.

I mean, you cannot place LALT there in Layer 2, LCTL should be there instead because you have LCTL on the key on Layer 0. (Line 66) And LANG4, LANG5 and SPC on Line 68 also infringe the rule.

https://github.com/altercation/tmk_firrmware_hhkb_teensy2/blob/3d8f4f94b5b489796903660e0f21bb5c3445fd72/keyboard/hhkb/keymap_es.c#L66

For example,
1) on Layer 0 you press LCTL(and hold it) - <LCTL press event>
2) hold FN1 down to move into Layer 2 - LCTL is still down
3) on Layer 2 you release the ex-LCTL(now LALT) key - this fires just <LALT release event>(not LCTL)


Voila, LCTL is stuck now :) Never occur <LCTL release event> here.


I don't think it's perfect yet (I've had a couple weird instances where I feel like there is a stuck modifier) but that might not be due to this function. YMMV.
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Tue, 07 October 2014, 13:09:08
Nice mod. We seldom see unreversible modification on HHKB like this here, I like your work!

Thanks! I still think going with a custom PCB from you is probably a better route, but I got lucky and everything worked out.

As for modifier stuck, *basically* you should place same modifier(and Fn) on a key position between layers. This rule comes from current TMK keymap design limitation.
...<snip>...
Voila, LCTL is stuck now :) Never occur <LCTL release event> here.

This makes complete sense and is very clear, thank you *so* much, Hasu. I'll rework the layouts based on that.
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Tue, 07 October 2014, 13:56:42
Nice mod. We seldom see unreversible modification on HHKB like this here, I like your work!

Thanks! I still think going with a custom PCB from you is probably a better route, but I got lucky and everything worked out.

But then you would not have had USB support since hasu's pcv doesn't support that and he has no plans on adding it.
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Tue, 07 October 2014, 14:13:46
But then you would not have had USB support since hasu's pcv doesn't support that and he has no plans on adding it.

True, and given my current "laptop" setup (http://imgur.com/oXLJkpP), that usb hub is a requirement when I'm mobile.
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Wed, 08 October 2014, 17:53:20
Here's a snapshot of my keymap with new fixes suggested by Hasu above: https://github.com/altercation/tmk_firrmware_hhkb_teensy2/blob/432fae840fa46aba3fe03d34c8598f1dfe93eaa9/keyboard/hhkb/keymap_es.c

Note that the above link is to a specific commit, so if you are reading this from THE FUTURE you probably should also check the current master for that file (or more likely I've reforked Hasu's repo and am now properly rebasing off it).
Title: Re: Teensy HHKB Controller (Write up)
Post by: deci on Wed, 29 October 2014, 05:59:09
Thanks so much to Smasher for this guide and thanks to Hasu for this great firmware.

Got everything wired up and custom keycodes working without much difficulty.

The amount of cool stuff you can do with TMK is awesome.

Thanks for making this process so painless. I love my hhkb so much more now. ;D
Title: Re: Teensy HHKB Controller (Write up)
Post by: Smasher816 on Wed, 29 October 2014, 18:38:16
Glad it helped. Enjoy your HHKB
Title: Re: Teensy HHKB Controller (Write up)
Post by: pharaoh on Fri, 31 October 2014, 19:45:28
I just stumbled upon this thread, read through all of it, immediately bought the components to try it out.  I can't wait to make my HH  happier!
Title: Re: Teensy HHKB Controller (Write up)
Post by: jdcarpe on Fri, 21 November 2014, 08:19:10
Here's a minor revision (quick and dirty shield for cable retention) and a shot of the bottom where I put a hole in to do a hard reset on the teensy (for when magic keys aren't enough).

Show Image
(http://i.imgur.com/hHPw8AD.jpg?1)


Show Image
(http://i.imgur.com/XK4zoUS.jpg?1)


This mod is awesome! Programmable Teensy controller, USB hub retained (added), and a flash drive, wow. Maybe next you will replace the flash drive with a MicroSD card slot mounted in the side of your HHKB!! :D
Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Sat, 22 November 2014, 13:30:16
This mod is awesome! Programmable Teensy controller, USB hub retained (added), and a flash drive, wow. Maybe next you will replace the flash drive with a MicroSD card slot mounted in the side of your HHKB!! :D

Hey thanks! Big fan of your work!

I think the slot is a great idea. I did look at a couple hubs that also have built in card readers. Maybe will revisit those.
Title: Re: Teensy HHKB Controller (Write up)
Post by: blackvan on Fri, 24 April 2015, 10:37:13
I have the teensy all wired up and installed (great writ up on that front btw) but I am stuck in the programming part. In the OP it says "Open matrix.c and scroll down to this line "#elif defined(__AVR_ATmega32U4__)" but I do not see this line or the quoted init block in matrix.c of the current TMK repo. I see this line mentioned in hhkb_avr.h but the code is not the same as what is in the thread so I am not sure what to change.

Does anything need to be changed or was TMK updated at some point so that this teensy wiring is now included standard? I'm not really a coder so any help would be great.
Title: Re: Teensy HHKB Controller (Write up)
Post by: lifow on Tue, 23 June 2015, 13:53:24
I have the teensy all wired up and installed (great writ up on that front btw) but I am stuck in the programming part. In the OP it says "Open matrix.c and scroll down to this line "#elif defined(__AVR_ATmega32U4__)" but I do not see this line or the quoted init block in matrix.c of the current TMK repo. I see this line mentioned in hhkb_avr.h but the code is not the same as what is in the thread so I am not sure what to change.

Does anything need to be changed or was TMK updated at some point so that this teensy wiring is now included standard? I'm not really a coder so any help would be great.

I'm in the same position. Did you go ahead and try it without any modification? Any luck?

Title: Re: Teensy HHKB Controller (Write up)
Post by: Drew Baumann on Sat, 08 August 2015, 03:26:37
I have the teensy all wired up and installed (great writ up on that front btw) but I am stuck in the programming part. In the OP it says "Open matrix.c and scroll down to this line "#elif defined(__AVR_ATmega32U4__)" but I do not see this line or the quoted init block in matrix.c of the current TMK repo. I see this line mentioned in hhkb_avr.h but the code is not the same as what is in the thread so I am not sure what to change.

Does anything need to be changed or was TMK updated at some point so that this teensy wiring is now included standard? I'm not really a coder so any help would be great.

I'm in the same position. Did you go ahead and try it without any modification? Any luck?



I did the original wiring and spent some time messing around with the files only to have failing results. I looked up the wiring details in Hasu's writeup on github and changed two wires. After that I had success with normal unmodified builds. Attached is an image highlighting the wires I needed to change.
[attachimg=1]

Title: Re: Teensy HHKB Controller (Write up)
Post by: fog on Tue, 20 October 2015, 14:23:47
I've added a cleaned up hhkb_teensy keyboard variant to the current TMK code that targets this modification specifically (replacing the HHKB Pro 2 controller board with a Teensy 2.0).

I've posted it here: https://github.com/altercation/tmk_keyboard/tree/master/keyboard/hhkb_teensy .

I don't know if it's a pull request worthy, but I may submit it to the official TMK project if there is interest.

-Ethan
Title: Re: Teensy HHKB Controller (Write up)
Post by: undersea on Fri, 21 April 2017, 09:29:58
Dear anyone,

Could you please help me this one ?
I am using Teensy 2.0 ++ for Controller of HHKB Pro2. I was successfully with this guide.
Now it isn't stable, I desoldering the pin B0-B6 and F0-F1 & GRD +5V

I solder it with Pin A0-A6 and D0-D1 and another GRD, +5V.

I know I have to re-program and change pin in hhkb_avr.h. I dont know about C++
The teensy PCB could programmed with TMK firmware successfully. But I dont know how to change PIN, PORT, DDR for working.
Now Windows can regconize board, but couldn't type anything.
I use Switch Hitter to test keyboard.

Thanks in advance.
Title: Re: Teensy HHKB Controller (Write up)
Post by: hbar on Mon, 24 July 2017, 03:56:09
I know I'm digging out an old thread here, but I just converted a HHKB to TMK with a Pro Micro board, and I thought this could be useful to people like me who hate loose wires:
[attachimg=1]
What I did was to align the ZH connector (1.5mm pitch), with its pins 2 and 12 already bent towards their friend pins 1 and 13, with the 2.54mm pitch of the contacts on the board as well as possible.  I turns out that three pins (5, 7, and 9) would interfere with their neighbours, so I bent them upward slightly and soldered three wires to them so they connect to the other side of the board:
[attachimg=2]
Of course, VCC and GND aren't in the right place, so we need two more wires to connect them (VCC runs underneath the board, tucked between the PCB and the connector body, so the underside of the assembly is still rather flat).  Now we can keep this board in place with some double-sided tape right behind the DIP-switch cover, the original HHKB cable is long enough to reach there.  One drawback is that the pin assignment is completely random, therefore about 20 lines in the firmware must be changed to accommodate this.  Also, two controller pins are shorted to GND and VCC, respectively, so we better make sure they are configured as inputs.
Title: Re: Teensy HHKB Controller (Write up)
Post by: joric on Thu, 09 May 2019, 16:52:33
Did you make it work or not? I'm trying to do the same but the remapping seems hard. I was going to do something like this but your "random" proximity-based mapping seems more viable :) Maybe I'll use yours. I was mostly doing that for nRFMicro (https://github.com/joric/nrfmicro) and pins on Nordic controllers are all equal so there's no real preference.

Would look somewhat like this (the riser board locks in place without glue):

(https://i.imgur.com/4bNpDLkh.jpg)
Title: Re: Teensy HHKB Controller (Write up)
Post by: joric on Sat, 11 May 2019, 04:05:31
Alternative "Hbar" HHKB Pro 2 - Pro Micro wiring (from the photos above):

(https://i.imgur.com/DrgcnEi.jpg)

Code: [Select]
#define HHKB_PINS_PRO_MICRO_HBAR{ B2, B3, D7, B1, C6, F7, D4, F6, F5 }               /* Pro Micro Hbar */

#define HHKB_PINS HHKB_PINS_PRO_MICRO_HBAR
#undef HHKB_POWER_SAVING

enum {
    HHKB_KEY_PIN = 0,    /* ~KEY: Low(0) when key is pressed (input with pullup) */
    HHKB_KEY_PREV_PIN,   /* HYS: High(1) when key is pressed (output) */
    HHKB_ROW_BIT0_PIN,   /* A(bit0) select row 0-7 (output) */
    HHKB_ROW_BIT1_PIN,   /* B(bit1) select row 0-7 (output) */
    HHKB_ROW_BIT2_PIN,   /* C(bit2) select row 0-7 (output) */
    HHKB_COL_BIT0_PIN,   /* A(bit0) select column 0-7 (output) */
    HHKB_COL_BIT1_PIN,   /* B(bit1) select column 0-7 (output) */
    HHKB_COL_BIT2_PIN,   /* C(bit2) select column 0-7 (output) */
    HHKB_COL_SELECT_PIN, /* ~D(enable) Low(0) enables selected column (output) */
#ifdef HHKB_POWER_SAVING
    HHKB_POWER_PIN,
#endif
#ifdef HHKB_JP
    HHKB_JP_COL_BIT3_PIN,   /* ~Enable of Z2   row0-7  (output) */
    HHKB_JP_COL_BIT4_PIN,   /* ~Enable of Z3   row8-15 (output) */
#endif
/*
    NOTE: Probably HYS changes threshold for upstroke and makes hysteresis in the result.
    NOTE: HYS should be given High(1) when previous KEY state is Low(0).
    NOTE: 1KOhm didn't work as pullup resistor on KEY. AVR internal pullup or 10KOhm resistor was OK.
    NOTE: JP has two HC4051(Z2,Z3) and line 5, 6 and 7 are connected to both of them.
*/
    HHKB_PIN_COUNT
} HHKB_pins_enum;

static const pin_t HHKB_pins[HHKB_PIN_COUNT] = HHKB_PINS;

static inline void KEY_ENABLE(void) { writePinLow(HHKB_pins[HHKB_COL_SELECT_PIN]); }
static inline void KEY_UNABLE(void) { writePinHigh(HHKB_pins[HHKB_COL_SELECT_PIN]); }
static inline bool KEY_STATE(void) { return readPin(HHKB_pins[HHKB_KEY_PIN]); }
static inline void KEY_PREV_ON(void) { writePinHigh(HHKB_pins[HHKB_KEY_PREV_PIN]); }
static inline void KEY_PREV_OFF(void) { writePinLow(HHKB_pins[HHKB_KEY_PREV_PIN]); }

static inline void KEY_POWER_ON(void) {
    writePinHigh(HHKB_pins[HHKB_POWER_PIN]); // MOS FET switch on
    /* Without this wait you will miss or get false key events. */
    _delay_ms(5);                       // wait for powering up
}
static inline void KEY_POWER_OFF(void) {
    writePinLow(HHKB_pins[HHKB_POWER_PIN]);  // MOS FET switch off
}
static inline bool KEY_POWER_STATE(void) { return PORTD & (1<<4); }
#else
static inline void KEY_POWER_ON(void) {}
static inline void KEY_POWER_OFF(void) {}
static inline bool KEY_POWER_STATE(void) { return true; }
#endif

static inline void KEY_INIT(void)
{
    setPinInputHigh(HHKB_pins[HHKB_KEY_PIN]);
    setPinOutput(HHKB_pins[HHKB_ROW_BIT0_PIN]);
    setPinOutput(HHKB_pins[HHKB_ROW_BIT1_PIN]);
    setPinOutput(HHKB_pins[HHKB_ROW_BIT2_PIN]);
    setPinOutput(HHKB_pins[HHKB_COL_BIT0_PIN]);
    setPinOutput(HHKB_pins[HHKB_COL_BIT1_PIN]);
    setPinOutput(HHKB_pins[HHKB_COL_BIT2_PIN]);
    setPinOutput(HHKB_pins[HHKB_COL_SELECT_PIN]);
    setPinOutput(HHKB_pins[HHKB_KEY_PREV_PIN]);
#ifdef HHKB_POWER_SAVING
    setPinOutput(HHKB_pins[HHKB_POWER_PIN]);
#endif
#ifdef HHKB_JP
    setPinOutput(HHKB_pins[HHKB_JP_COL_BIT3]);
    setPinOutput(HHKB_pins[HHKB_JP_COL_BIT4]);
#endif
    KEY_UNABLE();
    KEY_PREV_OFF();
    KEY_POWER_OFF();
}

#define SET_PIN_COND(PIN, COND) if (COND) writePinHigh(PIN); else writePinLow(PIN);

static inline void KEY_SELECT(uint8_t ROW, uint8_t COL)
{
    SET_PIN_COND(HHKB_pins[HHKB_ROW_BIT0_PIN], ROW & 1);
    SET_PIN_COND(HHKB_pins[HHKB_ROW_BIT1_PIN], ROW & 2);
    SET_PIN_COND(HHKB_pins[HHKB_ROW_BIT2_PIN], ROW & 4);

    SET_PIN_COND(HHKB_pins[HHKB_COL_BIT0_PIN], COL & 1);
    SET_PIN_COND(HHKB_pins[HHKB_COL_BIT1_PIN], COL & 2);
    SET_PIN_COND(HHKB_pins[HHKB_COL_BIT2_PIN], COL & 4);
}


Not tested, so try at your own risk.

Upd. regarding that:

Quote
Now we can keep this board in place with some double-sided tape right behind the DIP-switch cover, the original HHKB cable is long enough to reach there.

I found it to be false on my Pro 2 maybe I just haven't tried hard enough maybe my Pro 2 has shorter wires but there's almost no wiggle room and I afraid to damage the cable in process. So I don't know if it's really a viable stragegy to solder the JST connector directly to the Pro Micro. I will use the extender cable.
Title: Re: Teensy HHKB Controller (Write up)
Post by: joric on Sat, 11 May 2019, 17:11:43
Ok. this branch is working and tested. Wired as above.

https://github.com/joric/qmk_firmware/commits/joric-hhkb-promicro

Now I do the BLE thing.

Pics:

(https://i.imgur.com/b36l943.jpg)

(https://i.imgur.com/yXyeiRJ.jpg)

(https://i.imgur.com/8zpIblY.jpg)


TL;DR
Pin mapping is here: https://i.imgur.com/DrgcnEi.jpg
ProMicro version (works fine): https://github.com/joric/qmk_firmware/tree/joric-hhkb-promicro/keyboards/hhkb
nRFMicro version (in progress): https://github.com/joric/qmk_firmware/tree/nrf52-hhkb/keyboards/hhkb_ble
More info here: https://github.com/joric/nrfmicro/wiki/HHKB-BLE