RTEMS matrix keyboard driver with UID interface

Pavel Pisa ppisa4lists at pikron.com
Sun Sep 19 15:31:48 UTC 2004


Hello RTEMS users,

I have written RTEMS matrix keyboard driver with UID interface.
This is timer and interrupt activated keyboard driver for matrix keyboard 
directly connected to M9328 MX1 GPIO pins. The driver supports Micro Input 
Driver (UID) interface and works with MicroWindows GUI framework.

It can be usesfull directly to MX1 users or can be used as template
for writing such driver for other architectures.

The driver registers as "/dev/kbd". Because my console sits on
serial port, I have to patch MicroWindows code to open "/dev/kbd"
instead of using standard input.

I have been surprised, that I have not found any example of keyboard
driver RTEMS on the net except included integrated complex PC framebuffer,
which is not good starting point. I hope that my work can help to others.

The driver reports key down and key release events. We need that
to correctly decode cases, when user holds one key for longer time
to change increment for value changes.
Because UID is not clean in that aspect, I have used modifier value
& 0x80 to report release. That is bad.
I suggest to add MV_UID_KBD_RELEASE or something similar
into mw_uid.h device types or add some new field into
MW_UID_MESSAGE -> kbd_t.

http://cmp.felk.cvut.cz/~pisa/#arm

There is also simple MicroWindows screen driver source
and many others goodies on my page.

I need to put together USB device driver and we want
to add DM9000 ETHERNET controller to our board.

Has somebody experience with MX1, USB under RTEMS
or Davicom DM9000 connected to MX1 or other MCU?

Best wishes

                Pavel Pisa
        e-mail: pisa at cmp.felk.cvut.cz
        www:    http://cmp.felk.cvut.cz/~pisa
        work:   http://www.pikron.com



pi at kotik:/usr/src/rtems/microwin-031117/src/drivers# diff input_rtems.c.orig 
input_rtems.c -u
--- input_rtems.c.orig  2001-06-21 08:32:41.000000000 +0200
+++ input_rtems.c       2004-09-13 00:00:39.000000000 +0200
@@ -45,13 +45,14 @@
 static int      MWMou_GetButtonInfo(void);
 static void     MWMou_GetDefaultAccel(int *pscale,int *pthresh);
 static int      MWMou_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp);
+static int      MWMou_Poll(void);

 /* prototypes of the Kbd driver */
 static int     MWKbd_Open(KBDDEVICE *pkd);
 static void    MWKbd_Close(void);
-static void    MWKbd_GetModifierInfo(int *modifiers);
-static int     MWKbd_Read(MWUCHAR *buf, int *modifiers);
-
+static void    MWKbd_GetModifierInfo(MWKEYMOD *modifiers, MWKEYMOD 
*curmodifiers);
+static int     MWKbd_Read(MWKEY *buf,MWKEYMOD *modifiers,MWSCANCODE 
*scancode);
+static int     MWKbd_Poll(void);

 MOUSEDEVICE mousedev =
 {
@@ -60,7 +61,7 @@
     MWMou_GetButtonInfo,
     MWMou_GetDefaultAccel,
     MWMou_Read,
-    NULL
+    MWMou_Poll,
 };


@@ -69,7 +70,7 @@
     MWKbd_Close,
     MWKbd_GetModifierInfo,
     MWKbd_Read,
-    NULL
+    MWKbd_Poll,
 };

 struct MW_UID_MESSAGE m_kbd = { 0 };
@@ -82,6 +83,7 @@
 static const char *Q_NAME        = "MWQ";
 #define            Q_MAX_MSGS      128
 #define            MOUSE_DEVICE    "/dev/mouse"
+#define            KBD_DEVICE      "/dev/kbd"


 /* Open and register driver */
@@ -151,6 +153,15 @@
 }

 /*
+ * Returns non-zero value if event is ready.
+ */
+static int
+MWMou_Poll(void)
+{
+    return ( m_mou.type != MV_UID_INVALID ) ? 1 : 0;
+}
+
+/*
  * Attempt to read bytes from the mouse and interpret them.
  * Returns -1 on error, 0 if either no bytes were read or not enough
  * was read for a complete state, or 1 if the new state was read.
@@ -189,7 +200,11 @@
    /* no valid event */
    m_kbd.type = MV_UID_INVALID;
   /* kbd it is already opened */
+  #ifndef KBD_DEVICE
    kbd_fd = fileno( stdin );
+  #else
+   kbd_fd = open( KBD_DEVICE, O_NONBLOCK );
+  #endif
    /* register kbd driver */
    rc = open_queue_and_register_driver( kbd_fd );
    if( rc )
@@ -209,9 +224,21 @@
  * Return the possible modifiers for the keyboard.
  */
 static  void
-MWKbd_GetModifierInfo(int *modifiers)
+MWKbd_GetModifierInfo(MWKEYMOD *modifiers, MWKEYMOD *curmodifiers)
+{
+    if(modifiers)
+        *modifiers = 0;      /* no modifiers available */
+    if(curmodifiers)
+        *curmodifiers=0;
+}
+
+/*
+ * Returns non-zero value if event is ready.
+ */
+static int
+MWKbd_Poll(void)
 {
-    *modifiers = 0;      /* no modifiers available */
+    return ( m_kbd.type != MV_UID_INVALID ) ? 1 : 0;
 }

 /*
@@ -220,14 +247,13 @@
  * is ready, and 1 if data was read.  This is a non-blocking call.
  */
 static int
-MWKbd_Read(MWUCHAR *buf, int *modifiers)
+MWKbd_Read(MWKEY *buf,MWKEYMOD *modifiers,MWSCANCODE *scancode)
 {
    /* check if new KBD event has been posted */
    if( m_kbd.type != MV_UID_INVALID )
    {
-      *buf = (UCHAR)m_kbd.m.kbd.code;
-/*    *modifiers = m_kbd.m.kbd.modifiers;  */
-      *modifiers = 0;
+      *buf = m_kbd.m.kbd.code;
+      *modifiers = m_kbd.m.kbd.modifiers;

       /* consume event */
       m_kbd.type = MV_UID_INVALID;



More information about the users mailing list