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