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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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