]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/input_rtems.c
Cleanup CVS ipmorted branch
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / input_rtems.c
1 /*
2 /////////////////////////////////////////////////////////////////////////////
3 // $Header: /usr/cvs/microwin/src/drivers/input_rtems.c,v 1.1.1.1 2001/06/21 06:32:41 greg Exp $
4 //
5 // Copyright (c) 2000 - Rosimildo da Silva
6 //  
7 // MODULE DESCRIPTION: 
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.
11 //
12 // The skeleton of the drivers were based on standard Microwindows drivers.
13 //
14 // MODIFICATION/HISTORY:
15 //
16 // $Log: input_rtems.c,v $
17 // Revision 1.1.1.1  2001/06/21 06:32:41  greg
18 // Microwindows pre8 with patches
19 //
20 // Revision 1.1.1.1  2001/06/05 03:44:01  root
21 // First import of 5/5/2001 Microwindows to CVS
22 //
23 //
24 /////////////////////////////////////////////////////////////////////////////
25 */
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <fcntl.h>
29 #include <sys/ioctl.h>
30 #include <errno.h>
31
32 #include <rtems/mw_uid.h>
33 #include "device.h"
34 #include "windef.h"   /* UCHAR */
35
36
37 extern int close( int fd ); /* RTEMS does not include close() in stdio.h */
38
39 #define    SCALE        3    /* default scaling factor for acceleration */
40 #define    THRESH       5    /* default threshhold for acceleration */
41
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);
48
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);
54
55
56 MOUSEDEVICE mousedev = 
57 {
58     MWMou_Open,
59     MWMou_Close,
60     MWMou_GetButtonInfo,
61     MWMou_GetDefaultAccel,
62     MWMou_Read,
63     NULL
64 };
65
66
67 KBDDEVICE kbddev = {
68     MWKbd_Open,
69     MWKbd_Close,
70     MWKbd_GetModifierInfo,
71     MWKbd_Read,
72     NULL
73 };
74
75 struct MW_UID_MESSAGE m_kbd = { 0 };
76 struct MW_UID_MESSAGE m_mou = { 0 };
77
78
79 static int mou_fd = -1;
80 static int kbd_fd   = -1;
81
82 static const char *Q_NAME        = "MWQ";
83 #define            Q_MAX_MSGS      128
84 #define            MOUSE_DEVICE    "/dev/mouse"
85
86
87 /* Open and register driver */
88 static int open_queue_and_register_driver( int fd )
89 {
90    int rc;
91    rc = uid_open_queue( Q_NAME, O_CREAT | O_RDWR, Q_MAX_MSGS );
92    if( rc ) 
93    {
94       return rc;
95    }
96    return uid_register_device( fd, Q_NAME );
97 }
98
99 /* close and unregister device */
100 static int close_queue_and_unregister_device( int fd )
101 {
102     uid_unregister_device( fd );
103     return uid_close_queue();
104 }  
105
106
107 /*
108  * Open up the mouse device.
109  */
110 static int
111 MWMou_Open(MOUSEDEVICE *pmd)
112 {
113    int rc;
114    /* no valid event */
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 );
119    if( rc )
120       return -1;
121    return 2;
122 }
123
124 /*
125  * Close the mouse device.
126  */
127 static void
128 MWMou_Close(void)
129 {
130    close_queue_and_unregister_device( mou_fd );
131    close( mou_fd );
132 }
133
134 /*
135  * Get mouse buttons supported
136  */
137 static int
138 MWMou_GetButtonInfo(void)
139 {
140    return 0;
141 }
142
143 /*
144  * Get default mouse acceleration settings
145  */
146 static void
147 MWMou_GetDefaultAccel(int *pscale,int *pthresh)
148 {
149     *pscale = SCALE;
150     *pthresh = THRESH;
151 }
152
153 /*
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.
159  */
160 static int
161 MWMou_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp)
162 {
163    /* check if a new mouse event has been posted */
164    if( m_mou.type != MV_UID_INVALID )
165    {
166       /* check which return to send up ... */
167       int rc = ( m_mou.type == MV_UID_REL_POS ) ? 1 : 2;
168
169       *bp = m_mou.m.pos.btns;
170       *dx = m_mou.m.pos.x;
171       *dy = m_mou.m.pos.y;
172       *dz = m_mou.m.pos.z;
173       /* consume event */
174       m_mou.type = MV_UID_INVALID;
175       return rc;
176    }
177    return 0;
178 }
179
180
181
182 /*
183  * Open the keyboard.
184  */
185 static int
186 MWKbd_Open(KBDDEVICE *pkd)
187 {
188    int rc;
189    /* no valid event */
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 );
195    if( rc )
196       return -1;
197    return 1;
198 }
199
200 /*
201  * Close the keyboard.
202  */
203 static void
204 MWKbd_Close(void)
205 {
206 }
207
208 /*
209  * Return the possible modifiers for the keyboard.
210  */
211 static  void
212 MWKbd_GetModifierInfo(int *modifiers)
213 {
214     *modifiers = 0;      /* no modifiers available */
215 }
216
217 /*
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.
221  */
222 static int
223 MWKbd_Read(MWUCHAR *buf, int *modifiers)
224 {
225    /* check if new KBD event has been posted */
226    if( m_kbd.type != MV_UID_INVALID )
227    {
228       *buf = (UCHAR)m_kbd.m.kbd.code;
229 /*    *modifiers = m_kbd.m.kbd.modifiers;  */
230       *modifiers = 0;
231
232       /* consume event */
233       m_kbd.type = MV_UID_INVALID;
234       return 1;
235    }
236     return 0;
237 }