2 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2000 - Rosimildo da Silva
8 // This module implements the Microwindows Drivers for systems that implements
9 // the Micro Input Device interface. This driver is not specific in any way
10 // to RTEMS. It could be used with any sustem that implements such interface.
12 // The skeleton of the drivers were based on standard Microwindows drivers.
14 // MODIFICATION/HISTORY:
17 // Revision 1.1.9.1 2009-06-15 14:11:00 lothar
18 // unified MX27, MX25, MX37 trees
20 // Revision 1.1.1.1 2001/06/21 06:32:41 greg
21 // Microwindows pre8 with patches
23 // Revision 1.1.1.1 2001/06/05 03:44:01 root
24 // First import of 5/5/2001 Microwindows to CVS
27 /////////////////////////////////////////////////////////////////////////////
32 #include <sys/ioctl.h>
35 #include <rtems/mw_uid.h>
37 #include "windef.h" /* UCHAR */
40 extern int close( int fd ); /* RTEMS does not include close() in stdio.h */
42 #define SCALE 3 /* default scaling factor for acceleration */
43 #define THRESH 5 /* default threshhold for acceleration */
45 /* prototypes of the mouse driver */
46 static int MWMou_Open(MOUSEDEVICE *pmd);
47 static void MWMou_Close(void);
48 static int MWMou_GetButtonInfo(void);
49 static void MWMou_GetDefaultAccel(int *pscale,int *pthresh);
50 static int MWMou_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp);
52 /* prototypes of the Kbd driver */
53 static int MWKbd_Open(KBDDEVICE *pkd);
54 static void MWKbd_Close(void);
55 static void MWKbd_GetModifierInfo(int *modifiers);
56 static int MWKbd_Read(MWUCHAR *buf, int *modifiers);
59 MOUSEDEVICE mousedev =
64 MWMou_GetDefaultAccel,
73 MWKbd_GetModifierInfo,
78 struct MW_UID_MESSAGE m_kbd = { 0 };
79 struct MW_UID_MESSAGE m_mou = { 0 };
82 static int mou_fd = -1;
83 static int kbd_fd = -1;
85 static const char *Q_NAME = "MWQ";
86 #define Q_MAX_MSGS 128
87 #define MOUSE_DEVICE "/dev/mouse"
90 /* Open and register driver */
91 static int open_queue_and_register_driver( int fd )
94 rc = uid_open_queue( Q_NAME, O_CREAT | O_RDWR, Q_MAX_MSGS );
99 return uid_register_device( fd, Q_NAME );
102 /* close and unregister device */
103 static int close_queue_and_unregister_device( int fd )
105 uid_unregister_device( fd );
106 return uid_close_queue();
111 * Open up the mouse device.
114 MWMou_Open(MOUSEDEVICE *pmd)
118 m_mou.type = MV_UID_INVALID;
119 mou_fd = open( MOUSE_DEVICE, O_NONBLOCK );
120 /* Open your mouse device here */
121 rc = open_queue_and_register_driver( mou_fd );
128 * Close the mouse device.
133 close_queue_and_unregister_device( mou_fd );
138 * Get mouse buttons supported
141 MWMou_GetButtonInfo(void)
147 * Get default mouse acceleration settings
150 MWMou_GetDefaultAccel(int *pscale,int *pthresh)
157 * Attempt to read bytes from the mouse and interpret them.
158 * Returns -1 on error, 0 if either no bytes were read or not enough
159 * was read for a complete state, or 1 if the new state was read.
160 * When a new state is read, the current buttons and x and y deltas
161 * are returned. This routine does not block.
164 MWMou_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp)
166 /* check if a new mouse event has been posted */
167 if( m_mou.type != MV_UID_INVALID )
169 /* check which return to send up ... */
170 int rc = ( m_mou.type == MV_UID_REL_POS ) ? 1 : 2;
172 *bp = m_mou.m.pos.btns;
177 m_mou.type = MV_UID_INVALID;
189 MWKbd_Open(KBDDEVICE *pkd)
193 m_kbd.type = MV_UID_INVALID;
194 /* kbd it is already opened */
195 kbd_fd = fileno( stdin );
196 /* register kbd driver */
197 rc = open_queue_and_register_driver( kbd_fd );
204 * Close the keyboard.
212 * Return the possible modifiers for the keyboard.
215 MWKbd_GetModifierInfo(int *modifiers)
217 *modifiers = 0; /* no modifiers available */
221 * This reads one keystroke from the keyboard, and the current state of
222 * the mode keys (ALT, SHIFT, CTRL). Returns -1 on error, 0 if no data
223 * is ready, and 1 if data was read. This is a non-blocking call.
226 MWKbd_Read(MWUCHAR *buf, int *modifiers)
228 /* check if new KBD event has been posted */
229 if( m_kbd.type != MV_UID_INVALID )
231 *buf = (UCHAR)m_kbd.m.kbd.code;
232 /* *modifiers = m_kbd.m.kbd.modifiers; */
236 m_kbd.type = MV_UID_INVALID;