summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/mouse
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libmisc/mouse')
-rw-r--r--cpukit/libmisc/mouse/README214
-rw-r--r--cpukit/libmisc/mouse/mouse_parser.c311
-rw-r--r--cpukit/libmisc/mouse/mouse_parser.h108
-rw-r--r--cpukit/libmisc/mouse/serial_mouse.c184
-rw-r--r--cpukit/libmisc/mouse/serial_mouse.h156
5 files changed, 973 insertions, 0 deletions
diff --git a/cpukit/libmisc/mouse/README b/cpukit/libmisc/mouse/README
new file mode 100644
index 0000000000..ab684a6d0b
--- /dev/null
+++ b/cpukit/libmisc/mouse/README
@@ -0,0 +1,214 @@
+#
+# $Id$
+#
+
+SOURCE: http://www.kryslix.com/nsfaq/Q.12.html
+
+Subject: What protocol do mice use?
+Date: 09/16/97
+Updated: 11/16/00 This document was adapated from a web page produced by
+Tomi Engdahl <then@delta.hut.fi>
+Microsoft serial mouse
+Description
+
+The Microsoft serial mouse is the most popular 2 button mouse. It is
+supported by all major operating systems. The maximum tracking rate for
+a Microsoft mouse is 40 reports/second * 127 counts per report, in other
+words, 5080 counts per second. The most common range for mice is is 100
+to 400 CPI (counts per inch) but can be up to 1000 CPI. A 100CPI mouse
+can discriminate motion up to 50.8 inches/second while a 400 CPI mouse
+can only discriminate motion up to 12.7 inches/second.
+Pinout
+
+9 pin 25 pin Line Comments
+shell 1 GND
+3 2 TD Serial data from host to mouse (only for power)
+2 3 RD Serial data from mouse to host
+7 4 RTS Positive voltage to mouse
+8 5 CTS
+6 6 DSR
+5 7 SGND
+4 20 DTR Positive voltage to mouse and reset/detection
+
+RTS = Request to Send CTS = Clear to Send
+DSR = Data Set Ready DTR = Data Terminal Ready
+GND = Protective Ground SGND = Signal Ground
+
+To function correctly, both the RTS and DTR lines must be
+positive. DTR/DSR and RTS/CTS must NOT be shorted. RTS may be toggled
+negative for at least 100ms to reset the mouse. (After a cold boot, the
+RTS line is usually negative. This provides an automatic toggle when
+RTS is brought positive). When DTR is toggled the mouse should send a
+single byte 0x45 (ASCII 'M').
+
+Serial data parameters:
+1200bps, 7 databits, 1 stop-bit
+
+Data packet format:
+
+Data is sent in 3 byte packets for each event (a button is pressed or
+released or the mouse moves):
+
+ D7 D6 D5 D4 D3 D2 D1 D0
+
+Byte 1 X 1 LB RB Y7 Y6 X7 X6
+Byte 2 X 0 X5 X4 X3 X2 X1 X0
+Byte 3 X 0 Y5 Y4 Y3 Y2 Y1 Y0
+
+LB is the state of the left button (1 means down)
+RB is the state of the right button (1 means down)
+X7-X0 movement in X direction since last packet (signed byte)
+Y7-Y0 movement in Y direction since last packet (signed byte)
+
+The high order bit of each byte (D7) is ignored. Bit D6 indicates the start of an event, which allows the software to synchronize with the mouse.
+
+Graphical representation of a packet
+
+ 1st byte 2nd byte 3rd byte
+ ================ =============== ================
+ - 1 ? ? Y Y X X - 0 X X X X X X - 0 Y Y Y Y Y Y
+ ================ =============== ================
+ | | \ / \ / \---------/ \---------/
+ | | | | | |
+ | | | \----\ | |
+ | | \--------|-------|--------\ |
+ | | / \ /---------\ / \ /---------\
+ | | ================ =================
+ | | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ Left Button --/ | ================ =================
+Right Button ----/ X increment Y increment
+
+3 Button Logitech extension
+
+Logitech extended the 2 button mouse protocol to support 3 button mice
+by adding a 4th byte when the middle button is pressed (and the first
+packet after it is released). If a 4th byte is encountered (i.e., an
+extra byte with D6 set to 0) then D5 of that byte (0x20) indicates the
+status of the middle mouse button.
+
+Mouse systems mouse
+
+Serial data parameters:
+
+1200bps, 8 databits, 1 stop-bit
+
+5 byte Mouse Systems packet
+
+ D7 D6 D5 D4 D3 D2 D1 D0
+
+Byte 1 1 0 0 0 0 LB CB RB
+Byte 2 X7 X6 X5 X4 X3 X2 X1 X0
+Byte 3 Y7 Y6 Y5 Y4 Y3 Y4 Y1 Y0
+Byte 4 X7' X6' X5' X4' X3' X2' X1' X0'
+Byte 5 Y7' Y6' Y5' Y4' Y3' Y4' Y1' Y0'
+
+LB is left button state (0=pressed, 1=released)
+CB is center button state (0=pressed, 1=released)
+RB is right button state (0=pressed, 1=released)
+X7-X0 movement in X direction since last packet in signed byte
+ format (-128..+127), positive direction right
+Y7-Y0 movement in Y direction since last packet in signed byte
+ format (-128..+127), positive direction up
+X7'-X0' movement in X direction since sending of X7-X0 packet in signed byte
+ format (-128..+127), positive direction right
+Y7'-Y0' movement in Y direction since sending of Y7-Y0 in signed byte
+ format (-128..+127), positive direction up
+
+The last two bytes in the packet (bytes 4 and 5) contain information
+about movement data changes which have occured after data bytes 2 and
+3 have been sent.
+
+PS/2 mouse
+
+The standard PS/2 mouse (such as the Logitech mouse) defaults to 160 CPI
+and can be switched to 40, 80, 160 or 320 CPI via software. The Microsoft
+mouse driver for Windows 3.x and Windows 95 defaults to 160 counts per
+inch. The maximum tracking rate for PS/2 mouse is 40 reports/second *
+255 counts per report, or 10200 counts per second. A 100 CPI mouse could
+discriminate motion up to 102 inches per second while a 400 CPI mouse
+could discriminate motion up to 25.2 inches per second.
+
+Connector pinout
+
+Pin Wire Name
+1 DATA
+2 Reserved
+3 Ground
+4 +5V Supply
+5 CLK
+6 Reserved
+Shield Chassis
+
+Packet Format
+
+ D7 D6 D5 D4 D3 D2 D1 D0
+Byte 1 XV XV YS XS 1 M R L
+Byte 2 X7 X6 X5 X4 X3 X2 X1 X0
+Byte 3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0
+
+L Left button state (1 = pressed down)
+M Middle button state (1 = pressed down)
+R Right button state (1 = pressed down)
+X0-X7 Movement in X direction
+Y0-Y7 Movement in Y direction
+XS,YS Movement data sign bits (1 = negative)
+XV,YV Movement data overflow bits (1 = overflow has occured)
+
+Physical connector
+
+The PS/2 mouse connector has the following pinout when looking at the
+connector on the back of the computer:
+
+ 4 u 6
+ 1 . 2
+ 3 5
+
+1. GND
+2. +5V
+3. DATA
+4. CLOCK
+5. Not used
+6. Not used
+
+Bi-directional transmission is controlled by the CLK and DATA lines. Both
+are fed by an open collector device which lets either host or mouse force
+the line to "0". During non-transmission, CLK is at "1" and DATA can be at
+"0" or "1".
+
+The host can inhibit mouse transmission by forcing CLK to "0". If the
+host inhibits the mouse while it is transmitting, the byte must be
+retransmitted (if the inhibit state arrived before the 11th clock).
+
+Receiving data: Check 'clock'. If inactive, there is a bit on the 'data'
+line. Each transmission unit is one start bit, eight data bits, odd
+parity and one stop bit. Start bits are low, stop bits high. Each clock
+active or inactive period is 30 to 50 microseconds. Data transition to
+falling edge of clock is 5 to 25 microseconds.
+
+Sending: Check that both clock and data are high. Pull down data for
+start bit, and start clocking.
+
+NOTE: Logitech has made the extension to this protocol to allow three
+buttons (the M bit is always 0 on 2 button mice).
+
+References
+
+* Original PC mouse info page by Tomi Engdahl
+ http://www.hut.fi/~then/mytexts/mouse.html
+
+* PC Magazine May 28, 1991
+
+* Programmer's Reference to Genius Mouse
+ ftp://x2ftp.oulu.fi/pub/msdos/programming/docs/gmouse.doc
+
+* Logitech Pointing Device Hardware Information Product Support Document # 1410
+ ftp://ftp.logitech.com/pub/TechSupport/MOUSE/HELP/1410.txt
+
+* Mice: How do they work? by Richard Torrens
+ http://box.argonet.co.uk/users/4qd/meece.html
+
+* In Pursuit Of The Perfect Portable Pointer by Intelink Electronics
+from EDN Products Edition April 16, 1977 pages 43-45
+
+* Programming the Microsoft Mouse
+ http://www.geocities.com/SiliconValley/2151/mouse.html
diff --git a/cpukit/libmisc/mouse/mouse_parser.c b/cpukit/libmisc/mouse/mouse_parser.c
new file mode 100644
index 0000000000..9d78bbd979
--- /dev/null
+++ b/cpukit/libmisc/mouse/mouse_parser.c
@@ -0,0 +1,311 @@
+/*
+ * This code is derived from a UNIX Serial Port Mouse Driver with
+ * the following notice:
+ *
+ * ==================================================================
+ * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
+ * Portions Copyright (c) 1991 David I. Bell
+ * Permission is granted to use, distribute, or modify this source,
+ * provided that this copyright notice remains intact.
+ *
+ * UNIX Serial Port Mouse Driver
+ *
+ * This driver opens a serial port directly, and interprets serial data.
+ * Microsoft, PC, Logitech and PS/2 mice are supported. The PS/2 mouse
+ * is only supported if the OS runs the mouse byte codes through the
+ * serial port.
+ *
+ * Mouse Types Supported: pc ms, logi, ps2
+ * ==================================================================
+ *
+ * It has been modified to support the concept of being just a parser
+ * fed data from an arbitrary source. It is independent of either
+ * a PS/2 driver or a serial port.
+ *
+ * It was moved to cpukit/libmisc/mouse by Joel Sherrill.
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h> /* strcmp */
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <rtems.h>
+#include <rtems/mouse_parser.h>
+#include <rtems/mw_uid.h>
+
+/* states for the mouse */
+#define IDLE 0 /* start of byte sequence */
+#define XSET 1 /* setting x delta */
+#define YSET 2 /* setting y delta */
+#define XADD 3 /* adjusting x delta */
+#define YADD 4 /* adjusting y delta */
+
+/* values in the bytes returned by the mouse for the buttons*/
+#define PC_LEFT_BUTTON 4
+#define PC_MIDDLE_BUTTON 2
+#define PC_RIGHT_BUTTON 1
+
+#define MS_LEFT_BUTTON 2
+#define MS_RIGHT_BUTTON 1
+
+#define PS2_CTRL_BYTE 0x08
+#define PS2_LEFT_BUTTON 1
+#define PS2_RIGHT_BUTTON 2
+
+/* Bit fields in the bytes sent by the mouse.*/
+#define TOP_FIVE_BITS 0xf8
+#define BOTTOM_THREE_BITS 0x07
+#define TOP_BIT 0x80
+#define SIXTH_BIT 0x40
+#define BOTTOM_TWO_BITS 0x03
+#define THIRD_FOURTH_BITS 0x0c
+#define BOTTOM_SIX_BITS 0x3f
+
+/* local data */
+static int state; /* IDLE, XSET, ... */
+static BUTTON buttons; /* current mouse buttons pressed*/
+static BUTTON availbuttons; /* which buttons are available */
+static COORD xd; /* change in x */
+static COORD yd; /* change in y */
+
+static int left; /* because the button values change */
+static int middle; /* between mice, the buttons are */
+static int right; /* redefined */
+
+static int (*parse)( int ); /* parse routine */
+
+/* local routines*/
+static int ParsePC(int); /* routine to interpret PC mouse */
+static int ParseMS(int); /* routine to interpret MS mouse */
+static int ParsePS2(int); /* routine to interpret PS/2 mouse */
+
+/*
+ * Open up the mouse device.
+ * Returns the fd if successful, or negative if unsuccessful.
+ */
+int mouse_parser_initialize(const char *type)
+{
+ /* set button bits and parse procedure*/
+ if (!strcmp(type, "pc") || !strcmp(type, "logi")) {
+ /* pc or logitech mouse*/
+ left = PC_LEFT_BUTTON;
+ middle = PC_MIDDLE_BUTTON;
+ right = PC_RIGHT_BUTTON;
+ parse = ParsePC;
+ } else if (strcmp(type, "ms") == 0) {
+ /* microsoft mouse*/
+ left = MS_LEFT_BUTTON;
+ right = MS_RIGHT_BUTTON;
+ middle = 0;
+ parse = ParseMS;
+ } else if (strcmp(type, "ps2") == 0) {
+ /* PS/2 mouse*/
+ left = PS2_LEFT_BUTTON;
+ right = PS2_RIGHT_BUTTON;
+ middle = 0;
+ parse = ParsePS2;
+ } else
+ return -1;
+
+ printk("Device: /dev/mouse -- mouse type is: %s\n", type );
+
+ /* initialize data*/
+ availbuttons = left | middle | right;
+ state = IDLE;
+ buttons = 0;
+ xd = 0;
+ yd = 0;
+ return 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.
+ * When a new state is read, the current buttons and x and y deltas
+ * are returned. This routine does not block.
+ */
+int MOU_Data( int ch, COORD *dx, COORD *dy, COORD *dz, BUTTON *bptr)
+{
+ int b;
+
+ if ( !parse ) {
+ printk( "Mouse parser is not initialized!\n" );
+ return -1;
+ }
+
+ /*
+ * Loop over all the bytes read in the buffer, parsing them.
+ * When a complete state has been read, return the results,
+ * leaving further bytes in the buffer for later calls.
+ */
+ if ( (*parse)( ch ) ) {
+ *dx = xd;
+ *dy = yd;
+ *dz = 0;
+ b = 0;
+ if (buttons & left)
+ b |= LBUTTON;
+ if (buttons & right)
+ b |= RBUTTON;
+ if (buttons & middle)
+ b |= MBUTTON;
+ *bptr = b;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Input routine for PC mouse.
+ * Returns nonzero when a new mouse state has been completed.
+ */
+static int ParsePC(int byte)
+{
+ int sign; /* sign of movement */
+
+ switch (state) {
+ case IDLE:
+ if ((byte & TOP_FIVE_BITS) == TOP_BIT) {
+ buttons = ~byte & BOTTOM_THREE_BITS;
+ state = XSET;
+ }
+ break;
+
+ case XSET:
+ sign = 1;
+ if (byte > 127) {
+ byte = 256 - byte;
+ sign = -1;
+ }
+ xd = byte * sign;
+ state = YSET;
+ break;
+
+ case YSET:
+ sign = 1;
+ if (byte > 127) {
+ byte = 256 - byte;
+ sign = -1;
+ }
+ yd = -byte * sign;
+ state = XADD;
+ break;
+
+ case XADD:
+ sign = 1;
+ if (byte > 127) {
+ byte = 256 - byte;
+ sign = -1;
+ }
+ xd += byte * sign;
+ state = YADD;
+ break;
+
+ case YADD:
+ sign = 1;
+ if (byte > 127) {
+ byte = 256 - byte;
+ sign = -1;
+ }
+ yd -= byte * sign;
+ state = IDLE;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Input routine for Microsoft mouse.
+ * Returns nonzero when a new mouse state has been completed.
+ */
+static int ParseMS(int byte)
+{
+ switch (state) {
+ case IDLE:
+ if (byte & SIXTH_BIT) {
+ buttons = (byte >> 4) & BOTTOM_TWO_BITS;
+ yd = ((byte & THIRD_FOURTH_BITS) << 4);
+ xd = ((byte & BOTTOM_TWO_BITS) << 6);
+ state = XADD;
+ }
+ break;
+
+ case XADD:
+ xd |= (byte & BOTTOM_SIX_BITS);
+ state = YADD;
+ break;
+
+ case YADD:
+ yd |= (byte & BOTTOM_SIX_BITS);
+ state = IDLE;
+ if (xd > 127)
+ xd -= 256;
+ if (yd > 127)
+ yd -= 256;
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Input routine for PS/2 mouse.
+ * Returns nonzero when a new mouse state has been completed.
+ */
+static int ParsePS2(int byte)
+{
+ switch (state) {
+ case IDLE:
+ if (byte & PS2_CTRL_BYTE) {
+ buttons = byte &
+ (PS2_LEFT_BUTTON|PS2_RIGHT_BUTTON);
+ state = XSET;
+ }
+ break;
+
+ case XSET:
+ if(byte > 127)
+ byte -= 256;
+ xd = byte;
+ state = YSET;
+ break;
+
+ case YSET:
+ if(byte > 127)
+ byte -= 256;
+ yd = -byte;
+ state = IDLE;
+ return 1;
+ }
+ return 0;
+}
+
+/* generic mouse parser */
+void mouse_parser_enqueue( unsigned char *buffer, size_t size )
+{
+ COORD dx;
+ COORD dy;
+ COORD dz;
+ BUTTON bptr;
+
+ while( size-- ) {
+ if ( MOU_Data( *buffer++, &dx, &dy, &dz, &bptr ) ) {
+ struct MW_UID_MESSAGE m;
+
+ m.type = MV_UID_REL_POS;
+ /* buttons definitons have been selected to match */
+ m.m.pos.btns = bptr;
+ m.m.pos.x = dx;
+ m.m.pos.y = dy;
+ m.m.pos.z = dz;
+ /* printk( "Mouse: msg: dx=%d, dy=%d, btn=%X\n", dx, dy, bptr ); */
+ uid_send_message( &m );
+ }
+ }
+}
+
diff --git a/cpukit/libmisc/mouse/mouse_parser.h b/cpukit/libmisc/mouse/mouse_parser.h
new file mode 100644
index 0000000000..59b6abb2f3
--- /dev/null
+++ b/cpukit/libmisc/mouse/mouse_parser.h
@@ -0,0 +1,108 @@
+/*
+ * This file is the header file for the Mouse Parser Engine which
+ * is derived from a UNIX Serial Port Mouse Driver with the following
+ * notice:
+ *
+ * ==================================================================
+ * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
+ * Portions Copyright (c) 1991 David I. Bell
+ * Permission is granted to use, distribute, or modify this source,
+ * provided that this copyright notice remains intact.
+ *
+ * UNIX Serial Port Mouse Driver
+ *
+ * This driver opens a serial port directly, and interprets serial data.
+ * Microsoft, PC, Logitech and PS/2 mice are supported. The PS/2 mouse
+ * is only supported if the OS runs the mouse byte codes through the
+ * serial port.
+ *
+ * Mouse Types Supported: pc ms, logi, ps2
+ * ==================================================================
+ *
+ * It has been modified to support the concept of being just a parser
+ * fed data from an arbitrary source. It is independent of either
+ * a PS/2 driver or a serial port.
+ *
+ * It was moved to cpukit/libmisc/mouse by Joel Sherrill.
+ *
+ * $Id$
+ */
+
+#ifndef __MOUSE_PARSER_h__
+#define __MOUSE_PARSER_h__
+
+#include <rtems/mw_uid.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This is the mask for the right button.
+ *
+ * @note Use the same definitions as the user interface.
+ */
+#define RBUTTON MV_BUTTON_RIGHT
+
+/**
+ * This is the mask for the center button.
+ *
+ * @note Use the same definitions as the user interface.
+ */
+#define MBUTTON MV_BUTTON_CENTER
+
+/**
+ * This is the mask for the left button.
+ *
+ * @note Use the same definitions as the user interface.
+ */
+#define LBUTTON MV_BUTTON_LEFT
+
+/**
+ * This type is the device coordinates.
+ */
+typedef int COORD;
+
+/**
+ * This type is the mouse button mask.
+ */
+typedef unsigned int BUTTON;
+
+/**
+ * This type defines a pointer to the enqueue method. It is
+ * available since some device drivers keep pointers to the method
+ * to know when to enqueue or not.
+ */
+typedef void (*mouse_parser_enqueue_handler)(unsigned char *, size_t);
+
+/**
+ * @brief Initialize the Mouse Parser Engine
+ *
+ * This method initializes the Mouse Parser Engine for the mouse
+ * of @a type. The @a type should be one of the following strings:
+ * pc ms, logi, ps2.
+ *
+ * @a param[in] type indicates the type of mouse.
+ *
+ * @return This method returns 0 on success and -1 on error.
+ */
+int mouse_parser_initialize(const char *type);
+
+/**
+ * @brief Enqueue Input to the Mouse Parser Engine
+ *
+ * This method is used to pass mouse input to the Mouse Parser Engine.
+ *
+ * @a param[in] buffer is the data to enqueue
+ * @a param[in] size is the amount of data to enqueue
+ */
+void mouse_parser_enqueue(
+ unsigned char *buffer,
+ size_t size
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/cpukit/libmisc/mouse/serial_mouse.c b/cpukit/libmisc/mouse/serial_mouse.c
new file mode 100644
index 0000000000..c61401626d
--- /dev/null
+++ b/cpukit/libmisc/mouse/serial_mouse.c
@@ -0,0 +1,184 @@
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <rtems/libio.h>
+#include <termios.h>
+#include <rtems/termiostypes.h>
+#include <rtems/mouse_parser.h>
+#include <rtems/serial_mouse.h>
+
+int serial_mouse_fd = -1;
+const char *serial_mouse_device;
+const char *serial_mouse_type;
+
+int serial_mouse_l_rint(int c, struct rtems_termios_tty *tp)
+{
+ unsigned char buf = c;
+
+ /* call mouse_parser( void *ptr, char *buffer, int size ) */
+ mouse_parser_enqueue( &buf, 1 );
+ return 0;
+}
+
+static struct rtems_termios_linesw serial_mouse_linesw = {
+ .l_open = NULL,
+ .l_close = NULL,
+ .l_read = NULL,
+ .l_write = NULL,
+ .l_rint = serial_mouse_l_rint,
+ .l_start = NULL,
+ .l_ioctl = NULL,
+ .l_modem = NULL
+};
+
+
+/*
+ * Serial Mouse - device driver INITIALIZE entry point.
+ */
+rtems_device_driver serial_mouse_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ bool status;
+
+ status = bsp_get_serial_mouse_device(
+ &serial_mouse_device,
+ &serial_mouse_type
+ );
+
+ (void) rtems_io_register_name( "/dev/mouse", major, 0 );
+
+ rtems_termios_linesw[ 6 ] = serial_mouse_linesw;
+
+ return RTEMS_SUCCESSFUL;
+}
+
+/*
+ * serial_mouse - device driver OPEN entry point
+ */
+rtems_device_driver serial_mouse_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *args
+)
+{
+ struct termios termios_attr;
+ int status;
+ int disc = 6;
+
+ /* XXX open(2) the configured /dev/comX */
+ /* XXX save the file descriptor */
+ serial_mouse_fd = open( serial_mouse_device, O_RDONLY );
+ if ( serial_mouse_fd == -1 ) {
+ printk(
+ "Error opening serial_mouse device on %s\n",
+ serial_mouse_device
+ );
+ return RTEMS_IO_ERROR;
+ }
+
+ /* 1200-8-N-1, without hardware flow control */
+ /* BSP_uart_init( BSP_UART_PORT, 1200, CHR_8_BITS, 0, 0, 0 ); */
+ status = tcgetattr(serial_mouse_fd, &termios_attr );
+ if (status != 0) {
+ printk("Error getting mouse attributes\n");
+ return RTEMS_IO_ERROR;
+ }
+ termios_attr.c_lflag &= ~(ICANON|ECHO|ECHONL|ECHOK|ECHOE|ECHOPRT|ECHOCTL);
+ termios_attr.c_iflag &= ~(IXON|IXANY|IXOFF);
+ /*
+ termios_attr.c_cc[VMIN] = itask_VMIN;
+ termios_attr.c_cc[VTIME] = itask_VTIME;
+ */
+ termios_attr.c_cflag |= B1200;
+ termios_attr.c_cflag |= CS8;
+ status = tcsetattr( serial_mouse_fd, TCSANOW, &termios_attr );
+ if (status != 0) {
+ printk("Error setting mouse attributes\n");
+ return RTEMS_IO_ERROR;
+ }
+
+ status = ioctl(serial_mouse_fd, TIOCSETD, &disc);
+ if (status != 0) {
+ printk("Error setting mouse attributes\n");
+ return RTEMS_IO_ERROR;
+ }
+
+ sleep(5);
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_device_driver serial_mouse_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ close( serial_mouse_fd );
+
+ return RTEMS_SUCCESSFUL;
+}
+
+rtems_device_driver serial_mouse_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+
+rtems_device_driver serial_mouse_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ return RTEMS_SUCCESSFUL;
+}
+
+
+rtems_device_driver serial_mouse_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+)
+{
+ rtems_libio_ioctl_args_t *args = (rtems_libio_ioctl_args_t *)arg;
+
+ switch( args->command ) {
+
+ case MW_UID_REGISTER_DEVICE:
+ printk( "SerialMouse: reg=%s\n", args->buffer );
+ mouse_parser_initialize( serial_mouse_type );
+ break;
+
+ case MW_UID_UNREGISTER_DEVICE:
+ break;
+
+ default:
+ args->ioctl_return = ioctl(serial_mouse_fd, args->command, args->buffer );
+ if ( !args->ioctl_return )
+ return RTEMS_SUCCESSFUL;
+ return RTEMS_IO_ERROR;
+ }
+ args->ioctl_return = 0;
+ return RTEMS_SUCCESSFUL;
+}
diff --git a/cpukit/libmisc/mouse/serial_mouse.h b/cpukit/libmisc/mouse/serial_mouse.h
new file mode 100644
index 0000000000..65e98089cb
--- /dev/null
+++ b/cpukit/libmisc/mouse/serial_mouse.h
@@ -0,0 +1,156 @@
+/**
+ * @file rtems/serial_mouse.h
+ *
+ * This file describes the Serial Mouse Driver for all boards.
+ * This driver assumes that the BSP or application will provide
+ * an implementation of the method bsp_get_serial_mouse_device()
+ * which tells the driver what serial port device to open() and
+ * what type of mouse is connected.
+ *
+ * This driver relies on the Mouse Parser Engine.
+ */
+
+/*
+ * COPYRIGHT (c) 1989-2011.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ *
+ * $Id$
+ */
+
+#ifndef __SERIAL_MOUSE_h__
+#define __SERIAL_MOUSE_h__
+
+/* functions */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * This macro defines the serial mouse device driver entry points.
+ */
+#define SERIAL_MOUSE_DRIVER_TABLE_ENTRY \
+ { serial_mouse_initialize, serial_mouse_open, serial_mouse_close, \
+ serial_mouse_read, serial_mouse_write, serial_mouse_control }
+
+/**
+ * @brief Serial Mouse Driver Initialization
+ *
+ * This method initializes the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_initialize(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver Open
+ *
+ * This method implements the Open device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_open(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver Close
+ *
+ * This method implements the Close device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_close(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver Read
+ *
+ * This method implements the Read device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_read(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver Write
+ *
+ * This method implements the Write device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_write(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Serial Mouse Driver IO Control
+ *
+ * This method implements the IO Control device driver entry
+ * point for the serial mouse driver.
+ *
+ * @param[in] major is the mouse device major number
+ * @param[in] minor is the mouse device minor number
+ * @param[in] arguments points to device driver arguments
+ */
+rtems_device_driver serial_mouse_control(
+ rtems_device_major_number major,
+ rtems_device_minor_number minor,
+ void *arg
+);
+
+/**
+ * @brief Obtain Serial Mouse Configuration Information
+ *
+ * This method is implemented by the BSP or application and
+ * tells the driver what device to open() and what type of
+ * mouse is connected.
+ *
+ * @param[in] name will point to a string with the device name
+ * of the serial port with the mouse connected.
+ * @param[in] type will point to a string with the type of mouse connected.
+ *
+ * @return This method returns true on success and false on error.
+ */
+bool bsp_get_serial_mouse_device(
+ const char **name,
+ const char **type
+);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __tty_drv__ */