Author Topic: IBM 5251 keyboard PC interface  (Read 12517 times)

0 Members and 1 Guest are viewing this topic.

Offline bhtooefr

  • Thread Starter
  • Posts: 1624
  • Location: Newark, OH, USA
  • this switch can tick sound of music
    • bhtooefr.org
IBM 5251 keyboard PC interface
« on: Mon, 10 May 2010, 07:38:40 »
Goal:
To interface an IBM 5251 keyboard to a modern PS/2 port.

Instructions:
None at this time

Status:
2010-06-16: Wrote preliminary decoding code last night. This is completely untested, and the only goal of this code is to dump raw scancodes to the serial terminal. Pastebin: http://pastebin.com/JnhEmgm2
2010-05-10: Signs of life from keyboard when supplying +5 and -5 VDC, and reading the make/break pin, need to figure out how to properly handle parallel I/O out of a 74164 SIPO shift register on an Arduino. This may end up requiring a PISO shift register for the easiest way to do it, as there's sample code for using a PISO shift register out there, but nothing that I can find for directly using parallel I/O.

Useful documents:
kbdbabel's schematic of the 5251 keyboard
Thread on Arduino forum
« Last Edit: Wed, 16 June 2010, 07:29:07 by bhtooefr »

Offline JBert

  • Posts: 764
IBM 5251 keyboard PC interface
« Reply #1 on: Wed, 12 May 2010, 15:45:49 »
It's been a while since I've done some embedded programming but what is your exact problem?

Can't you configure 8 pins to use a digital input, then somehow try to track the clocking signal to know when it is safe to copy the input bit states to memory?

Sadly I haven't got this keyboard nor an Arduino to play with.
IBM Model F XT + Soarer's USB Converter || Cherry G80-3000/Clears

The storage list:
IBM Model F AT || Cherry G80-3000/Blues || Compaq MX11800 (Cherry brown, bizarre layout) || IBM KB-8923 (model M-style RD) || G81-3010 Hxx || BTC 5100C || G81-3000 Sxx || Atari keyboard (?)


Currently ignored by: nobody?

Disclaimer: we don\'t help you save money on [strike]keyboards[/strike] hardware, rather we make you feel less bad about your expense.
[/SIZE]

Offline bhtooefr

  • Thread Starter
  • Posts: 1624
  • Location: Newark, OH, USA
  • this switch can tick sound of music
    • bhtooefr.org
IBM 5251 keyboard PC interface
« Reply #2 on: Wed, 12 May 2010, 17:18:38 »
I'm not sure what the clock signal is (unless I'm just supposed to figure it out by polling the digital I/Os quickly, and hoping I get a stable clock,) and I'm such a n00b that I don't have any idea how to handle parallel I/O. Basically, if there's not a sketch someone already made to handle parallel input, it's not getting done.

Most likely what I'll end up doing is ship the keyboard to someone else to have them make an adapter. Expensive on a 5251 board, but such is life.

Offline ch_123

  • * Exalted Elder
  • Posts: 5860
IBM 5251 keyboard PC interface
« Reply #3 on: Wed, 12 May 2010, 17:27:27 »
I assume that the 5251's signalling protocol isn't on kbdbabel?

You could ask him how he determines the signalling protocol. Another idea is to determine the type of keyboard controller it has and pray that you can find a manual for it...

Offline bhtooefr

  • Thread Starter
  • Posts: 1624
  • Location: Newark, OH, USA
  • this switch can tick sound of music
    • bhtooefr.org
IBM 5251 keyboard PC interface
« Reply #4 on: Wed, 12 May 2010, 17:45:23 »
It's all IBM-specific parts for the keyboard controller, and he doesn't have the signalling.

Even if he did, though, I wouldn't have the foggiest idea of how to get it working properly.

Offline ch_123

  • * Exalted Elder
  • Posts: 5860
IBM 5251 keyboard PC interface
« Reply #5 on: Wed, 12 May 2010, 18:03:39 »
I remember reading something like this with someone who was converting a Sun mouse to USB...

Really what you need is a logic analyzer. You'd need to apply 5V and and watch what is coming across the data lines and try and figure out what is going on, using something like the 3278 protocol as a reference.

Of course then you'd need something that translates it all and sends across USB... definitely easier said than done. :D

Offline bhtooefr

  • Thread Starter
  • Posts: 1624
  • Location: Newark, OH, USA
  • this switch can tick sound of music
    • bhtooefr.org
IBM 5251 keyboard PC interface
« Reply #6 on: Thu, 13 May 2010, 09:31:43 »
Based on some discussion on the Arduino forum, some discussion in Freenode/#fmcg, and some Googling, I think I might have a solution to reading this keyboard.

Digital pins 0 through 7 on the Arduino are all on one "port," something that can be quickly read, and operated on.

The "Data Av." pin is apparently Data Available, so it should be something I can interrupt on. So, ignoring POR, and ignoring the PS/2 stuff, here's what I'm thinking this will look like:

Main:
Interrupt on Data Av.
Read PORTD
Call decode routine, passing value of PORTD

Decode routine:
If top bit = 1, then set make/break accordingly
Look up bottom 7 bits in 5251 to AT lookup table (I'll use AT scancodes instead of PS/2, even though it's on a PS/2 port. AT scancodes match up more closely to the XT layout.)
Create scancode from make/break and the looked up scancode
Call PS/2 send routine, passing formed scancode

Offline ch_123

  • * Exalted Elder
  • Posts: 5860
IBM 5251 keyboard PC interface
« Reply #7 on: Thu, 13 May 2010, 10:11:36 »
Reminds me of VHDL... What language do the Arduinos use anyway?

Offline bhtooefr

  • Thread Starter
  • Posts: 1624
  • Location: Newark, OH, USA
  • this switch can tick sound of music
    • bhtooefr.org
IBM 5251 keyboard PC interface
« Reply #8 on: Thu, 13 May 2010, 10:59:16 »
Wiring, which is essentially a simplified C++.

Offline JBert

  • Posts: 764
IBM 5251 keyboard PC interface
« Reply #9 on: Thu, 13 May 2010, 13:53:26 »
Ah, I see you figured out how to apply what I was talking about. Keep us updated!
IBM Model F XT + Soarer's USB Converter || Cherry G80-3000/Clears

The storage list:
IBM Model F AT || Cherry G80-3000/Blues || Compaq MX11800 (Cherry brown, bizarre layout) || IBM KB-8923 (model M-style RD) || G81-3010 Hxx || BTC 5100C || G81-3000 Sxx || Atari keyboard (?)


Currently ignored by: nobody?

Disclaimer: we don\'t help you save money on [strike]keyboards[/strike] hardware, rather we make you feel less bad about your expense.
[/SIZE]

Offline bhtooefr

  • Thread Starter
  • Posts: 1624
  • Location: Newark, OH, USA
  • this switch can tick sound of music
    • bhtooefr.org
IBM 5251 keyboard PC interface
« Reply #10 on: Wed, 16 June 2010, 07:33:35 »
So I'm working on the side of the code that fetches keystrokes from the keyboard. This is completely untested - I didn't feel like hooking up the keyboard to the Arduino last night. Pastebin link: http://pastebin.com/JnhEmgm2

The actual code, posted here as well:

Code: [Select]
/*
 *  IBM 5251 Keyboard Protocol Converter
 *  Version 20100615-1
 *
 *  Copyright 2010 Eric Rucker. All rights reserved.
 *  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *
 *  THIS SOFTWARE IS PROVIDED BY ERIC RUCKER ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ERIC RUCKER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *  The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Eric Rucker.
 */
 
const int pinDataAv = 2;                                // pin for available data

const int pinD0 = 3;                                    // data pins
const int pinD1 = 4;
const int pinD2 = 5;
const int pinD3 = 6;
const int pinD4 = 7;
const int pinD5 = 8;
const int pinD6 = 9;

const int pinMakeBrk = 10;                              // keyboard make/break bit

const int pinAck = 11;                                  // acknowledge pin

boolean boKeyboardData[8];                                 // variable to hold data from keyboard

boolean boByteHandled = true;                                     // mark byte as unhandled

void setup() {
  attachInterrupt(pinDataAv, dataAvailable, CHANGE);    // set up interrupt on available data pin
 
  pinMode(pinD0, INPUT);                                // set up pins
  pinMode(pinD1, INPUT);
  pinMode(pinD2, INPUT);
  pinMode(pinD3, INPUT);
  pinMode(pinD4, INPUT);
  pinMode(pinD5, INPUT);
  pinMode(pinD6, INPUT);
  pinMode(pinMakeBrk, INPUT);
 
  pinMode(pinAck, OUTPUT);
  digitalWrite(pinAck, HIGH);
 
  Serial.begin(1200);                                   // set up serial debugging
}

void loop() {
  while (boByteHandled == false) {
    // this needs to be changed for the real code
    outputKeyboardData(boKeyboardData);
   
    boByteHandled = true;
  }
}
 
void dataAvailable() {
  boByteHandled = false;
 
  boKeyboardData[0] = digitalRead(pinD0);
  boKeyboardData[1] = digitalRead(pinD1);
  boKeyboardData[2] = digitalRead(pinD2);
  boKeyboardData[3] = digitalRead(pinD3);
  boKeyboardData[4] = digitalRead(pinD4);
  boKeyboardData[5] = digitalRead(pinD5);
  boKeyboardData[6] = digitalRead(pinD6);
  boKeyboardData[7] = digitalRead(pinMakeBrk);
 
  digitalWrite(pinAck, LOW);
  delayMicroseconds(100);
  digitalWrite(pinAck, HIGH);
}

void outputKeyboardData(boolean* boData) {
  char outputText[8];
 
  for (int x = 0; x < 8; x++) {
    if (boData[x] == false) {
      outputText[x] = '0';
    }
    else {
      outputText[x] = '1';
    }
  }
 
  Serial.println(outputText);
}


BTW, what I could use the most help with is the PS/2 side of things - if someone could write a generic PS/2 library that lets me feed PS/2 scan codes in, and handles all communication with the PS/2 host, that would be great.

I can handle generating the scan codes, and feeding them in, however.

Offline dfj

  • Posts: 171
  • Location: Canada
  • Visit our irc: #geekhack on libera.chat!
Oi, glad ye've started!
« Reply #11 on: Thu, 24 June 2010, 16:10:49 »
Quote from: bhtooefr;193606
So I'm working on the side of the code that fetches keystrokes from the keyboard. This is completely untested - I didn't feel like hooking up the keyboard to the Arduino last night.

BTW, what I could use the most help with is the PS/2 side of things - if someone could write a generic PS/2 library that lets me feed PS/2 scan codes in, and handles all communication with the PS/2 host, that would be great.

I can handle generating the scan codes, and feeding them in, however.


I'm going to be back in firmware land within the next day or so - and the PS2 stuff is pretty fresh in my mind.

  I've got 2-3 interesting firmware thangs on my mind, but doing device-side PS2 is of definite interest. I would like to write it such that it can be run on the teensy(++), mnemonix's driver, the arduino(168+), and some random atinyxx.
  If I'm not ready to give it my full attention by the time you are ready, (which might be right now, for all I know), then I can just feed you lots of code samples, links, answer questions (I am on the IRC way too much lately) and otherwise get you started with making an arduino library for device-side PS2.
  Nice thing about surfacing device-side PS2 is you can test it largely through the ps2->USB converters and then perhaps a KVM until you are brave/cocky enough to stuff it straight into a PC. :)

looking forward,
dfj
Fave Switch manus: IBM, Topre, Matias, ...