OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [drivers/] [mou_ipaq.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Microwindows touch screen driver for UCB1200 & UCB1300's
3
 * used with ARM boards, including Compaq iPAQ and Intel Assabet.
4
 *
5
 * Copyright (c) 2000 Century Software Embedded Technologies
6
 *
7
 * iPAQ/Assabet: Requires /dev/h3600_ts kernel driver (char 11,0).
8
 * L7200: Requires /dev/touchscreen/ucb1x00-ts
9
 */
10
#include <stdio.h>
11
#include <stdlib.h>
12
#include <unistd.h>
13
#include <errno.h>
14
#include <fcntl.h>
15
#include <math.h>
16
#include <sys/ioctl.h>
17
#include "device.h"
18
 
19
#ifdef __ECOS
20
#define TOUCHDEVICE     "/dev/ts"                       /* iPAQ*/
21
#else
22
#define TOUCHDEVICE     "/dev/h3600_ts"                 /* iPAQ*/
23
#endif
24
/*define TOUCHDEVICE    "/dev/touchscreen/ucb1x00" */   /* L7200*/
25
 
26
/* file descriptor for touch panel */
27
static int pd_fd = -1;
28
 
29
/* Hack extern to used when hiding the mouse cursor
30
 * There needs to be a better way to do this
31
*/
32
extern SCREENDEVICE scrdev;
33
 
34
static int PD_Open(MOUSEDEVICE *pmd)
35
{
36
        /*
37
         * open up the touch-panel device.
38
         * Return the fd if successful, or negative if unsuccessful.
39
         */
40
 
41
        pd_fd = open(TOUCHDEVICE, O_RDONLY | O_NONBLOCK);
42
        if (pd_fd < 0) {
43
                EPRINTF("Error %d opening touch panel\n", errno);
44
                return -1;
45
        }
46
        GdHideCursor(&scrdev);
47
        return pd_fd;
48
}
49
 
50
static void PD_Close(void)
51
{
52
        /* Close the touch panel device. */
53
        if (pd_fd >= 0)
54
                close(pd_fd);
55
        pd_fd = -1;
56
}
57
 
58
static int PD_GetButtonInfo(void)
59
{
60
        /* get "mouse" buttons supported */
61
        return MWBUTTON_L;
62
}
63
 
64
static void PD_GetDefaultAccel(int *pscale,int *pthresh)
65
{
66
        /*
67
         * Get default mouse acceleration settings
68
         * This doesn't make sense for a touch panel.
69
         * Just return something inconspicuous for now.
70
         */
71
        *pscale = 3;
72
        *pthresh = 5;
73
}
74
 
75
static int PD_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb)
76
{
77
        /* read a data point */
78
        short data[4];
79
        int bytes_read;
80
 
81
        bytes_read = read(pd_fd, data, sizeof(data));
82
 
83
        if (bytes_read != sizeof(data)) {
84
                if (errno == EINTR || errno == EAGAIN)
85
                        return 0;
86
                /*
87
                 * kernel driver bug: select returns read available,
88
                 * but read returns -1
89
                 * we return 0 here to avoid GsError above
90
                 */
91
                /*return -1;*/
92
                return 0;
93
        }
94
 
95
        *px = (MWCOORD)data[1];
96
        *py = (MWCOORD)data[2];
97
 
98
        *pb = (data[0] ? MWBUTTON_L : 0);
99
 
100
        *pz = 0;
101
 
102
        if(! *pb )
103
          return 3;                     /* only have button data */
104
        else
105
          return 2;                     /* have full set of data */
106
}
107
 
108
MOUSEDEVICE mousedev = {
109
        PD_Open,
110
        PD_Close,
111
        PD_GetButtonInfo,
112
        PD_GetDefaultAccel,
113
        PD_Read,
114
        NULL
115
};
116
 
117
#ifdef TEST
118
int main(int argc, char ** v)
119
{
120
        MWCOORD x, y, z;
121
        int     b;
122
        int result;
123
        int mouse = -1;
124
        DPRINTF("Opening touch panel...\n");
125
 
126
        if((result=PD_Open(0)) < 0)
127
                DPRINTF("Error %d, result %d opening touch-panel\n", errno, result);
128
 
129
        /* This stuff below can be used to set some of the parameters of the
130
         * driver from the command line before going in to the test loop.
131
         * Could this have been done better? Yup.
132
         */
133
 
134
        if(argc > 1) {
135
                ioctl(result,1,atoi(v[1]));
136
                DPRINTF("Setting pressure to %d\n",atoi(v[1]));
137
        }
138
        if(argc > 2) {
139
                ioctl(result,2,atoi(v[2]));
140
                DPRINTF("Setting updelay to %d\n",atoi(v[2]));
141
        }
142
        if(argc > 3) {
143
                ioctl(result,3,atoi(v[3]));
144
                DPRINTF("Setting raw x to %d\n",atoi(v[3]));
145
        }
146
        if(argc > 4) {
147
                ioctl(result,4,atoi(v[4]));
148
                DPRINTF("Setting raw y to %d\n",atoi(v[4]));
149
        }
150
        if(argc > 5) {
151
                ioctl(result,5,atoi(v[5]));
152
                DPRINTF("Setting res x to %d\n",atoi(v[5]));
153
        }
154
        if(argc > 6) {
155
                ioctl(result,6,atoi(v[6]));
156
                DPRINTF("Setting res y to %d\n",atoi(v[6]));
157
        }
158
        if(argc > 7) {
159
                ioctl(result,7,atoi(v[7]));
160
                DPRINTF("Setting fudge x to %d\n",atoi(v[7]));
161
        }
162
        if(argc > 8) {
163
                ioctl(result,8,atoi(v[8]));
164
                DPRINTF("Setting fudge y to %d\n",atoi(v[8]));
165
        }
166
        if(argc > 9) {
167
                ioctl(result,9,atoi(v[9]));
168
                DPRINTF("Setting average sample to %d\n",atoi(v[9]));
169
        }
170
        if(argc > 10) {
171
                ioctl(result,10,atoi(v[10]));
172
                DPRINTF("Setting raw min x to %d\n",atoi(v[10]));
173
        }
174
        if(argc > 11) {
175
                ioctl(result,11,atoi(v[11]));
176
                DPRINTF("Setting raw min y to %d\n",atoi(v[11]));
177
        }
178
 
179
        DPRINTF("Reading touch panel...\n");
180
 
181
        while(1) {
182
                result = PD_Read(&x, &y, &z, &b);
183
                if( result > 0) {
184
                        if(mouse != b) {
185
                                mouse = b;
186
                                if(mouse)
187
                                        DPRINTF("Pen Down\n");
188
                                else
189
                                        DPRINTF("Pen Up\n");
190
                        }
191
 
192
                        DPRINTF("%d,%d,%d,%d,%d\n", result, x, y, z, b);
193
 
194
                }
195
        }
196
}
197
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.