Practical library series : PS/2 (Keyboard, Mouse)

Languages

日本語版はこちら:実用ライブラリシリーズ:PS/2 (キーボード、マウス)

Overview

PS/2 device is a legacy human interface device.

It's easy to use for input device on micro controller.

So I decided to design the library.

The library use only 2 pins (CLK and DAT).

It use interrupt based receive, so your application codes will simplify.

Feautures

  • Supported a PS/2 keyboard and a mouse.
  • Interrupt based receiver.
  • Simple interfaces.

Circuits

Projects

The library project is PS2

The test program is PS2_TestProgram

How to use it?

PS2Keyboard class

#include "mbed.h"
#include "PS2Keyboard.h"

PS2Keyboard ps2kb(p12, p11); // CLK, DAT

int main() {
    PS2Keyboard::keyboard_event_t evt_kb;

    while (1) {
        if (ps2kb.processing(&evt_kb)) {
            printf("[%d]:", evt_kb.type);
            for (int i = 0; i < evt_kb.length; i++) {
                printf("%02x ", evt_kb.scancode[i]);
            }
            printf("\n");
        }
    }
}

PS2Mouse class

#include "mbed.h"
#include "PS2Mouse.h"

PS2Mouse ps2ms(p23, p22); // CLK, DAT

int main() {
    PS2Mouse::mouse_event_t evt_ms;
    while (1) {
        if (ps2ms.processing(&evt_ms)) {
            printf("%c%c%c:%4d,%4d,%2d\n",
                evt_ms.left ? 'L' : '.',
                evt_ms.center ? 'C' : '.',
                evt_ms.right ? 'R' : '.',
                evt_ms.x, evt_ms.y, evt_ms.z);
        }
    }
}

References

Limits

  • Some PS/2 mouses will transmit data high rates. In this case, the internal buffer will overflow.


0 comments

You need to log in to post a comment