Author Topic: Question about scancode sets (from a newbie)  (Read 1018 times)

0 Members and 1 Guest are viewing this topic.

Offline Phosphatide

  • Thread Starter
  • Posts: 4
  • Location: California, USA
Question about scancode sets (from a newbie)
« on: Thu, 03 September 2015, 14:55:37 »
I originally made a post in another thread asking about a particular step in a project, but then realized after a proper search in this forum that I might as well just ask this openly here. The project in question is the Bluetooth Model M keyboard: https://geekhack.org/index.php?topic=58015.0

To reiterate the inquiry, I too wish to convert my old keyboard into a fancy Bluetooth one. The brand is "President Micro Systems" as opposed to IBM, which has essential 0 search results everywhere. Nonetheless, it is a keyboard that uses a 5-pin DIN plug so I believe it is an AT keyboard. The project focused on keyboards with a PS/2 connector, which then pushed me to look for an answer to whether I need to take extra steps to make sure my keyboard works. I realized a few days after making a post in the thread that this may just be a general question about scancodes and how exactly do I use them.

As someone who is extremely new to the deeper world of keyboards that is more than just keycap designs and mechanical switch preferences, I've never heard of scancodes until I began reading up on this particular project guide. Furthermore, my attempts to research this topic with relevance to this project have come up short, and I'm still left rather confused by the whole concept. Thus my questions are as follows:

1. What exactly are the attributes and differences to scancode sets besides them having different values from each other for the keys? That much was all I managed to understand from Google and Wikipedia.
2. Specifically, what are some important distinctions between scancode sets 2 and 3? Does that affect what I need to do for this project?
3. Overall for the purposes of properly learning this topic, how does one take scancodes into consideration when working on a project that involves reading inputs from a keyboard? In other words, why is it important to know what scancode set a keyboard is using and how does that affect a project (not just this one I'm looking at)?
4. How does one confirm what scancode set a keyboard is using? In order to test my keyboard for proper functionality I used an adapter I bought from Fry's to plug the device into a PS/2 port, and everything worked out fine. However, does this in any way affect the scancode used (I feel like the answer for this specific question is no but I'm just checking)?

I'm sure there are more questions I would have for this but I need a good baseline first, I guess. I did try to search this site for some info, but I got lost in the search results and wasn't sure how to find a thread that went through the basics. If there's a good reading out there or even here on the forum, please do link them along with any explanations/answers you have so I can enlighten myself with the knowledge of what scancodes are.

Offline Findecanor

  • Posts: 5042
  • Location: Koriko
Re: Question about scancode sets (from a newbie)
« Reply #1 on: Thu, 03 September 2015, 15:55:12 »
I think it is likely that you only need to concern yourself about the AT protocol (set 2).

Set 1 is XT and used by Model F XT, some early third-party keyboards. Many third-party keyboards that speak XT speak AT too - and users change protocol using a toggle switch on the back or bottom of the keyboard.
I think there is some code in the protocol  for the host to tell the keyboard which protocol to talk, but I don't think anybody ever used that.
Set 1 is still used internally by Windows, however... because of historical reasons. When IBM made the AT, they put a microcontroller in the machine that converted from AT to XT scancodes so that DOS programs that interfaced the hardware directly would still work.

Set 2 is AT and (PS/2 is the AT protocol with a smaller plug), but it has been extended now and again and the codes can be a bit complex.

Set 3 was used only by IBM's terminals to their own mainframes. I don't think any PC keyboard or PC has ever supported it. If the keyboard speaks Set 3, then it is most likely a type of Model M from IBM.

I suppose that you intend to build and program the protocol converter. Luckily there are some existing resources:

* Bluetooth keyboards (and mice and gamepads etc.) are using the USB HID protocol in low-speed mode, so you could reuse some USB code.
* Hasu's tmk_keyboard firmware for the Atmel AVR microcontrollers could be a starting point. It is a library suite with different targets for different keyboard controllers and PS/2-to-USB converter. The most common microcontroller to use is the ATmega32u4, which is on the Teensy 2.0 and the Arduino Pro Micro boards (cheaper on eBay).
* Adafruit has a couple of Bluetooth modules. There has been talk about them, but I have not seen anybody use one in a keyboard yet. If you made code for them and released to the community as Open Source then I think that would be much appreciated.
One module is a ATMega32u4 microcontroller with USB and Bluetooth.
The other (Bluefruit EZ-key) is not programmable but you won't need to write any actual Bluetooth code - just feed it keyboard data over a serial line.
« Last Edit: Thu, 03 September 2015, 16:18:13 by Findecanor »
🍉

Offline Phosphatide

  • Thread Starter
  • Posts: 4
  • Location: California, USA
Re: Question about scancode sets (from a newbie)
« Reply #2 on: Fri, 04 September 2015, 03:06:55 »
I can't tell if tmk_keyboard supports my particular keyboard, since it's an AT keyboard and not a PS/2 one. Does that matter in the end once I wire up the keyboard's PCB to a microcontroller, since I was able to successfully test and use the keyboard on my PC using a AT to PS/2 converter? If I go by the information you provided on the differences between the scancode sets, can I assume this will work anyway because my keyboard should be using a standard scancode set anyway (code 2 in particular, most likely) and not need to worry about whether it being an AT keyboard affects anything?

If the answer does involve me doing a bit of clever coding, what do I need to understand about scancodes to guide me towards the solution? I wasn't able to identify any key signs in bcg's tutorial, so perhaps I missed it if there was something.

Offline Findecanor

  • Posts: 5042
  • Location: Koriko
Re: Question about scancode sets (from a newbie)
« Reply #3 on: Fri, 04 September 2015, 03:44:44 »
As I wrote above, PS/2 and AT are the same protocol. The only difference is that PS/2 has a smaller plug.
🍉

Offline Phosphatide

  • Thread Starter
  • Posts: 4
  • Location: California, USA
Re: Question about scancode sets (from a newbie)
« Reply #4 on: Fri, 04 September 2015, 05:26:51 »
Ah, apparently I completely misread that. In that case it looks like I'm probably set for this project.

Thank you so much for the help and information!