Jump to content
IGNORED

USB Keyboard Adapter w/Arduino style components


jedimatt42

Recommended Posts

 

(Updated May 29, 2016)

 

This is an open source hardware project to use a Teensy 3.x and USB Host shield as an adapter to allow connecting a USB Keyboard to a TI-99/4a console.

 

instructions: http://ti994a.cwfk.net/TiUsbKeys.html

source: https://github.com/jedimatt42/TI-99-usb-keys

 

The project was then extended with alternate firmware for the Teensy micro-controller, to act as a USB to XT keyboard adapter for the Myarc Geneve 9640.

 

instructions: http://ti994a.cwfk.net/UsbGeneve.html

source: https://github.com/jedimatt42/teensyUSBtoXT

 

My presentation on the topic at PNW Fest West 2016 (Video by: Omega):

 

-M@

 

----------- Original First Post -------------

 

I've been working on a USB keyboard adapter.

 

This is an adapter that accepts USB keyboard input and connects to the TI matrix keyboard connector to allow using your favorite USB keyboards with your real iron TI console.

 

I have it working pretty well as of last night. I'm using a Teensy 3.1 which is 5v tolerant with lots of GPIO pins. and a mini USB Host shield from Circuits@Home.

 

My source for the Teensy is here:

 

https://github.com/jedimatt42/TI-99-usb-keys

 

It is a ways from polished. Current problems are:

 

I think I have a short, such that the '.' produces either a '.' or a '/' and when held down produces a continuous stream of them since it can't decide which it wants to be.

 

function-= goes back to the cyan screen, but stays there.

 

And then I want to add mappings for all the fun extra keys like arrows and stuff. :)

 

I have a question about the TI and alpha-lock:

 

Is there ever a difference between shift-S, and the alpha-lock being down and someone pressing s?

 

I know there is a technical difference in the hardware. The alpha-lock has it's own 'column' that comes from the 9901, instead of the decoder chip the other 'columns' come from. And alpha-lock is not a shift-lock... But what I'm getting at: is there any practice of programmers measuring if the alpha-lock is down or not? or accepting a 's' with the alpha-lock down, but not accepting a shift-s?

 

What I'd like to do is just through in a shift for free (as appropriate) if the caps-lock key is on in the USB keyboard, and ignore the input for the alpha-lock.

 

This whole thing will never, by my hand, be as inexpensive as Tursi's PS/2 adapter, since I'm starting with 2 parts that were about $20 apiece. But it is fun :)

 

There is a bunch of potential here with these parts... The USB Host library supports Bluetooth HID keyboards too.. so it isn't much of a code change to use a little bluetooth nub. And, with just 1 or maybe 2 wires from the joystick port, a HID gamepad could be mapped to the joystick with keyboard assignments for the extra buttons.

 

Pictures:

 

https://goo.gl/photos/xhLKCTwCPuAeUbP86

 

-M@

  • Like 2
Link to comment
Share on other sites

Damn, I'm impressed, that looks like a lot of fun! ;-)

It's nice to see someone having a blast with something new on the hardware side of things!

 

gallery_35324_1027_178425.jpg

 

It'll be neat to see the finished project, maybe something with the components attached to a single PCB that'll fit into the console and a PDF file with assembly instructions. :thumbsup: That should work with one of the new USB wireless keyboards!

Link to comment
Share on other sites

It's good to hear you are having so much progress!

 

When you're interested, feel free to drop me a PM. There were a number of non-technical issues that I needed to solve to cleanly map the PS/2 keyboard to the TI keyboard (the handling of meta keys and ensuring that keys are pressed and released appropriately). I feel the current solution works pretty well, but it too a few iterations.

 

When you're at that point, I'll take a dig through the code history and try to remember the various issues I faced. :)

  • Like 1
Link to comment
Share on other sites

As for cost... the Teeny is an AVR too. It would be possible to start with a raw AVR and port your code (most likely). :)

 

The Teensy 3.1 actually supports USB Host mode with OTG cables, but the libraries aren't there yet. :) So using the USB Host shield gets me a lot of free software to build off of.

  • Like 1
Link to comment
Share on other sites

It's good to hear you are having so much progress!

 

When you're interested, feel free to drop me a PM. There were a number of non-technical issues that I needed to solve to cleanly map the PS/2 keyboard to the TI keyboard (the handling of meta keys and ensuring that keys are pressed and released appropriately). I feel the current solution works pretty well, but it too a few iterations.

 

When you're at that point, I'll take a dig through the code history and try to remember the various issues I faced. :)

 

Will do. Thanks! I've had a couple interesting symptoms so far, with the FCTN =, and haven't tried to utilize special keys.

 

It looked like FCTN = is extremely early in the scan from the TI's point of view, and my current scheme won't clear keys except during the interrupt triggered when a column pin is falling. That doesn't seem to be soon enough. :) It works great from fbForth, which appears to have the TI interrupt that scans for FCTN= turned off (or something like that.)

Link to comment
Share on other sites

Check this out. It's a TI 99/4A USB keyboard interface using a Teensy 2++: Comprehensive tutorial with code http://www.instructables.com/id/RaspTI-Convert-a-Vintage-Computer-TI-994A-into/#step1.

You can easily substitute a Teensy 3.1 here.

 

that's going the other way, though, that's turning a TI keyboard into a USB keyboard.

Link to comment
Share on other sites

It looked like FCTN = is extremely early in the scan from the TI's point of view, and my current scheme won't clear keys except during the interrupt triggered when a column pin is falling. That doesn't seem to be soon enough. :) It works great from fbForth, which appears to have the TI interrupt that scans for FCTN= turned off (or something like that.)

 

It's actually a completely separate test that does only the single column. For full compatibility, you can't make any assumptions about order or sequence of scans. Because it's done by software, literally anything goes. In my PS/2 adapter I maintain a virtual TI keyboard - the state of the array is updated by key events, otherwise the columns are continuously polled with the row data correspondingly output (I didn't have enough interrupt pins to use interrupts for the column changes - that's the main reason it's clocked so high).

 

The main issues I had were related to keys that used one meta key on the PC and a different meta key on the TI, for instance the tilde (which is a shift key on the PC, and a FCTN key on the TI). I have to admit that in the end I eliminated a lot of issues by not mapping the shift key straight through, rather I had a PC keyboard map and a shifted PC keyboard map, and used the state of the PC shift key to decide which map to use. (For the rare but existing case that needs a real shift on the TI, I mapped the Windows key to shift). Then it was just a matter of properly tracking when to activate and when to release the meta keys for smooth operation - that's the stuff I'd have to look up. :)

Link to comment
Share on other sites

It's actually a completely separate test that does only the single column. For full compatibility, you can't make any assumptions about order or sequence of scans. Because it's done by software, literally anything goes.

Last night I was ranting about maybe ordering this or that to make it align with the TI scanning code. Good to know that would be a waste of time.

 

 

In my PS/2 adapter I maintain a virtual TI keyboard - the state of the array is updated by key events,

I'm doing the same.

 

(I didn't have enough interrupt pins to use interrupts for the column changes - that's the main reason it's clocked so high).

I do have interrupt available on all gpio pins, so I've started with the approach of an interrupt per column as it is falling. This mostly works, but right now the way I'm changing output pin state, I think is too expensive. And I'm missing some interrupts, or not getting the pin state set quick enough, such that the repeat status sees a miss and thinks I'm pressing the key many times.

 

 

The main issues I had were related to keys that used one meta key on the PC and a different meta key on the TI, for instance the tilde

I think I've got those covered. shift [ is actually fctn f... https://github.com/jedimatt42/TI-99-usb-keys/commit/c225c3323b6e4e6428cc9b24ee1fa37c48c36e27

If it is one of the special combinations, handle it, and only run the simpler mapping if it wasn't handled.

 

I just realized, I don't support someone just holding the shift key down or the fctn or ctrl key... so I get to iterate :)

 

 

I've added a schematic to the google album... I'm treating each board as a big IC.

post-42954-0-95044100-1442510733_thumb.png

 

  • Like 2
Link to comment
Share on other sites

I was able to fix the repeating keys by sacrificing not-interfering with the built-in keyboard, but I can approach that differently. My code that ran in the interrupts was indeed too expensive.

 

Also I'd like input on what a few keys should do with:

 

F10 - is Fctn 0 a thing?

F11

F12

 

INS - I have tentatively set to Editor Assembler's Insert Char

DEL - same, E/A's Delete Char

PGUP

PGDN

HOME

END

TAB - E/A's tab

 

All of the other keys seemed really straightforward/obvious ... arrows are arrows :) backspace is left arrow. ESC is Fctn 9.

 

I'd love to actually just copy the Classic99 keymap, but I haven't found that enumerated any where.

 

-M@

Link to comment
Share on other sites

Here are the notes for my PS/2 adapter (which is the code that Classic99 runs):

 

 

Scroll Lock has a function that is not quite intuitive - it toggles the mode of the arrow keys. When scroll lock is OFF, the arrow keys function as though you pressed FCTN-E/S/D/X. When scroll lock is ON, the arrow keys simply return E/S/D/X, and so may be used in games and other programs for navigation.

 

Alt maps to FCTN, although it should be rarely needed now. The old keymaps should mostly still work (ie: ALT-I will return a question mark!) Alt-Equals will still be quit. The editor keys are based on the mappings used in the TI Editor/Assembler package and TI BASIC. Some of these mappings may not be available to BASIC (for example, Page Down is FCTN-4, so it will terminate a BASIC program). Likewise for F4.

 

As a side effect of the ref-counting and mapping code, SHIFT on the PS2 keyboard does NOT map directly to SHIFT on the TI side. Normally this is transparent, but some devices, such as the Horizon RAMdisk, use holding SHIFT as an indication to bypass boot code. If you need this functionality, use the Windows key on a Windows keyboard - this maps directly to the TI SHIFT key. Note your keyboard must be able to start up quickly enough to beat the RAMdisk boot, but most seem to.

 

Extended Keys:

PC Key          TI Keys
--------------  -----------------------------------
Up Arrow        FCTN-E (see note above on Scroll Lock)
Down Arrow      FCTN-X (see note above on Scroll Lock)
Left Arrow      FCTN-S (see note above on Scroll Lock)
Right Arrow     FCTN-D (see note above on Scroll Lock)
Tab             FCTN-7
F1              FCTN-1
F2              FCTN-2
F3              FCTN-3
F4              FCTN-4
F5              FCTN-5
F6              FCTN-6
F7              FCTN-7
F8              FCTN-8
F9              FCTN-9
F10             FCTN-0
Insert          FCTN-2
Delete          FCTN-1
Page Down       FCTN-4
Page Up         FCTN-6

Also, a number of keys with no direct analogy were mapped into control keys for use with a TI program, if you choose to use them. Test them first as they are not guaranteed the same on all keyboards (or to even exist for that matter!).

Left Windows  Shift (use this for RAMdisk boots, etc)
Right Windows Shift (use this for RAMdisk boots, etc)
F11           CTRL-1
F12           CTRL-2
Home          CTRL-U
End           CTRL-V
Esc           FCTN-9 (back)
WWW Search    CTRL-N
Print Screen  CTRL-A
WWW Favorites CTRL-T
WWW Refresh   CTRL-S
Volume Down   CTRL-I
Mute          CTRL-G
WWW Stop      CTRL-R
Calculator    CTRL-L
Windows Apps  CTRL-Z
WWW Forward   CTRL-Q
Volume Up     CTRL-H
Play/Pause    CTRL-F
Power         CTRL-C
WWW Back      CTRL-P
WWW Home      CTRL-O
Stop          FCTN-4
Sleep         CTRL-D
My Computer   CTRL-M
EMail         CTRL-K
Next track    FCTN-6
Media Select  CTRL-J
Wake          CTRL-E

Pressing ALT+F9 through ALT+F12 will toggle GPIO pins on my controller - this can be used for reset, load interrupt, etc.

 

And finally, Control+Alt+Delete reboots my controller, just in case the keyboard state becomes inconsistent. ;)

 

Docs and source are on my page for the PS/2 controller.

Edited by Tursi
Link to comment
Share on other sites

Here are the notes for my PS/2 adapter (which is the code that Classic99 runs):

 

As a side effect of the ref-counting and mapping code, SHIFT on the PS2 keyboard does NOT map directly to SHIFT on the TI side. Normally this is transparent, but some devices, such as the Horizon RAMdisk, use holding SHIFT as an indication to bypass boot code. If you need this functionality, use the Windows key on a Windows keyboard - this maps directly to the TI SHIFT key. Note your keyboard must be able to start up quickly enough to beat the RAMdisk boot, but

 

Since the Horizon Ramdisk OS can now be easily modified ;) if you have a suggestion for a PS/2 friendly key or routine, there stands a good chance a change can be made. Coincidentally, a similar challenge exists with the Geneve's XT keyboard and any direct-scan routines, so your PS/2 is not "alone". ;)

Edited by InsaneMultitasker
Link to comment
Share on other sites

 

Since the Horizon Ramdisk OS can now be easily modified ;) if you have a suggestion for a PS/2 friendly key or routine, there stands a good chance a change can be made. Coincidentally, a similar challenge exists with the Geneve's XT keyboard and any direct-scan routines, so your PS/2 is not "alone". ;)

 

This solution has worked fine for me for almost 10 years now, I don't think there's any need to change anything. :)

  • Like 1
Link to comment
Share on other sites

The keyboard mapping has come along nicely.

 

I've figured out caps-lock. So far everything co-exists nicely with the built-in keyboard. I believe this is due to my micro controller output pins being in OPENDRAIN mode.

I've been able to fix my Fctn-= behavior. It seems the TI doesn't soft-reset nicely unless I make sure I stop driving the 9901 input pins low.

 

The ctrl-alt-del to reboot the adapter is genious... Really improves my dev cycle!

 

The only bug I have right now comes in the form of occasional SHIFT-LOCK. which clears up with the ctrl-alt-del. But I'm hoping to fix that as I work out how to simulate holding the shift key with nothing else pressed (not a bug yet). I think I can manage that without forcing any alternative behavior on the user.

 

For grins and giggles, I tried out expresspcb software to layout a board that takes care of all the wiring. It's up on the github site:

https://github.com/jedimatt42/TI-99-usb-keys/blob/master/TIUSBKeys.pcb?raw=true

 

I truly don't know anything about that yet... so I ignored the fact that I don't know pad sizes and trace sizes... That was interesting though. It is a lot like opening the vault in TODs lower levels... If anyone wants to generously take a look and offer feedback, I'm all ears. (or eyes, as is the case) Might be too early for that though... I haven't labelled things, and I've barely googled the topic..

 

Question for the forum: Can you help me prioritize wireless receiver support?

 

I have a bluetooth nub, and a couple bluetooth keyboards. I can probably get that to work with the USB Host Shield library, as it supports some bluetooth hid. It looks like just some initialization differences, provided the pin 0000 works for your keyboard. But frankly, I use bluetooth keyboards only with my day-job machines. And wouldn't wish them on anyone. So then there are things like Logitech's little nano receivers, and HP has a similar proprietary situation.

 

So, I'll have to pick up a device to test this with. I'd like to aim at the Logitech technology, but since I personally don't want to use wireless ( my end game is a kvm, for the k part, I am however excited by the idea of enabling wireless ) I want to focus this investment. Anyone opposed to Logitech nano receivers?

 

I still have to test with my kvm, and my actual target keyboard. http://www.amazon.com/Happy-Hacking-Keyboard-Lite2-Black/dp/B0000U1DJ2/ref=sr_1_1?ie=UTF8&qid=1442808323&sr=8-1&keywords=happy+hacking+keyboard+lite+2

 

-M@

Link to comment
Share on other sites

Make sure you test with games. After I got the basics working nicely, I found that the holding of keys down and overlapping keys often used for gaming introduced some additional issues. (At least you probably won't have the issue of dealing with various keyboards with slightly different sample points, since USB is better spec'd than PS/2 ;) )

Link to comment
Share on other sites

I want it inside my console, and I don't want to 'wire' it by hand. While I have a Ksarul enhanced layout, It isn't final. I have an intermittent interfacing problem to work out still with some ghosty shift-lock behavior. I hope that is all to do with sketchy software on my end. But I need to pin it down before I get too serious about running boards. My intention is that when I do for myself, I'll make extras.

 

post-42954-0-70536000-1442866583_thumb.jpg

 

I also want to add hid gamepad support and the ability to hot-plug between keyboard and gamepad. But I haven't tested that yet, and it isn't in the layout. It should just be adding another 'column' to the virtual keyboard for player-1 joystick, and mapping the dpad and analog stick to the directions, and then fire button, and good candidates for the other half dozen buttons. 1, 2, 3, REDO, BACK...

 

And to Tursi's point of testing games: I've worked through a few. But hadn't focused on key combo support... I'll do some testing there. I'd like to write something that visualize the entire keyboard matrix on the TI, and lets me scan in different modes, as well as crazy manual 9901 manipulations. I don't have anything that tests holding shift down and stuff like that. I've started working on something in fbForth for this.

 

-M@

  • Like 2
Link to comment
Share on other sites

I attached a LED to the teensy that only lights when the virtual keyboard thinks it has the shift key down... and that quickly pointed the finger at my code, as the virtual keyboard state had shift when the ghostly shift-lock was in play. So that's good knews.

 

On the update front, I've implemented num-lock, and scroll-lock now.

I assume people would like num-lock to be on by default? That's what I'm planning to setup.

My desired start up state:

caps-lock on, cause Tursi (below) is totally right,

scroll-lock off,

num-lock on.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...