2 /////////////////////////////////////////////////////////////////////////////
3 // $Header: /usr/cvs/microwin/src/drivers/input_rtems.c,v 1.1.1.1 2001/06/21 06:32:41 greg Exp $
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:
16 // $Log: input_rtems.c,v $
17 // Revision 1.1.1.1 2001/06/21 06:32:41 greg
18 // Microwindows pre8 with patches
20 // Revision 1.1.1.1 2001/06/05 03:44:01 root
21 // First import of 5/5/2001 Microwindows to CVS
24 /////////////////////////////////////////////////////////////////////////////
29 #include <sys/ioctl.h>
32 #include <rtems/mw_uid.h>
34 #include "windef.h" /* UCHAR */
37 extern int close( int fd ); /* RTEMS does not include close() in stdio.h */
39 #define SCALE 3 /* default scaling factor for acceleration */
40 #define THRESH 5 /* default threshhold for acceleration */
42 /* prototypes of the mouse driver */
43 static int MWMou_Open(MOUSEDEVICE *pmd);
44 static void MWMou_Close(void);
45 static int MWMou_GetButtonInfo(void);
46 static void MWMou_GetDefaultAccel(int *pscale,int *pthresh);
47 static int MWMou_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp);
49 /* prototypes of the Kbd driver */
50 static int MWKbd_Open(KBDDEVICE *pkd);
51 static void MWKbd_Close(void);
52 static void MWKbd_GetModifierInfo(int *modifiers);
53 static int MWKbd_Read(MWUCHAR *buf, int *modifiers);
56 MOUSEDEVICE mousedev =
61 MWMou_GetDefaultAccel,
70 MWKbd_GetModifierInfo,
75 struct MW_UID_MESSAGE m_kbd = { 0 };
76 struct MW_UID_MESSAGE m_mou = { 0 };
79 static int mou_fd = -1;
80 static int kbd_fd = -1;
82 static const char *Q_NAME = "MWQ";
83 #define Q_MAX_MSGS 128
84 #define MOUSE_DEVICE "/dev/mouse"
87 /* Open and register driver */
88 static int open_queue_and_register_driver( int fd )
91 rc = uid_open_queue( Q_NAME, O_CREAT | O_RDWR, Q_MAX_MSGS );
96 return uid_register_device( fd, Q_NAME );
99 /* close and unregister device */
100 static int close_queue_and_unregister_device( int fd )
102 uid_unregister_device( fd );
103 return uid_close_queue();
108 * Open up the mouse device.
111 MWMou_Open(MOUSEDEVICE *pmd)
115 m_mou.type = MV_UID_INVALID;
116 mou_fd = open( MOUSE_DEVICE, O_NONBLOCK );
117 /* Open your mouse device here */
118 rc = open_queue_and_register_driver( mou_fd );
125 * Close the mouse device.
130 close_queue_and_unregister_device( mou_fd );
135 * Get mouse buttons supported
138 MWMou_GetButtonInfo(void)
144 * Get default mouse acceleration settings
147 MWMou_GetDefaultAccel(int *pscale,int *pthresh)
154 * Attempt to read bytes from the mouse and interpret them.
155 * Returns -1 on error, 0 if either no bytes were read or not enough
156 * was read for a complete state, or 1 if the new state was read.
157 * When a new state is read, the current buttons and x and y deltas
158 * are returned. This routine does not block.
161 MWMou_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp)
163 /* check if a new mouse event has been posted */
164 if( m_mou.type != MV_UID_INVALID )
166 /* check which return to send up ... */
167 int rc = ( m_mou.type == MV_UID_REL_POS ) ? 1 : 2;
169 *bp = m_mou.m.pos.btns;
174 m_mou.type = MV_UID_INVALID;
186 MWKbd_Open(KBDDEVICE *pkd)
190 m_kbd.type = MV_UID_INVALID;
191 /* kbd it is already opened */
192 kbd_fd = fileno( stdin );
193 /* register kbd driver */
194 rc = open_queue_and_register_driver( kbd_fd );
201 * Close the keyboard.
209 * Return the possible modifiers for the keyboard.
212 MWKbd_GetModifierInfo(int *modifiers)
214 *modifiers = 0; /* no modifiers available */
218 * This reads one keystroke from the keyboard, and the current state of
219 * the mode keys (ALT, SHIFT, CTRL). Returns -1 on error, 0 if no data
220 * is ready, and 1 if data was read. This is a non-blocking call.
223 MWKbd_Read(MWUCHAR *buf, int *modifiers)
225 /* check if new KBD event has been posted */
226 if( m_kbd.type != MV_UID_INVALID )
228 *buf = (UCHAR)m_kbd.m.kbd.code;
229 /* *modifiers = m_kbd.m.kbd.modifiers; */
233 m_kbd.type = MV_UID_INVALID;