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

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [drivers/] [mou_ps5.c] - Diff between revs 674 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 674 Rev 1765
/*
/*
 * Microwindows touch screen driver for Psion 5
 * Microwindows touch screen driver for Psion 5
 */
 */
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
#include <math.h>
#include <math.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#define _LINUX_TYPES_H
#define _LINUX_TYPES_H
#include <linux/fb.h>
#include <linux/fb.h>
#include </linux/include/asm-arm/arch/touch_psion.h>
#include </linux/include/asm-arm/arch/touch_psion.h>
 
 
#include "device.h"
#include "device.h"
 
 
/* file descriptor for touch panel */
/* file descriptor for touch panel */
static int pd_fd;
static int pd_fd;
 
 
/* Hack extern to used when hiding the mouse cursor
/* Hack extern to used when hiding the mouse cursor
 * There needs to be a better way to do this
 * There needs to be a better way to do this
*/
*/
extern SCREENDEVICE scrdev;
extern SCREENDEVICE scrdev;
 
 
static int PD_Open(MOUSEDEVICE *pmd)
static int PD_Open(MOUSEDEVICE *pmd)
{
{
        /*
        /*
         * open up the touch-panel device.
         * open up the touch-panel device.
         * Return the fd if successful, or negative if unsuccessful.
         * Return the fd if successful, or negative if unsuccessful.
         */
         */
 
 
        pd_fd = open("/dev/touch_psion", O_NONBLOCK);
        pd_fd = open("/dev/touch_psion", O_NONBLOCK);
        if (pd_fd < 0) {
        if (pd_fd < 0) {
                fprintf(stderr, "Error %d opening touch panel\n", errno);
                fprintf(stderr, "Error %d opening touch panel\n", errno);
                return -1;
                return -1;
        }
        }
 
 
        GdHideCursor(&scrdev);
        GdHideCursor(&scrdev);
        return pd_fd;
        return pd_fd;
}
}
 
 
static void PD_Close(void)
static void PD_Close(void)
{
{
        /* Close the touch panel device. */
        /* Close the touch panel device. */
        fprintf(stderr,"PD_Close called\n");
        fprintf(stderr,"PD_Close called\n");
        if (pd_fd > 0)
        if (pd_fd > 0)
                close(pd_fd);
                close(pd_fd);
        pd_fd = 0;
        pd_fd = 0;
}
}
 
 
static int PD_GetButtonInfo(void)
static int PD_GetButtonInfo(void)
{
{
        /* get "mouse" buttons supported */
        /* get "mouse" buttons supported */
        return MWBUTTON_L;
        return MWBUTTON_L;
}
}
 
 
static void PD_GetDefaultAccel(int *pscale,int *pthresh)
static void PD_GetDefaultAccel(int *pscale,int *pthresh)
{
{
        /*
        /*
         * Get default mouse acceleration settings
         * Get default mouse acceleration settings
         * This doesn't make sense for a touch panel.
         * This doesn't make sense for a touch panel.
         * Just return something inconspicuous for now.
         * Just return something inconspicuous for now.
         */
         */
        *pscale = 3;
        *pscale = 3;
        *pthresh = 5;
        *pthresh = 5;
}
}
 
 
static int PD_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb)
static int PD_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb)
{
{
        /* read a data point */
        /* read a data point */
        struct touch_psion_event data;
        struct touch_psion_event data;
        int bytes_read;
        int bytes_read;
 
 
        bytes_read = read(pd_fd, &data, sizeof(data));
        bytes_read = read(pd_fd, &data, sizeof(data));
 
 
        if (bytes_read != sizeof(data)) {
        if (bytes_read != sizeof(data)) {
                if (errno == EINTR || errno == EAGAIN)
                if (errno == EINTR || errno == EAGAIN)
                        return 0;
                        return 0;
                return -1;
                return -1;
        }
        }
 
 
        *px = (MWCOORD)data.x_c;
        *px = (MWCOORD)data.x_c;
        *py = (MWCOORD)data.y_c;
        *py = (MWCOORD)data.y_c;
 
 
        *pb = (data.down>0?MWBUTTON_L:0);
        *pb = (data.down>0?MWBUTTON_L:0);
        *pz = 0;
        *pz = 0;
 
 
        if((*px == -1 || *py == -1) && *pb >= 0)
        if((*px == -1 || *py == -1) && *pb >= 0)
                return 3;                       /* only have button data */
                return 3;                       /* only have button data */
        if((*px == -1 || *py == -1) && *pb < 0)
        if((*px == -1 || *py == -1) && *pb < 0)
                return 0;                        /* don't have any data   */
                return 0;                        /* don't have any data   */
        return 2;                               /* have full set of data */
        return 2;                               /* have full set of data */
}
}
 
 
MOUSEDEVICE mousedev = {
MOUSEDEVICE mousedev = {
        PD_Open,
        PD_Open,
        PD_Close,
        PD_Close,
        PD_GetButtonInfo,
        PD_GetButtonInfo,
        PD_GetDefaultAccel,
        PD_GetDefaultAccel,
        PD_Read,
        PD_Read,
        NULL
        NULL
};
};
 
 
#ifdef TEST
#ifdef TEST
int main(int argc, char ** v)
int main(int argc, char ** v)
{
{
        MWCOORD         x, y, z;
        MWCOORD         x, y, z;
        MWBUTTON        b;
        MWBUTTON        b;
        int result;
        int result;
        int mouse = -1;
        int mouse = -1;
        printf("Opening touch panel...\n");
        printf("Opening touch panel...\n");
 
 
        if((result=PD_Open(0)) < 0)
        if((result=PD_Open(0)) < 0)
                printf("Error %d, result %d opening touch-panel\n", errno, result);
                printf("Error %d, result %d opening touch-panel\n", errno, result);
 
 
        /* This stuff below can be used to set some of the parameters of the
        /* This stuff below can be used to set some of the parameters of the
         * driver from the command line before going in to the test loop.
         * driver from the command line before going in to the test loop.
         * Could this have been done better? Yup.
         * Could this have been done better? Yup.
         */
         */
 
 
        if(argc > 1) {
        if(argc > 1) {
                ioctl(result,1,atoi(v[1]));
                ioctl(result,1,atoi(v[1]));
                fprintf(stderr,"Setting pressure to %d\n",atoi(v[1]));
                fprintf(stderr,"Setting pressure to %d\n",atoi(v[1]));
        }
        }
        if(argc > 2) {
        if(argc > 2) {
                ioctl(result,2,atoi(v[2]));
                ioctl(result,2,atoi(v[2]));
                fprintf(stderr,"Setting updelay to %d\n",atoi(v[2]));
                fprintf(stderr,"Setting updelay to %d\n",atoi(v[2]));
        }
        }
        if(argc > 3) {
        if(argc > 3) {
                ioctl(result,3,atoi(v[3]));
                ioctl(result,3,atoi(v[3]));
                fprintf(stderr,"Setting raw x to %d\n",atoi(v[3]));
                fprintf(stderr,"Setting raw x to %d\n",atoi(v[3]));
        }
        }
        if(argc > 4) {
        if(argc > 4) {
                ioctl(result,4,atoi(v[4]));
                ioctl(result,4,atoi(v[4]));
                fprintf(stderr,"Setting raw y to %d\n",atoi(v[4]));
                fprintf(stderr,"Setting raw y to %d\n",atoi(v[4]));
        }
        }
        if(argc > 5) {
        if(argc > 5) {
                ioctl(result,5,atoi(v[5]));
                ioctl(result,5,atoi(v[5]));
                fprintf(stderr,"Setting res x to %d\n",atoi(v[5]));
                fprintf(stderr,"Setting res x to %d\n",atoi(v[5]));
        }
        }
        if(argc > 6) {
        if(argc > 6) {
                ioctl(result,6,atoi(v[6]));
                ioctl(result,6,atoi(v[6]));
                fprintf(stderr,"Setting res y to %d\n",atoi(v[6]));
                fprintf(stderr,"Setting res y to %d\n",atoi(v[6]));
        }
        }
        if(argc > 7) {
        if(argc > 7) {
                ioctl(result,7,atoi(v[7]));
                ioctl(result,7,atoi(v[7]));
                fprintf(stderr,"Setting fudge x to %d\n",atoi(v[7]));
                fprintf(stderr,"Setting fudge x to %d\n",atoi(v[7]));
        }
        }
        if(argc > 8) {
        if(argc > 8) {
                ioctl(result,8,atoi(v[8]));
                ioctl(result,8,atoi(v[8]));
                fprintf(stderr,"Setting fudge y to %d\n",atoi(v[8]));
                fprintf(stderr,"Setting fudge y to %d\n",atoi(v[8]));
        }
        }
        if(argc > 9) {
        if(argc > 9) {
                ioctl(result,9,atoi(v[9]));
                ioctl(result,9,atoi(v[9]));
                fprintf(stderr,"Setting average sample to %d\n",atoi(v[9]));
                fprintf(stderr,"Setting average sample to %d\n",atoi(v[9]));
        }
        }
        if(argc > 10) {
        if(argc > 10) {
                ioctl(result,10,atoi(v[10]));
                ioctl(result,10,atoi(v[10]));
                fprintf(stderr,"Setting raw min x to %d\n",atoi(v[10]));
                fprintf(stderr,"Setting raw min x to %d\n",atoi(v[10]));
        }
        }
        if(argc > 11) {
        if(argc > 11) {
                ioctl(result,11,atoi(v[11]));
                ioctl(result,11,atoi(v[11]));
                fprintf(stderr,"Setting raw min y to %d\n",atoi(v[11]));
                fprintf(stderr,"Setting raw min y to %d\n",atoi(v[11]));
        }
        }
 
 
        printf("Reading touch panel...\n");
        printf("Reading touch panel...\n");
 
 
        while(1) {
        while(1) {
                result = PD_Read(&x, &y, &z, &b);
                result = PD_Read(&x, &y, &z, &b);
                if( result > 0) {
                if( result > 0) {
                        if(mouse != b) {
                        if(mouse != b) {
                                mouse = b;
                                mouse = b;
                                if(mouse)
                                if(mouse)
                                        printf("Pen Down\n");
                                        printf("Pen Down\n");
                                else
                                else
                                        printf("Pen Up\n");
                                        printf("Pen Up\n");
                        }
                        }
 
 
                        printf("%d,%d,%d,%d,%d\n", result, x, y, z, b);
                        printf("%d,%d,%d,%d,%d\n", result, x, y, z, b);
 
 
                }
                }
        }
        }
}
}
#endif
#endif
 
 

powered by: WebSVN 2.1.0

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