Author Topic: TMK PS/2 to USB keyboard converter  (Read 185277 times)

0 Members and 1 Guest are viewing this topic.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #100 on: Thu, 12 January 2012, 04:24:32 »
REVENGE, thanks for the link.

Hmm, those waveform will not work with my converter on Teensy too. I think AVR USART hardware can handle that fast signal without timing problem.

While my Teensy converter uses PS/2 handler implemented with software(poor my C lang), V-USB converter uses this USART hardware to reduce cycles for PS/2 handling. Of course you can use the USART hardware on Teensy too.

You have two option to take: building a V-USB converter or using USART on Teensy one.
 Looking these files will help you.
ps2_usb/Makefile.vusb
ps2_usb/config_vusb.h
ps2_usart.c

Offline REVENGE

  • Posts: 568
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #101 on: Thu, 12 January 2012, 10:05:26 »
Quote from: hasu;488527
REVENGE, thanks for the link.

Hmm, those waveform will not work with my converter on Teensy too. I think AVR USART hardware can handle that fast signal without timing problem.

While my Teensy converter uses PS/2 handler implemented with software(poor my C lang), V-USB converter uses this USART hardware to reduce cycles for PS/2 handling. Of course you can use the USART hardware on Teensy too.

You have two option to take: building a V-USB converter or using USART on Teensy one.
 Looking these files will help you.
ps2_usb/Makefile.vusb
ps2_usb/config_vusb.h
ps2_usart.c
Roger that, I'll be looking into this, thanks! :D
◕ ‿ ◕

Offline REVENGE

  • Posts: 568
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #102 on: Fri, 13 January 2012, 01:05:23 »
So, I haven't figured out how to work your PS/2 via USART implementation, but I did build the Teensyduino PS2Keyboard implementation and it seems to work fine in serial mode. In fact, that thing also seems to work just fine with my set 3 terminal model F. Any limitations to using this as the basis for a converter?
◕ ‿ ◕

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #103 on: Fri, 13 January 2012, 03:25:25 »
I just looked over PJRCs' PS2Keyboard source. It uses an interrupt routine for PS/2 handling instead of USART hardware I meant, and seems to support only Code Set 2. (Code Set 2 and 3 shares same code of alpha/numeric keys, but as for modifier, function key and etc. codes differ.)
I think USART implementation has no limitations at all except that you can't use USART function for another.


I can come up with three implementation method to handle the PS/2 signal.
1. simple and stupid wait & read loop(intensive use of cpu cycles)
2. Interrupt(a few use)
3. USART hardware(not use at all)

I used method 1. to implement my converter on Teensy and it was OK in most case.
I used method 3. to implement my converter with V-USB because it uses clock cycles intensively and very timing sensitive. I could not use even method 2 with V-USB due to very tight timing issue.

Offline REVENGE

  • Posts: 568
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #104 on: Sun, 15 January 2012, 04:15:19 »
Hmm, do you have any hints for using the USART implementation with Teensy? I think I've changed the registers in the config header file to the ones used by the 32u4, but I get nothing, and I have no idea how to debug it either. :(
◕ ‿ ◕

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #105 on: Sun, 15 January 2012, 09:50:58 »
I added some files to support USART implementation.

Try latest source and do 'make -f Makefile.pjrc_usart'.
Note that pin configuration for this is different from 'simple and stupid' one. Connect Clock line to PD5 pin and Data to PD2.
« Last Edit: Sun, 15 January 2012, 09:53:31 by hasu »

Offline REVENGE

  • Posts: 568
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #106 on: Sun, 15 January 2012, 13:03:35 »
Quote from: hasu;491025
I added some files to support USART implementation.

Try latest source and do 'make -f Makefile.pjrc_usart'.
Note that pin configuration for this is different from 'simple and stupid' one. Connect Clock line to PD5 pin and Data to PD2.
Sweet, getting it now to build. For the makefile and config, I actually had almost exactly the same thing as you (even named the files the same, teehee....) except my pin defs are different. I'm guessing I can't customize those and have to use what you set?
◕ ‿ ◕

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #107 on: Sun, 15 January 2012, 13:07:10 »
Right. USART pins are fixed depending on MCU and my configuration is for Teensy(ATmega32U4).

Offline REVENGE

  • Posts: 568
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #108 on: Sun, 15 January 2012, 13:19:44 »
Nevermind, I'm being dumb.
« Last Edit: Sun, 15 January 2012, 13:26:17 by REVENGE »
◕ ‿ ◕

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #109 on: Sun, 15 January 2012, 13:27:02 »
F2 is not present on ATMega32U4(Teensy 2.0).
But why do you find F2? you need D2 and D5 as I described before.
You need sleep? Me too :) I got to go to bed now.

Offline REVENGE

  • Posts: 568
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #110 on: Sun, 15 January 2012, 13:43:28 »
Quote from: hasu;491132
F2 is not present on ATMega32U4(Teensy 2.0).
But why do you find F2? you need D2 and D5 as I described before.
You need sleep? Me too :) I got to go to bed now.
No, I needed to wake up and start paying attention, that's what. :P

Yeah, so it seems to work fine! Good stuff. The lock keys respond a little sluggishly, but I'm guessing that's because there're still some LED stuff going on? Is it even possible to support lock LEDs?
◕ ‿ ◕

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #111 on: Sun, 15 January 2012, 13:58:03 »
Nice!

Ah... USART is only for receiving, unfortunately it still uses 'simple and stupid' method to send command like SET LED(converter->keyboard communication).
It seems to have the timing issue when sending to the keyboard.

This patch might cure the problem by some chance. Try this.
Code: [Select]
diff --git a/ps2_usart.c b/ps2_usart.c
index 7d591c6..7160f57 100644
--- a/ps2_usart.c
+++ b/ps2_usart.c
@@ -127,7 +127,7 @@ uint8_t ps2_host_send(uint8_t data)
     WAIT(clock_lo, 15000, 1);
     /* data [2-9] */
     for (uint8_t i = 0; i < 8; i++) {
-        _delay_us(15);
+        _delay_us(1);
         if (data&(1<<i)) {
             parity = !parity;
             data_hi();
@@ -138,12 +138,12 @@ uint8_t ps2_host_send(uint8_t data)
         WAIT(clock_lo, 50, 3);
     }
     /* parity [10] */
-    _delay_us(15);
+    _delay_us(1);
     if (parity) { data_hi(); } else { data_lo(); }
     WAIT(clock_hi, 50, 4);
     WAIT(clock_lo, 50, 5);
     /* stop bit [11] */
-    _delay_us(15);
+    _delay_us(1);
     data_hi();
     /* ack [12] */
     WAIT(data_lo, 50, 6);

Offline REVENGE

  • Posts: 568
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #112 on: Sun, 15 January 2012, 15:54:29 »
Hmmzord, I'll try the patch later tonight. A more immediate problem is that I need to solder something (wire, pin, whatever) to D5 -  I'm using my hand to touch a wire to the contact and to do testing (:-/). Another crazy idea: would it be possible to use one of the digital pins exclusively to send lock LED commands to the keyboard? From what I understand, using the UART / USART is independent of regular programming.
◕ ‿ ◕

Offline mich

  • Posts: 156
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #113 on: Sat, 21 January 2012, 04:53:23 »
Hi, does anybody know if this software will fit onto an AT90USB162 (16k flash, 512 ram)?

I can buy either AT90USB162 or ATmega32U4, but I'd prefer the smaller one.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #114 on: Sat, 21 January 2012, 07:27:32 »
mich,
I built binary with default configuration for at90usb162 though I have no chip to program and try.
I think this will fit on the chip and also you can reduce size by removing unused keymaps and functions.
Code: [Select]
  text    data     bss     dec     hex filename
  13734      18     114   13866    362a ps2_usb_pjrc.elf


REVENGE,
Did you try my patch? I want to hear the result. thanks.

Offline Soarer

  • * Moderator
  • Posts: 1918
  • Location: UK
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #115 on: Sat, 21 January 2012, 07:34:16 »
Until fairly recently my converter worked on a '162. The limiting features are: only 512 bytes of RAM, and only 4 USB endpoints.

Offline REVENGE

  • Posts: 568
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #116 on: Sat, 21 January 2012, 16:16:41 »
Quote from: hasu;495472
REVENGE,
Did you try my patch? I want to hear the result. thanks.
Weird, I thought I posted already...

It mostly works, but there are a few quirks. For some reason, the forward slash key does not work consistently. Sometimes it makes, but doesn't break, sometimes it doesn't repeat, sometimes it doesn't work at all. On my other PS/2 to USB converter and native PS/2, it works fine. This is with regards to the Monterey.
◕ ‿ ◕

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #117 on: Sat, 21 January 2012, 18:56:11 »
Thanks.
The patch seems to cure the LED problem.

As for wierd key things, it is probably not a real bug or problem.
To activate cursor keys and mouse keys keymap layers, '/' and ';' are used as Fn key and normal key at same time.
Try '/' + hjkl to move cursor and ';' + hjkl to move mouse cursor. See the article page or keymap.c for detail.

This incur some side effects, as you described these keys has no key repeating and a legend is registered on key released not pressed.
(To register key you must press and release the key in about 200mS and to repeat key you can double tap the key and hold in that time.)
These side effects are not occurred on dedicated Fn keys. You can use unused key for this such as right windows key or something.

These functions might impose frustration on you in some situation.
This default keymap is just to demonstrate the functions of my firmware, you can change this keymap by editing keymap.c.
Or pressed LShift + RShift + 1 to switch normal QWERTY keymap without these Fn keys temporarily.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #118 on: Wed, 04 December 2013, 10:05:20 »
I updated this project to support my DIY hardware. Fixed some bugs and add improvements.
https://github.com/tmk/keyboard_converter

Pic of herd of converters.
« Last Edit: Wed, 04 December 2013, 10:08:37 by hasu »

Offline jdcarpe

  • * Curator
  • Posts: 8852
  • Location: Odessa, TX
  • Live long, and prosper.
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #119 on: Wed, 04 December 2013, 10:11:06 »
USB-to-USB converter possible?
KMAC :: LZ-GH :: WASD CODE :: WASD v2 :: GH60 :: Alps64 :: JD45 :: IBM Model M :: IBM 4704 "Pingmaster"

http://jd40.info :: http://jd45.info


in memoriam

"When I was a kid, I used to take things apart and never put them back together."

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #120 on: Wed, 04 December 2013, 10:31:25 »
Everything is possible :) My firmware doesn't support atm, though.

If you are interested in technical info...
This thread at DT:
http://deskthority.net/workshop-f7/is-remapping-a-usb-keyboard-using-teensy-possible-t2841.html
and code:
https://github.com/tmk/tmk_keyboard/tree/master/converter/usb_usb
It has stoped at very early stage of devlopement for long time.

Offline bcg

  • Posts: 112
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #121 on: Fri, 06 December 2013, 20:50:51 »
I updated this project to support my DIY hardware. Fixed some bugs and add improvements.
https://github.com/tmk/keyboard_converter

Pic of herd of converters.
Show Image


Nice.  Real nice.   :thumb:
:wq!

Offline gropingmantis

  • Posts: 77
  • Location: United Kingdom
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #122 on: Tue, 28 January 2014, 15:45:32 »
oops wrong thread
« Last Edit: Sat, 01 February 2014, 03:05:00 by gropingmantis »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #123 on: Thu, 13 November 2014, 14:39:31 »
I merged a pull request of fix for V-USB version. Thank you, 0mark.

https://github.com/tmk/tmk_keyboard/pull/142

Offline ryansoh3

  • Posts: 4
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #124 on: Wed, 19 November 2014, 23:03:15 »
Hats off to hasu for the awesome project.

Any particular reason why V-USB doesn't support System/Media control protocols?

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #125 on: Wed, 19 November 2014, 23:16:37 »
No reason. V-USB is awesome library you can support various USB functions including NKRO, those protocols. (TMK doesn't support NKRO with V-USB atm.) TMK's V-USB code supports System/Media key usages.
https://github.com/tmk/tmk_keyboard/blob/master/protocol/vusb/vusb.c#L337

But I've not used V-USB myself and not updated its code for long time, I'm not sure it still works.

Offline ryansoh3

  • Posts: 4
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #126 on: Thu, 20 November 2014, 00:55:58 »
Ah, thanks. I thought both NKRO and Sys/Media control wasn't supported because it said

Quote
The converter on V-USB lacks some features for now: USB NKRO and System/Media control.

Under USB Support https://github.com/tmk/tmk_keyboard/tree/master/converter/ps2_usb

Offline ryansoh3

  • Posts: 4
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #127 on: Sun, 23 November 2014, 12:10:07 »
Hey hasu,

I was able to setup my PS/2 to USB converter thanks to your code.

Now I have a fully functional Dell AT101W via an ATMega328P via VUSB. :)

Just wondering, how do I get the keyboard to be able to wake the computer from sleep?
With a Logitech Keyboard, I see the Power Management tab under Device Properties in Windows, but no tab for the Converter.

Does it have to do with missing Power Data and Power Capabilities info?

Plus under
Code: [Select]
powercfg -devicequery wake_armed in CMD the Converter isn't listed... meaning that it doesn't support wake from sleep.

Thanks!

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #128 on: Sun, 23 November 2014, 17:16:22 »
Glad to hear it works!

TMK VUSB doesn't support remote wakeup feature unfortunately while LUFA and PJRC stack support.

It is definitely possible to implement the feature on V-USB, but I have no time and plan  to do so for a while.

Offline ryansoh3

  • Posts: 4
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #129 on: Mon, 24 November 2014, 00:24:44 »
Gotcha, thanks for the info mate. :)

Offline UFOnet

  • Posts: 2
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #130 on: Tue, 25 November 2014, 16:19:11 »
Hi there.
Is it possible to use this project also with Arduino Leonardo?

Thanks.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #131 on: Tue, 25 November 2014, 17:11:44 »
yes, it works.

Offline Lubed Up Slug

  • Posts: 79
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #132 on: Tue, 25 November 2014, 22:16:40 »
lol wrong thread sorry
« Last Edit: Tue, 25 November 2014, 22:22:25 by Lubed Up Slug »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #133 on: Tue, 25 November 2014, 22:26:39 »
First, with this converter you never need any diodes. Maybe, you are in wrong thread.

Make sure your keymap is clean and plain without fancy functions. And check your hardware.


EDIT: oops, I'm too quick :D

Offline UFOnet

  • Posts: 2
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #134 on: Wed, 26 November 2014, 04:09:49 »
Hi there.
Is it possible to use this project also with Arduino Leonardo?

Thanks.

yes, it works.

Thanks for answer. And is it possible to programm it without loosing arduino bootloader?
Is it possible to programm it via serial port or ISP programmer is needed.

Could you, please, post some instruction how to do it? I`m real beginner.

Thanks.
« Last Edit: Wed, 26 November 2014, 04:18:05 by UFOnet »

Offline robercik

  • Posts: 1
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #135 on: Sat, 21 February 2015, 13:49:45 »
Glad to hear it works!

TMK VUSB doesn't support remote wakeup feature unfortunately while LUFA and PJRC stack support.

It is definitely possible to implement the feature on V-USB, but I have no time and plan  to do so for a while.

This is done in my project of clean keyboard and mouse translator with atmega328p:

https://github.com/robszy/ps2usb

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #136 on: Sat, 21 February 2015, 15:29:22 »
Thanks. I'll look into later.

Offline Yeitso

  • Posts: 10
  • Location: Sweden
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #137 on: Mon, 16 March 2015, 04:12:24 »
Can't seem to get this to work. Im using a Pro Micro and have Data hooked up to PD1 and clock to PD0 and nothing happens when i hook up the converter exept it shows up in my hardwarelist as a keyboard.
I've added a 4K pull-up resistor to the data line from VCC and that made the keyboard light up when i hooked it up but its still not working. Do I need a pul-up resistor on the clock line aswell?

Ive changed the PS2_DATA_BIT to 1 and PS_CLOCK_BIT to 0 in the config on USART as the Pro Micro does not have PD5 (it does but thats one of the internal leds).

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #138 on: Mon, 16 March 2015, 13:06:56 »
Use two pullup resistors on both signal lines, just in case.
You can't use PS2_USART on Leonardo and Pro Micro, use PS2_BUSYWAIT(or PS2_INT) instead. In particular PS2_BUSYWAIT works with any pin combination, it would be useful. Also PS2_INT works for your pin configuration.

It seems people are confused by flexible pin configuration and variation of protocol implementations, If I have  time I'll change pin usage same as Soarer's and use busywait impl by default to allow users chaging pins freely.

Offline lmorchard

  • Posts: 10
  • Location: Ferndale, MI, US
  • {web,mad,computer} scientist
    • lmorchard.com
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #139 on: Tue, 02 February 2016, 13:24:22 »
Don't have a lot to say in this thread yet - except for thank you!

I just got a few IBM Model M keyboards from a friend of mine. So, I ran down to the local Microcenter, bought a Teensy 2.0. I sacrificed an old PS/2 extension cable I had lying around, and 10 minutes later I had everything wired up. Installed the toolchain and had the firmware running in another 15 minutes.

It's rather ugly, but I've got this all hooked up to my Mac and I'm happily tweaking the key maps to swap in more useful keys. Hoping to wrap my head around the source code some more to see if maybe there's anything more interesting I can do! I might also try embedding a Teensy in one of these keyboards, just to make everything cleaner.

Again, thanks for your work!

126708-0

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #140 on: Tue, 02 February 2016, 19:56:57 »
Great, glad to hear it works for you!
Enjoy both clicky springs and snappy domes :D

Offline Newbie75

  • Posts: 2
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #141 on: Wed, 09 March 2016, 17:36:02 »
Hi, is it also possible to use teensy 2.0 vice versa. So that I can connect my usb-keyboard via teensy to the ps/2 input of my computer? And furthermore, will your firmware provided work with this?

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #142 on: Wed, 09 March 2016, 18:12:41 »
No.
1) Teensy 2.0 doesn't support USB keyboard input.
2) My firmware doesn't support PS/2 output.

Offline Newbie75

  • Posts: 2
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #143 on: Thu, 10 March 2016, 11:46:11 »
Thanks a lot for your reply..  ;)  Do you know a way to realize this? Because despite USB-connectivity of my keyboard I would prefer PS/2. (Although my keyboard doesn´t support PS/2, so that a simple USB A to PS/2 connector is useless). The Reason for me is, to get the real NKRO (which is limited via USB to 6KRO). Also I would be able to send key events like system control (power down, sleep, etc. ..)

Offline mougrim

  • Posts: 768
  • Location: Ukraine
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #144 on: Thu, 17 March 2016, 16:42:18 »
Thank you for a good work, Hasu!

Can I ask you if this converter could be used with a Atmega328-based controller, say, Arduino Nano?
IBM AT Model F, Vortexgear Race 3, AEKII (Alps Cream Damped), Metoo Zero (modded to Kailh Box Navy)

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #145 on: Thu, 17 March 2016, 17:02:12 »
yes, use vusb stack.

Offline itzmeluigi

  • Posts: 301
  • ПБТ
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #146 on: Thu, 17 March 2016, 20:44:52 »

Hi ive been trying to setup TMK PS/2 to USB converter using Arduino Nano atmega328p with Makefile.vusb. The keyboard powers up and the LED's blink on the Arduino when keys are pressed but the keybaord doesnt output any characters.

I have CLOCK connected to PD5 pin and DATA connected to PD2 pin but it still doesnt work.


Makefile.vusb:
Code: [Select]
# Target file name (without extension).
TARGET = ps2_usb_vusb

# Directory common source filess exist
TMK_DIR = ../../tmk_core

# Directory keyboard dependent files exist
TARGET_DIR = .

# keyboard dependent files
SRC = keymap_common.c \
matrix.c \
led.c

ifdef KEYMAP
    SRC := keymap_$(KEYMAP).c $(SRC)
else
    SRC := keymap_plain.c $(SRC)
endif

CONFIG_H = config.h


# Use USART for PS/2. With V-USB INT and BUSYWAIT code is not useful.
PS2_USE_USART = yes


# V-USB debug level: To use ps2_usart.c level must be 0
# ps2_usart.c requires USART to receive PS/2 signal.
OPT_DEFS += -DDEBUG_LEVEL=0


# MCU name, you MUST set this to match the board you are using
# type "make clean" after changing this, so all files will be rebuilt
#MCU = at90usb162       # Teensy 1.0
#MCU = atmega32u4       # Teensy 2.0
#MCU = at90usb646       # Teensy++ 1.0
#MCU = at90usb1286      # Teensy++ 2.0
MCU = atmega328p


# Processor frequency.
#   Normally the first thing your program should do is set the clock prescaler,
#   so your program will run at the correct speed.  You should also set this
#   variable to same clock speed.  The _delay_ms() macro uses this, and many
#   examples use this variable to calculate timings.  Do not add a "UL" here.
F_CPU = 16000000


# Build Options
#   comment out to disable the options.
#
MOUSEKEY_ENABLE = yes # Mouse keys
EXTRAKEY_ENABLE = yes # Audio control and System control
#NKRO_ENABLE = yes # USB Nkey Rollover
NO_UART = no # UART is unavailable



#---------------- Programming Options --------------------------
AVRDUDE = avrdude
# Type: avrdude -c ? to get a full listing.
AVRDUDE_PROGRAMMER = usbasp
AVRDUDE_PORT =
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep

# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y

# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V

# Increase verbosity level.  Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v

#AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)

PROGRAM_CMD = $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)


# Boot Section Size in bytes
#   Teensy halfKay   512
#   Atmel DFU loader 4096
#   LUFA bootloader  4096
#   USBasp           2048
OPT_DEFS += -DBOOTLOADER_SIZE=512


# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TMK_DIR)


include $(TMK_DIR)/protocol.mk
include $(TMK_DIR)/common.mk
include $(TMK_DIR)/protocol/vusb.mk
include $(TMK_DIR)/rules.mk



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

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

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

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

#ifndef CONFIG_H
#define CONFIG_H

#include <avr/interrupt.h>

#define VENDOR_ID       0xFEED
#define PRODUCT_ID      0x6512
#define DEVICE_VER      0x0001
#define MANUFACTURER    t.m.k.
#define PRODUCT         PS/2 keyboard converter
#define DESCRIPTION     convert PS/2 keyboard to USB


/* matrix size */
#define MATRIX_ROWS 32  // keycode bit: 3-0
#define MATRIX_COLS 8   // keycode bit: 6-4


/* key combination for command */
#define IS_COMMAND() ( \
    keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) || \
    keyboard_report->mods == (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT)) \
)


//#define NO_SUSPEND_POWER_DOWN


/*
 * PS/2 Busywait
 */
#ifdef PS2_USE_BUSYWAIT
#define PS2_CLOCK_PORT  PORTD
#define PS2_CLOCK_PIN   PIND
#define PS2_CLOCK_DDR   DDRD
#define PS2_CLOCK_BIT   1
#define PS2_DATA_PORT   PORTD
#define PS2_DATA_PIN    PIND
#define PS2_DATA_DDR    DDRD
#define PS2_DATA_BIT    0
#endif

/*
 * PS/2 Pin interrupt
 */
#ifdef PS2_USE_INT
/* uses INT1 for clock line(ATMega32U4) */
#define PS2_CLOCK_PORT  PORTD
#define PS2_CLOCK_PIN   PIND
#define PS2_CLOCK_DDR   DDRD
#define PS2_CLOCK_BIT   1
#define PS2_DATA_PORT   PORTD
#define PS2_DATA_PIN    PIND
#define PS2_DATA_DDR    DDRD
#define PS2_DATA_BIT    0
#define PS2_INT_INIT()  do {    \
    EICRA |= ((1<<ISC11) |      \
              (0<<ISC10));      \
} while (0)
#define PS2_INT_ON()  do {      \
    EIMSK |= (1<<INT1);         \
} while (0)
#define PS2_INT_OFF() do {      \
    EIMSK &= ~(1<<INT1);        \
} while (0)
#define PS2_INT_VECT    INT1_vect
#endif

/*
 * PS/2 USART
 */
#ifdef PS2_USE_USART
#if defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__)
/* XCK for clock line and RXD for data line */
#define PS2_CLOCK_PORT  PORTD
#define PS2_CLOCK_PIN   PIND
#define PS2_CLOCK_DDR   DDRD
#define PS2_CLOCK_BIT   5
#define PS2_DATA_PORT   PORTD
#define PS2_DATA_PIN    PIND
#define PS2_DATA_DDR    DDRD
#define PS2_DATA_BIT    2
/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
/* set DDR of CLOCK as input to be slave */
#define PS2_USART_INIT() do {   \
    PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);   \
    PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);     \
    UCSR1C = ((1 << UMSEL10) |  \
              (3 << UPM10)   |  \
              (0 << USBS1)   |  \
              (3 << UCSZ10)  |  \
              (0 << UCPOL1));   \
    UCSR1A = 0;                 \
    UBRR1H = 0;                 \
    UBRR1L = 0;                 \
} while (0)
#define PS2_USART_RX_INT_ON() do {  \
    UCSR1B = ((1 << RXCIE1) |       \
              (1 << RXEN1));        \
} while (0)
#define PS2_USART_RX_POLL_ON() do { \
    UCSR1B = (1 << RXEN1);          \
} while (0)
#define PS2_USART_OFF() do {    \
    UCSR1C = 0;                 \
    UCSR1B &= ~((1 << RXEN1) |  \
                (1 << TXEN1));  \
} while (0)
#define PS2_USART_RX_READY      (UCSR1A & (1<<RXC1))
#define PS2_USART_RX_DATA       UDR1
#define PS2_USART_ERROR         (UCSR1A & ((1<<FE1) | (1<<DOR1) | (1<<UPE1)))
#define PS2_USART_RX_VECT       USART1_RX_vect
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
/* XCK for clock line and RXD for data line */
#define PS2_CLOCK_PORT  PORTD
#define PS2_CLOCK_PIN   PIND
#define PS2_CLOCK_DDR   DDRD
#define PS2_CLOCK_BIT   4
#define PS2_DATA_PORT   PORTD
#define PS2_DATA_PIN    PIND
#define PS2_DATA_DDR    DDRD
#define PS2_DATA_BIT    0
/* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */
/* set DDR of CLOCK as input to be slave */
#define PS2_USART_INIT() do {   \
    PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT);   \
    PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT);     \
    UCSR0C = ((1 << UMSEL00) |  \
              (3 << UPM00)   |  \
              (0 << USBS0)   |  \
              (3 << UCSZ00)  |  \
              (0 << UCPOL0));   \
    UCSR0A = 0;                 \
    UBRR0H = 0;                 \
    UBRR0L = 0;                 \
} while (0)
#define PS2_USART_RX_INT_ON() do {  \
    UCSR0B = ((1 << RXCIE0) |       \
              (1 << RXEN0));        \
} while (0)
#define PS2_USART_RX_POLL_ON() do { \
    UCSR0B = (1 << RXEN0);          \
} while (0)
#define PS2_USART_OFF() do {    \
    UCSR0C = 0;                 \
    UCSR0B &= ~((1 << RXEN0) |  \
                (1 << TXEN0));  \
} while (0)
#define PS2_USART_RX_READY      (UCSR0A & (1<<RXC0))
#define PS2_USART_RX_DATA       UDR0
#define PS2_USART_ERROR         (UCSR0A & ((1<<FE0) | (1<<DOR0) | (1<<UPE0)))
#define PS2_USART_RX_VECT       USART_RX_vect
#endif
#endif

#endif

Does everything look ok? Did i configure the files wrong? Im temporarily out of ideas hopefully theres a way to get it working

« Last Edit: Thu, 17 March 2016, 21:07:33 by itzmeluigi »

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #147 on: Fri, 18 March 2016, 09:11:08 »
Your pin configuration is wrong. as config.h indicates, you have to use pd0/rxd and pd4/xck pin for atmega328p.

Offline itzmeluigi

  • Posts: 301
  • ПБТ
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #148 on: Fri, 18 March 2016, 10:58:49 »
Your pin configuration is wrong. as config.h indicates, you have to use pd0/rxd and pd4/xck pin for atmega328p.

I moved the wires CLOCK and DATA to PD0 and PD4 but the result is the same.

Offline hasu

  • Thread Starter
  • Posts: 3471
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO
« Reply #149 on: Fri, 18 March 2016, 16:46:13 »
Post pic of your wiring.
Did you connect DATA to PD0 and Clock ot PD4? Do you have pull up resistors?
And do you have components(zeners and registers on INT0/INT1) for VUSB?