TMK IBM PC Keyboard Converter

User avatar
hasu

05 Dec 2019, 01:11

IBM PC Keyboard Converter

The converter translates IBM PC keyboard protocols to plug classic keyboards into modern computer with USB ports. It supports both IBM XT and AT protocols, and all of scan code set 1, 2 and 3 with one firmware.


Also check this corresponding thread at geekhack.org.
https://geekhack.org/index.php?topic=103648.0


REQUEST FOR HELP:
Try prebuilt firmware below and report your result, please.
Post your keyboard model number here, also debug outputs on hid_listen would be helpful.

The converter need to be tested with keyboards below particularly, as of 2020-03-24.

- IBM PC XT 83-key
- IBM PC AT 84-key
- Zenith Z-150 XT black label
- Zenith Z-150 AT beige label




Update

2020-04-28 Add support G80-2551 and possibly other terminal keyboards(whose id is AB86)
2020-04-11 Keymap Editor is available
2020-03-02 firmware update for XT protocol handling and many other fixes



Hardware

Firmware supports ATMega32u4 by default, Teensy2/2++ or ProMicro can be used.
Wire controller pins below to keyboard signals, besides VCC and GND. This is compatible for Soarer's converter.

- Data: PD0
- Clock: PD1
- Reset: PB6 or PB7 (For some of XT keyboards. Not needed for AT, PS/2 and Terminal)

Pull up resistors of 1-4.7K Ohm on both Data and Clock line are recommended, without them it won't work in some cases.

Reset
Old Type-1 IBM XT keyboard and some of XT clones need this to reset its controller on startup. Many of IBM XT keyboards available are Type-2 and don't need the reset pin.

See this for Type-1 vs Type-2:
https://vintagecomputer.ca/ibm-pc-model ... vs-type-2/

As for clones Zenith Z-150 XT and Leading Edge DC-2014 are known to need this.

Connector pinouts
XT
- http://www.kbdbabel.org/conn/kbd_connector_ibmpc.png
- https://allpinouts.org/pinouts/connecto ... -xt-5-pin/

AT
- http://www.kbdbabel.org/conn/kbd_connector_ps2.png
- https://old.pinouts.ru/InputCables/Keyb ... nout.shtml

PS/2
- https://pinouts.ru/InputCables/KeyboardPC6_pinout.shtml

Terminal
- http://www.kbdbabel.org/conn/kbd_connector_ibmterm.png
- http://www.kbdbabel.org/conn/kbd_connec ... x_319x.png



Keymap Editor

You can edit keymap and download firmware here.

http://www.tmk-kbd.com/tmk_keyboard/editor/#ibmpc_usb


Default Prebuilt Firmware

You can usually download fimware from Keymap Edior above.
Use this default firmware when you are in trouble.

https://github.com/tmk/tmk_keyboard/tre ... usb/binary



Build Firmware

Download source code from: https://github.com/tmk/tmk_keyboard/tre ... /ibmpc_usb

$ cd converter/ibmpc_usb
$ make clean
$ make



Debug

Use hid_listen to see debug outputs from the converter.

https://www.pjrc.com/teensy/hid_listen.html

Code: Select all

Waiting for new device:...
Listening:


TMK:95aba6dd/LUFA


USB configured.

Keyboard start.
rAA rBF rBF wF5 rFA wF2 rFA rBF rBF wF4 rFA ID: BFBF
kbd: Terminal
wF8 rFA  
Last edited by hasu on 03 May 2020, 12:34, edited 9 times in total.

User avatar
ZedTheMan

05 Dec 2019, 01:22

This is exciting! I will begin to convert my soarer's converters to this for my F122 and other boards. Just have to break open the orihalcon cable and jerryrig reset pins directly to the 32u4.

User avatar
Muirium
µ

05 Dec 2019, 01:54

Looks promising: TMK has learned all of Soarer’s multi-protocol handling tricks!

I hope this will be Unimap compatible when you’re done! I love defining everything graphically.

User avatar
depletedvespene

05 Dec 2019, 02:02

Okay. I'm in for this.

User avatar
hasu

05 Dec 2019, 02:21

ZedTheMan ,
Yes, reset button would be a must-have when in trouble.
I don't recommend to use converter without reset button like orihalcon's for now at least. To use Teensy or Pro Micro is fine and safe.

If the firmware recognize your keyboard correctly you can put it into bootloader mode by holding 'Left shift + Right shift + Pause'. But if not you won't be able to acccess bootloader without reset button. I have a plan to add emergency rescue method for the situation.

Muirium,
I'll add specific support for this converter to my Keymap Editor some later.
But until then, you can do with trick below.

0. Download prebuilt firmware
1. Open Editor: http://www.tmk-kbd.com/tmk_keyboard/edi ... p/?usb_usb
2. Select the downloaded file on file chooser in 'Base Firmware File:' section
3. Click 'Load keymap from firmware' button
4. Edit your keymap
3. Then, click 'Download' button

John Doe

05 Dec 2019, 02:23

Nice job, ill have a try on my at/122 to see what will happen. Appreciate it.

User avatar
hasu

06 Jan 2020, 03:09

anyone can help?

REQUEST FOR HELP: Try and report your result.
Post your keyboard model number here, also debug outputs on hid_listen would be helpful.

User avatar
hasu

04 Mar 2020, 04:14

anyone?

User avatar
Redmaus
Gotta start somewhere

04 Mar 2020, 04:56

Would it be possible to test a Wyse? I can test some AT boards soon.

User avatar
ZedTheMan

04 Mar 2020, 05:53

Hi Hasu, sorry for not responding. I will flash this to my xt usb converter and try it with various boards I have when I have time, but this may take a bit, sorry.

User avatar
Redmaus
Gotta start somewhere

04 Mar 2020, 06:39

Works like a dream on my DS-2001! Thanks Hasu!

Soarer's kept messing up every time I stopped using it for awhile. DS-2001 uses AT protocol fyi.
IMG_9700.JPG
IMG_9700.JPG (281.43 KiB) Viewed 17128 times

User avatar
hasu

04 Mar 2020, 10:53

Redmaus, Thanks for the test!
and good to know it works with the keyobard.
As for Wyse, this doesn't support Wyse proprietary protocol. If the board speaks in AT, XT or Terminal protocol the converter should works.


At this time I'm interested in test results with keyboards below particularly.
It would be helpful to debug firmware if someone with the boards can test the converter with them.

- IBM PC XT 83-key(Model F)
- IBM PC AT 84-key(Model F)

User avatar
snacksthecat
✶✶✶✶

13 Mar 2020, 21:32

I can't promise I'll do it yet (not sure if I have parts on hand) but I own both of those keyboards so I'm going to "half" commit to testing the two Model Fs for you today or tomorrow.

Stuff like this is the least we can do after you've contributed so many great projects to the keyboard world, Hasu :)

User avatar
hasu

03 May 2020, 12:35

Updated first post.

Keymap Editor is avaialable here now.
http://www.tmk-kbd.com/tmk_keyboard/editor/#ibmpc_usb

frogmaster

28 Jun 2020, 13:00

I'm in the process of restoring a model f at for everyday use, and was thinking of using this, but i have modified the layout to suit my usage, and have verified, that the following Soarer's remap works:

Code: Select all

remapblock
EXTRA_LALT      LALT    # extra pad lhs of space
EXTRA_RALT      RALT    # extra pad rhs of space
EXTRA_EUROPE_2  BACKSLASH       # extra pad lhs of enter
EXTRA_INSERT LEFT       # extra pad lhs of insert
PAD_0 DOWN
PAD_PERIOD RIGHT
PAD_2 UP
PAD_4 DELETE
PAD_5 END
PAD_6 PAGE_DOWN
PAD_7 INSERT
PAD_8 HOME
PAD_9 PAGE_UP
ESC F11
NUM_LOCK F12
SCROLL_LOCK PRINTSCREEN
INTERNATIONAL_2 EUROPE_2
endblock
How could i accomplish this with the tmk keymap editor?

User avatar
hasu

29 Jun 2020, 01:29

I think if you do some trial and error on Keymap Editor you will know how to use it somehow.
What's your problem actually?

That remap looks to me really straight, though, I don't know much about how Soarer's remap setting works. You may need to explain me what you want.

frogmaster

29 Jun 2020, 09:14

Well for start, EXTRA_INSERT (0xb6) is missing from numpad (should be left of NUMPAD 0). What is the button i should select on the editor? Also, what are these mapped as on keymap editor keyboard? I was trying to grep these values in ibmpc_usb.c, but only one that showed up was 0xB6, which seems to be ignored in process_cs1, i don't know if it's the right place to look, or if the values should match with soarer's documentation.

Code: Select all

Excerpt from soarer's codes:
EXTRA_LALT	0xB1	AT-F extra pad lhs of space
EXTRA_PAD_PLUS	0xB2	Term extra pad bottom of keypad +
EXTRA_RALT	0xB3	AT-F extra pad rhs of space
EXTRA_EUROPE_2	0xB4	AT-F extra pad lhs of enter
EXTRA_BACKSLASH	0xB5	AT-F extra pad top of enter
EXTRA_INSERT	0xB6	AT-F extra pad lhs of Insert

User avatar
hasu

29 Jun 2020, 10:19

frogmaster wrote:
29 Jun 2020, 09:14
Well for start, EXTRA_INSERT (0xb6) is missing from numpad (should be left of NUMPAD 0). What is the button i should select on the editor?
First, flash firmware downloaded from Keymap Editor(without edit mapping). Then press the key on your keyboard to know what it registers on computer, you will need tool like Switchhitter or Aquakeytest often.

You should find a logical 'key' corresponding to what the keyboard registers on Keymap Editor, it is what you want to edit.

Also, what are these mapped as on keymap editor keyboard? I was trying to grep these values in ibmpc_usb.c, but only one that showed up was 0xB6, which seems to be ignored in process_cs1, i don't know if it's the right place to look, or if the values should match with soarer's documentation.
The keymap editor uses TMK specific codes(unimap code) internally to mapping keys, they won't match Soarer's specific internal defined codes(I think they are extended USB HID codes) or IBM XT scan codes.

0xB6 is not IBM XT scan code, Soarer's code. So it should be handled release code of 0x36, to be exact.
To know what scan code the key actually spits out you can use hid_listen tool with Soarer's or TMK converter.

User avatar
hasu

29 Jun 2020, 10:26

What is your keyboard model? You refered only 'model f'.

Which key are you refering? Posting pic is helpful.
"EXTRA_INSERT (0xb6) is missing from numpad (should be left of NUMPAD 0)."

User avatar
bsdice

29 Jun 2020, 13:26

Hey there,

I just built a TMK ps2_usb converter out of this Pro Micro clone from ebay:
Pro_Micro_01.jpg
Pro_Micro_01.jpg (79.67 KiB) Viewed 16276 times
At first I contemplated just buying a converter from anywhere, but I could already smell bugs with ISO-DE layout and non-configurability even before hitting the Buy-button. So I went with this. For better results I tweaked the whole setup a little:
  • Desoldered MIC5219 voltage regulator (the 5-legged IC), 2x 10uF (orange pieces), diode D2 (middle and right next to USB socket SMD pins). I recommend watching https://www.youtube.com/watch?v=CVsmwFAkf7I for good results without hot air.
  • Bridged J1, bridged the D2 pads. This connects USB 5V straight through to RAW and VCC pins.
  • Put a 105°C 5000h 10uF Europe Chemi-Con excellent quality "KY"-type electrolytic cap on RAW+GND (polarity is important) to replace the cheap tantalum caps' function. As a personal preference I don't like failing cheap tantalum or electrolytic capacitors.
  • Didn't need pullups on PS/2 CLK+DATA, so I left those out. Your boards may be different.
Since I wanted 100% control of bootloader I chose "Katiana" as bootloader from here https://github.com/m-kozlowski/Katiana with the following modifications:
Spoiler:

Code: Select all

diff -Nburp Katiana.orig/Board/LEDs.h Katiana/Board/LEDs.h
--- Katiana.orig/Board/LEDs.h	2019-02-23 03:04:02.000000000 +0100
+++ Katiana/Board/LEDs.h	2020-06-13 00:02:30.579388161 +0200
@@ -92,6 +92,25 @@ extern "C" {
 // Edit to specify the PORT, DDR and BIT for each of the three LEDs
 // Also specify the bit value when the LED is turned on..."1" or "0" ?
 //
+
+// SparkFun Pro Micro (LED_L not implemented)
+#define LEDS_RX_PORT	PORTB
+#define LEDS_TX_PORT	PORTD
+#define LEDS_L_PORT     PORTC
+
+#define LEDS_RX_DDR	DDRD
+#define LEDS_TX_DDR	DDRB
+#define LEDS_L_DDR	DDRC
+
+#define LEDS_RX_BIT	0x20
+#define LEDS_TX_BIT	0x01
+#define LEDS_L_BIT	0x80
+
+#define LEDS_RX_ACTIVE  0
+#define LEDS_TX_ACTIVE  0
+#define LEDS_L_ACTIVE   1
+
+
 #if 0
 // Leonardo
 #define LEDS_RX_PORT	PORTB
@@ -110,7 +129,9 @@ extern "C" {
 #define LEDS_TX_ACTIVE  0
 #define LEDS_L_ACTIVE   1
 
-#else
+#endif
+
+#if 0
 // WxRecorder (LED_L not implemented)
 
 #define LEDS_RX_PORT	PORTB
@@ -173,7 +194,7 @@ These functions are purposely NOT inline
    
 #if !defined(__DOXYGEN__)
 
-    inline void LEDs_Init(void)
+    static inline void LEDs_Init(void)
     {
 #if defined LED_DATA_FLASHES
 	LEDS_RX_DDR |= LEDS_RX_BIT;
@@ -189,7 +210,7 @@ These functions are purposely NOT inline
 #endif
     }
 
-    inline void LEDs_Disable(void)
+    static inline void LEDs_Disable(void)
     {
 	/** 
 	Set everything back to original state -- all DDR bits to input, and all port bits to zero.
@@ -210,63 +231,63 @@ These functions are purposely NOT inline
 #endif
     }
     
-    inline void LEDs_RX_Off(void)
+    static inline void LEDs_RX_Off(void)
     {
 #if defined LED_DATA_FLASHES
 	LEDS_RX_PORT LEDS_RX_OFF LEDS_RX_BIT;
 #endif
     }
 
-    inline void LEDs_RX_On(void)
+    static inline void LEDs_RX_On(void)
     {
 #if defined LED_DATA_FLASHES
 	LEDS_RX_PORT LEDS_RX_ON LEDS_RX_BIT;
 #endif
     }
 
-    inline void LEDs_RX_Toggle(void)
+    static inline void LEDs_RX_Toggle(void)
     {
 #if defined LED_DATA_FLASHES
 	LEDS_RX_PORT ^= LEDS_RX_BIT;
 #endif
     }
 
-    inline void LEDs_TX_Off(void)
+    static inline void LEDs_TX_Off(void)
     {
 #if defined LED_DATA_FLASHES
 	LEDS_TX_PORT LEDS_TX_OFF LEDS_TX_BIT;
 #endif
     }
 
-    inline void LEDs_TX_On(void)
+    static inline void LEDs_TX_On(void)
     {
 #if defined LED_DATA_FLASHES
 	LEDS_TX_PORT LEDS_TX_ON LEDS_TX_BIT;
 #endif
     }
 
-    inline void LEDs_TX_Toggle(void)
+    static inline void LEDs_TX_Toggle(void)
     {
 #if defined LED_DATA_FLASHES
 	LEDS_TX_PORT ^= LEDS_TX_BIT;
 #endif
     }
 
-    inline void LEDs_L_Off(void)
+    static inline void LEDs_L_Off(void)
     {
 #if LED_START_FLASHES > 0
 	LEDS_L_PORT LEDS_L_OFF LEDS_L_BIT;
 #endif
     }
 
-    inline void LEDs_L_On(void)
+    static inline void LEDs_L_On(void)
     {
 #if LED_START_FLASHES > 0
 	LEDS_L_PORT LEDS_L_ON LEDS_L_BIT;
 #endif
     }
 
-    inline void LEDs_L_Toggle(void)
+    static inline void LEDs_L_Toggle(void)
     {
 #if LED_START_FLASHES > 0
 	LEDS_L_PORT ^= LEDS_L_BIT;
diff -Nburp Katiana.orig/Config/AppConfig.h Katiana/Config/AppConfig.h
--- Katiana.orig/Config/AppConfig.h	2019-02-23 03:04:02.000000000 +0100
+++ Katiana/Config/AppConfig.h	2020-06-12 23:13:33.534868497 +0200
@@ -93,11 +93,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBI
 //
 
     #define ENABLE_FLASH_ERASE_SUPPORT
-//	#define ENABLE_EEPROM_BYTE_SUPPORT
+	#define ENABLE_EEPROM_BYTE_SUPPORT
 //	#define ENABLE_FLASH_BYTE_SUPPORT
 //	#define ENABLE_LOCK_BYTE_WRITE_SUPPORT
 	#define ENABLE_LOCK_FUSE_READ_SUPPORT
 
 #define USB_VID 0x1B4F
-#define USB_PID 0x9207
+#define USB_PID 0x9205
 
diff -Nburp Katiana.orig/Descriptors.c Katiana/Descriptors.c
--- Katiana.orig/Descriptors.c	2019-02-23 03:04:02.000000000 +0100
+++ Katiana/Descriptors.c	2020-06-22 02:09:19.721438576 +0200
@@ -227,13 +227,13 @@ const USB_Descriptor_String_t LanguageSt
  *  form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
  *  Descriptor.
  */
-const USB_Descriptor_String_t ManufacturerString = USB_STRING_DESCRIPTOR(L"Manufacturer Name Goes Here");
+const USB_Descriptor_String_t ManufacturerString = USB_STRING_DESCRIPTOR(L"YOUR NAME GOES HERE");
 
 /** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
  *  and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
  *  Descriptor.
  */
-const USB_Descriptor_String_t ProductString = USB_STRING_DESCRIPTOR(L"Product Name Goes Here");
+const USB_Descriptor_String_t ProductString = USB_STRING_DESCRIPTOR(L"Pro Micro Bootloader");
 
 #if defined(CUSTOM_USB_SERIAL) || defined(__DOXYGEN__)
 
diff -Nburp Katiana.orig/Katiana.c Katiana/Katiana.c
--- Katiana.orig/Katiana.c	2019-02-23 03:04:02.000000000 +0100
+++ Katiana/Katiana.c	2020-06-12 23:37:56.953882554 +0200
@@ -724,7 +724,7 @@ copies them out to the USB host using Cd
 \param[in] Count is the number of bytes to be sent.
 \see CdcSendByte
 */
-static void WriteProgmemArray(uint8_t *Response, uint8_t Count)
+static void WriteProgmemArray(const uint8_t *Response, uint8_t Count)
 {
     while (Count--) CdcSendByte( pgm_read_byte_near( Response++ ) );
 }
diff -Nburp Katiana.orig/Katiana.h Katiana/Katiana.h
--- Katiana.orig/Katiana.h	2019-02-23 03:04:02.000000000 +0100
+++ Katiana/Katiana.h	2020-06-12 23:38:07.728643630 +0200
@@ -236,7 +236,7 @@ static void inline SetupNormalHardware(v
   Some clever person could maybe find a way to prevent that warning from 
   being emitted?
 */
-static void __attribute__((noreturn naked noinline)) StartSketch( void );
+static void __attribute__((noreturn, naked, noinline)) StartSketch( void );
 
 #if defined(ENABLE_SECURITY_CHECKS)
     static uint8_t ValidateFlashBlock(uint16_t);
@@ -259,7 +259,7 @@ static void __attribute__((noinline)) Se
 static void __attribute__((noinline)) BootRwwEnable(void);
 static void __attribute__((noinline)) ExecuteSPM( uint8_t );
  __attribute__((noinline)) static void IncrementAddress(void);
-static void  __attribute__((noinline)) WriteProgmemArray(uint8_t*, uint8_t);
+static void  __attribute__((noinline)) WriteProgmemArray(const uint8_t*, uint8_t);
 
 /** 
 Function which grabs at most one AVR-910 command and fully processes it
diff -Nburp Katiana.orig/UsbHdwrSerial.h Katiana/UsbHdwrSerial.h
--- Katiana.orig/UsbHdwrSerial.h	2019-02-23 03:04:02.000000000 +0100
+++ Katiana/UsbHdwrSerial.h	2020-06-22 02:11:27.108081746 +0200
@@ -1,2 +1,2 @@
 #pragma once
-#define USB_HDWR_SERIAL "00000000000000000000"
+#define USB_HDWR_SERIAL "20200622E001"
diff -Nburp Katiana.orig/makefile Katiana/makefile
--- Katiana.orig/makefile	2019-02-23 03:04:02.000000000 +0100
+++ Katiana/makefile	2020-06-12 23:54:11.562311452 +0200
@@ -36,8 +36,8 @@
 MCU          = atmega32u4
 ARCH         = AVR8
 BOARD        = USER
-F_CPU        = 8000000
-F_USB        = 8000000
+F_CPU        = 16000000
+F_USB        = $(F_CPU)
 #
 # Flash and bootloader section sizes of the target, in KB. 
 # There's no easy way to import these into this makefile based on the MCU macro,
@@ -92,9 +92,9 @@ include $(DMBS_PATH)/avrdude.mk
 include $(DMBS_PATH)/atprogram.mk
 
 CheckUsbSerial: ValidateUsbHdwrSerial.c
-	cc ValidateUsbHdwrSerial.c -o TmpExec.exe
-	./TmpExec.exe
-	@rm -f TmpExec.exe
+	cc ValidateUsbHdwrSerial.c -o TmpExec
+	./TmpExec
+	@rm -f TmpExec
 
 RemoveUsbSerialCheck:
-	rm -f TmpExec.exe
+	rm -f TmpExec
Modifications are primarily for clean compilation or to correct compilation errors, use correct LED pins, enable EEPROM byte support, modify USB vendor and product string ("Product Name Goes Here"), correct CPU frequency to 16 MHz, correct Windows to Linux CheckUsbSerial utility, give it a hardware serial key (12 chars minimum). Katiana is an improved version of the Caterina bootloader and well tested on ATmega32u4 MCUs. There is a Katiana-Bootloader.pdf file in the project, very good reading. Of course TMK would need to be improved to use these new features, like determining cause of last reset or usage of bootloader's USB serial number. Ran out of time...

Also of note, as an ArchLinux user I had avr-gcc 10 installed at first, but after some readings of compiled assembly (and head scratching) and reading posts on eevblog and avrfreaks, I decided for code quality reasons to install avr-gcc 8.4.0, and also compile avr-libc with this compiler. Hit me with a message if anyone wants the PKGBUILDs for these.

tmk_keyboard also needed some modifications:
Spoiler:

Code: Select all

diff -Nburp tmk_keyboard-master/converter/ps2_usb/Makefile tmk_keyboard/converter/ps2_usb/Makefile
--- tmk_keyboard-master/converter/ps2_usb/Makefile	2020-06-03 05:35:47.000000000 +0200
+++ tmk_keyboard/converter/ps2_usb/Makefile	2020-06-24 02:20:57.995840542 +0200
@@ -1,5 +1,5 @@
 # Target file name (without extension).
-TARGET ?= ps2_usb
+TARGET ?= ps2_usb_32u4
 
 # Directory common source filess exist
 TMK_DIR ?= ../../tmk_core
@@ -14,6 +14,8 @@ SRC ?=	matrix.c \
 #
 # Keymap file
 #
+UNIMAP_ENABLE = yes
+KEYMAP_SECTION_ENABLE = yes
 ifdef UNIMAP_ENABLE
     KEYMAP_FILE = unimap
 else
@@ -33,7 +35,7 @@ CONFIG_H ?= config.h
 
 
 # MCU name
-MCU ?= atmega32u2
+MCU ?= atmega32u4
 
 # Processor frequency.
 #     This will define a symbol, F_CPU, in all source code files equal to the
@@ -86,7 +88,7 @@ OPT_DEFS += -DBOOTLOADER_SIZE=$(BOOTLOAD
 #   comment out to disable the options.
 #
 BOOTMAGIC_ENABLE ?= no	# Virtual DIP switch configuration(+1000)
-MOUSEKEY_ENABLE ?= no	# Mouse keys(+4700)
+MOUSEKEY_ENABLE ?= yes	# Mouse keys(+4700)
 EXTRAKEY_ENABLE ?= yes	# Audio control and System control(+450)
 CONSOLE_ENABLE ?= yes	# Console for debug(+400)
 COMMAND_ENABLE ?= yes    # Commands for debug and configuration
diff -Nburp tmk_keyboard-master/converter/ps2_usb/config.h tmk_keyboard/converter/ps2_usb/config.h
--- tmk_keyboard-master/converter/ps2_usb/config.h	2020-06-03 05:35:47.000000000 +0200
+++ tmk_keyboard/converter/ps2_usb/config.h	2020-06-24 01:48:59.009771718 +0200
@@ -20,12 +20,12 @@ along with this program.  If not, see <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
+#define VENDOR_ID       0x1B4F
+#define PRODUCT_ID      0x9206
+#define DEVICE_VER      0x0101
+#define MANUFACTURER    Your name goes here
+#define PRODUCT         USB-PS/2 Keyboard Converter
+#define DESCRIPTION     USB-PS/2 Keyboard Converter
 
 
 /* matrix size */
diff -Nburp tmk_keyboard-master/converter/ps2_usb/unimap_plain.c tmk_keyboard/converter/ps2_usb/unimap_plain.c
--- tmk_keyboard-master/converter/ps2_usb/unimap_plain.c	2020-06-03 05:35:47.000000000 +0200
+++ tmk_keyboard/converter/ps2_usb/unimap_plain.c	2020-06-24 02:10:02.304473598 +0200
@@ -33,13 +33,13 @@ const action_t actionmaps[][UNIMAP_ROWS]
     LSFT,NUBS,Z,   X,   C,   V,   B,   N,   M,   COMM,DOT, SLSH,     RO,  RSFT,          UP,           P1,  P2,  P3,  PENT,
     LCTL,LGUI,LALT,MHEN,          SPC,           HENK,KANA,RALT,RGUI,FN0, RCTL,     LEFT,DOWN,RGHT,    NUHS,P0,  PDOT,PEQL
     ),
-    UNIMAP(
+    UNIMAP_PS2(
               TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
-    GRV,      TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,          TRNS,TRNS,TRNS,         TRNS,TRNS,TRNS,
-    ESC, F1,  F2,  F3,  F4,  F5,  F6,  F7,  F8,  F9,  F10, F11, F12, INS, DEL,      TRNS,TRNS,TRNS,    TRNS,TRNS,TRNS,TRNS,
-    CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS,UP,  INS,      TRNS,     TRNS,TRNS,TRNS,    TRNS,TRNS,TRNS,TRNS,
-    TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,TRNS,TRNS,HOME,PGUP,LEFT,RGHT,          TRNS,                        TRNS,TRNS,TRNS,TRNS,
-    TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,END, PGDN,DOWN,     TRNS,TRNS,          PGUP,         TRNS,TRNS,TRNS,TRNS,
-    TRNS,TRNS,TRNS,TRNS,          TRNS,          TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,     HOME,PGDN,END,     TRNS,TRNS,TRNS,TRNS
+    TRNS,     TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,          TRNS,TRNS,TRNS,         TRNS,TRNS,TRNS,
+    TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,     TRNS,TRNS,TRNS,    TRNS,TRNS,TRNS,TRNS,
+    TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,     TRNS,     TRNS,TRNS,TRNS,    TRNS,TRNS,TRNS,TRNS,
+    TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,          TRNS,                        TRNS,TRNS,TRNS,TRNS,
+    TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,     TRNS,TRNS,          VOLU,         TRNS,TRNS,TRNS,TRNS,
+    TRNS,TRNS,TRNS,TRNS,          TRNS,          TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,     MUTE,VOLD,MUTE,    TRNS,TRNS,TRNS,TRNS
     ),
 };
diff -Nburp tmk_keyboard-master/tmk_core/common/avr/bootloader.c tmk_keyboard/tmk_core/common/avr/bootloader.c
--- tmk_keyboard-master/tmk_core/common/avr/bootloader.c	2020-06-03 05:35:47.000000000 +0200
+++ tmk_keyboard/tmk_core/common/avr/bootloader.c	2020-06-14 02:33:43.426154975 +0200
@@ -107,7 +107,7 @@ void bootloader_jump(void) {
     // Watchdog reset with bootkey causes the bootloader to enter program mode instead of starting application.
     // https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/caterina/Caterina.c#L68-L69
     // https://github.com/sparkfun/SF32u4_boards/blob/master/sparkfun/avr/bootloaders/caterina/Caterina.c#L88-L89
-    *(volatile uint16_t *)0x0800 = 0x7777;
+    *(volatile uint16_t *)(RAMEND-1) = 0x7777;
 #endif
 
     // watchdog reset
@@ -134,7 +134,7 @@ void bootloader_jump_after_watchdog_rese
         // Clear bootkey of Caterina bootloader for other bootloaders
         // Leonardo and Pro Micro with Arduino default fuse setting don't reach here
         // because bootloader section are executed before application everytime.
-        *(volatile uint16_t *)0x0800 = 0;
+        *(volatile uint16_t *)(RAMEND-1) = 0;
 #endif
 
         // This is compled into 'icall', address should be in word unit, not byte.
diff -Nburp tmk_keyboard-master/tmk_core/common.mk tmk_keyboard/tmk_core/common.mk
--- tmk_keyboard-master/tmk_core/common.mk	2020-06-03 05:35:47.000000000 +0200
+++ tmk_keyboard/tmk_core/common.mk	2020-06-22 04:12:21.839951266 +0200
@@ -109,7 +109,7 @@ ifeq (yes,$(strip $(KEYMAP_SECTION_ENABL
 endif
 
 # Version string
-TMK_VERSION := $(shell (git describe --always --dirty=+ || echo 'unknown') 2> /dev/null)
+TMK_VERSION := $(shell (git describe --always --dirty=+ || echo 'Pro_Micro') 2> /dev/null)
 OPT_DEFS += -DTMK_VERSION=$(TMK_VERSION)
 
 
diff -Nburp tmk_keyboard-master/tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/CDC.cpp tmk_keyboard/tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/CDC.cpp
--- tmk_keyboard-master/tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/CDC.cpp	2020-06-03 05:35:47.000000000 +0200
+++ tmk_keyboard/tmk_core/protocol/usb_hid/arduino-1.0.1/cores/arduino/CDC.cpp	2020-06-14 02:34:18.264120533 +0200
@@ -109,7 +109,7 @@ bool WEAK CDC_Setup(Setup& setup)
 			if (1200 == _usbLineInfo.dwDTERate) {
 				// We check DTR state to determine if host port is open (bit 0 of lineState).
 				if ((_usbLineInfo.lineState & 0x01) == 0) {
-					*(uint16_t *)0x0800 = 0x7777;
+					*(uint16_t *)(RAMEND-1) = 0x7777;
 					wdt_enable(WDTO_120MS);
 				} else {
 					// Most OSs do some intermediate steps when configuring ports and DTR can
@@ -119,7 +119,7 @@ bool WEAK CDC_Setup(Setup& setup)
 	
 					wdt_disable();
 					wdt_reset();
-					*(uint16_t *)0x0800 = 0x0;
+					*(uint16_t *)(RAMEND-1) = 0x0;
 				}
 			}
 			return true; 
I really forgot often to write make -f Makefile.32u4 so I modified the main Makefile instead. Modified USB VID/PID to be Sparkfun Pro Micro sketch ID (bootloader + 1). In unimap_plain.c there was a bug imho, should read UNIMAP_PS(...) for alternative layer. Also it took me a while to figure out that the Windows menu key (left of right ctrl) is used as a layer selector. Modified this layer to my liking, ymmv. For compatibility with Katiana bootloader I then edited the bootkey to be written at location RAMEND-1 and not 0x800. Finally edited "unknown" to read "Pro_Micro" in magic version output.

I flashed everything with USBASP adapter with firmware by PeterVH https://github.com/PeterVH/usbasp/tree/v1.06. Even bought two adapters, one to update the other. For reference (you should read out the original firmware first always and also check the fuses to be correct):
avrdude -v -c usbasp -p m8 -e -Ulock:w:0x3f:m -Uhfuse:w:0xd9:m -Ulfuse:w:0xef:m -Uflash:w:usbasp-v1.06-atmega8.hex:i
To flash everything (bootloader and sketch in one go) I use avrdude:
avrdude -v -c usbasp -p m32u4 -e -Ulock:w:0x3f:m -Uefuse:w:0xcb:m -Uhfuse:w:0xd8:m -Ulfuse:w:0xff:m -Uflash:w:Katiana.hex:i -Uflash:w:ps2_usb_32u4.hex:i -Ulock:w:0x2f:m
Later when you want to update the sketch using LAlt+RAlt+Pause key combination and within the following 8 second interval when bootloader waits I used:
avrdude -v -c butterfly -P /dev/ttyACM0 -p m32u4 -Uflash:w:ps2_usb_32u4.hex:i
As you can see avrdude here uses a different protocol and device "ttyACM0" which appears for 8 seconds after the magic key press. Very very handy especially if everything is boxed up or even integrated in a keyboard.

Finally big kudos to all authors of the employed softwares, and especially hasu: Open source at its finest!

frogmaster

29 Jun 2020, 16:13

Thanks hasu, got it to work. If someone get's stuck with modified IBM Model F AT 84-key, then i did the following remaps, i used 32u4 full-key keymap editor:
To get ISO enter, ISO left shift and standard caps, ctrl, alt positioning

Code: Select all

LEFT -> ISO #       
ISO # -> LEFT        
INSERT -> RALT    
LGUI -> LALT     
RCTRL -> CAPS     
CAPS -> RCTRL     
LALT -> LCTRL     
LCTRL -> CAPS      
Hiragana  -> ISO \  
For numpad to navigation cluster mapping:

Code: Select all

ins | home | pg_up | F11
del | end  | pg_dn | F12
    |      |       | printscr
    | up   |       | 
left| down | right | enter
used the following:

Code: Select all

P / -> F11    
P * -> F12    
P - ->  PRINTSCR
P + -> ENTER    
ESC -> INSERT     
P7 -> DELETE    
P8 -> END      
P9 -> Page Down
Num lock -> HOME
Scroll lock -> PAGE UP
It would be much simpler to edit the 84-key instead of the Full-key, if it wasn't for couple of missing keys, present on ibm pc at keyboard pcb, but not on the layout itself.

Just for reference, when watching hid_listen, where can i look up, what the particular r<code> corresponds with, for example, i get r1C when pressing a, where can i look that up?

User avatar
hasu

01 Jul 2020, 07:25

frogmaster,
Oh, AT keyboard. I assumed your keyboard is XT becasue you refered process_cs1.

I didn't realize missing keys on AT editor but I'll add them.
The misssing keys are 39 and 68 in scan code? Is there any other?
https://www.seasip.info/VintagePC/ibm_6450225.html

And can you post pic of your keyboard to show how it was modified?

User avatar
hasu

01 Jul 2020, 07:51

bsdice wrote:
29 Jun 2020, 13:26
Hey there,

I just built a TMK ps2_usb converter out of this Pro Micro clone from ebay:
Try new IBM PC Keyboard Converter(ibmpc_usb) ! This thread is for it :D

  • Desoldered MIC5219 voltage regulator (the 5-legged IC), 2x 10uF (orange pieces), diode D2 (middle and right next to USB socket SMD pins).
  • Bridged J1, bridged the D2 pads. This connects USB 5V straight through to RAW and VCC pins.
Solder bridging J1 is just enough if you use VCC pin for power, not RAW?

This is my thought on Pro Micro power line.
https://github.com/tmk/tmk_keyboard/wik ... der-bridge

And its schematic for reference.
https://github.com/tmk/tmk_keyboard/wik ... #schematic

User avatar
bsdice

01 Jul 2020, 09:03

hasu wrote:
01 Jul 2020, 07:51
Try new IBM PC Keyboard Converter(ibmpc_usb)
Anything particular advantageous with ibmpc_usb for PS/2 keyboards over ps2_usb?
hasu wrote:
01 Jul 2020, 07:51
Solder bridging J1 is just enough if you use VCC pin for power, not RAW?
I am using RAW+GND at the edge to replace cheap tantalums with better through-hole electrolytic capacitor.

As for desoldering the voltage regulator, I was skeptical with regard to parasitic current or oscillations, so I got just rid of it. I ever only use Vusb here and that is 5V.

frogmaster

01 Jul 2020, 22:04

hasu wrote:
01 Jul 2020, 07:25
frogmaster,
Oh, AT keyboard. I assumed your keyboard is XT becasue you refered process_cs1.

I didn't realize missing keys on AT editor but I'll add them.
The misssing keys are 39 and 68 in scan code? Is there any other?
https://www.seasip.info/VintagePC/ibm_6450225.html

And can you post pic of your keyboard to show how it was modified?
List of missing keys in AT 84key, for me at least, (in brackets is what i get when flashing clean unimap.hex):
39 (insert) right of space, to be used as RAlt
53 (left) left of enter, to be used as ISO #
68 (ISO #?) left of P0, to be used as left

KB as modified:
model_f_mod.jpg
model_f_mod.jpg (662.61 KiB) Viewed 16119 times

User avatar
hasu

02 Jul 2020, 04:41

frogmaster,
Interesting. I understand how the numpad part is configured now.

Added the keys to keymap editor. It should make easier to remap hidden keys of IBM AT keyboard.
Can you try this? You can load your existent firmware file at "Base Firmware File:" section and the editor should display your mapping correctly.
http://www.tmk-kbd.com/tmk_keyboard/edi ... mpc_usb_at

Could you post hid_listen log output of starup?
I'd like to check how the converter recognize the keyboard.

Also LED indicators works well?

frogmaster

02 Jul 2020, 08:51

hasu wrote:
02 Jul 2020, 04:41

Added the keys to keymap editor. It should make easier to remap hidden keys of IBM AT keyboard.
Can you try this? You can load your existent firmware file at "Base Firmware File:" section and the editor should display your mapping correctly.
http://www.tmk-kbd.com/tmk_keyboard/edi ... mpc_usb_at

Could you post hid_listen log output of starup?
I'd like to check how the converter recognize the keyboard.

Also LED indicators works well?
Brilliant, thank you, the LED indicators also seem to work fine, managed to get them all to light up with onscreen keyboard.
hid_listen output:

Code: Select all

TMK:0ab0ebf8/LUFA


USB configured.

Keyboard start.
I706 wFF rFA A1711 
PRT:10 ISR:FE90 rAA W2049 wF2 rFA R3052 
ID:0000(2) S3052 wED rFA w00 rFA L3058 

User avatar
hasu

02 Jul 2020, 10:31

frogmaster,
Thanks for your feedback!
It looks ok, the keyboard is recognized as expected.(AT protocol with Scan Code Set 2)

Post Reply

Return to “Workshop”