|
发表于 2005-3-20 11:52:00
|
显示全部楼层
取自uClinux-dist/linux-2.4.x/drivers/char/mc68328digi.h
SkyEye测试包中的LCD和触摸屏的demo程序就是这个小程序修改而来,
自己照着触摸屏驱动改改,再打开framebuffer,就可以在SkyEye用了
/*------------------------------------------------------------------------------
** The following sample code illustrates the usage of the ts driver:
**
** #include <string.h>
** #include <errno.h>
** #include <fcntl.h>
** #include <stdio.h>
** #include <linux/mc68328digi.h>
**
**
**
**
** const char *ts_device_name = "/dev/ts";
**
**
**
**
**
**
** void tsdrv_params_fprint(FILE *f, struct ts_drv_params *p)
** {
** fprintf(f, "version : %d\n", p->version);
** fprintf(f, "version_req : %d\n", p->version_req);
** fprintf(f, "x ratio : %d/%d\n", p->x_ratio_num, p->x_ratio_den);
** fprintf(f, "y ratio : %d/%d\n", p->y_ratio_num, p->y_ratio_den);
** fprintf(f, "x limits : %d/%d\n", p->x_min, p->x_max);
** fprintf(f, "y limits : %d/%d\n", p->y_min, p->y_max);
** fprintf(f, "x offset : %d\n", p->x_offset);
** fprintf(f, "y offset : %d\n", p->y_offset);
** fprintf(f, "invert xy : %d\n", p->xy_swap);
** fprintf(f, "mv thrs : %d\n", p->mv_thrs);
** fprintf(f, "follow thrs : %d\n", p->follow_thrs);
** fprintf(f, "sample ms : %d\n", p->sample_ms);
** fprintf(f, "dglitch on : %d\n", p->deglitch_on);
** fprintf(f, "evt Q on : %d\n", p->event_queue_on);
** }
**
**
** int tsdrv_init(int argc, char *argv[])
** {
** int ts_fd;
** int err;
** struct ts_drv_params drv_params;
** int mx1, mx2, my1, my2;
** int ux1, ux2, uy1, uy2;
**
** ts_fd = open(ts_device_name, O_RDWR);
** if(ts_fd==0) {
** fprintf(stderr, "%s: error: could not open device %s\n",
** argv[0], ts_device_name);
** return 0;
** }
**
** err = ioctl(ts_fd, TS_PARAMS_GET, &drv_params);
** if(err) {
** fprintf(stderr, "%s: ioctl TS_PARAMS_GET error: %s\n",
** argv[0], strerror(errno));
** close(ts_fd);
** return 0;
** }
**
** printf("\nDefault driver settings:\n");
** tsdrv_params_fprint(stdout, &drv_params);
**
**
** drv_params.version_req = MC68328DIGI_VERSION;
** drv_params.event_queue_on = 1;
** drv_params.deglitch_on = 0;
** drv_params.sample_ms = 10;
** drv_params.follow_thrs = 0;
** drv_params.mv_thrs = 2;
** drv_params.y_max = 159 + 66;
** drv_params.y_min = 0;
** drv_params.x_max = 159;
** drv_params.x_min = 0;
** drv_params.xy_swap = 0;
**
**
**
** mx1 = 508; ux1 = 0;
** my1 = 508; uy1 = 0;
** mx2 = 188; ux2 = 159;
** my2 = 188; uy2 = 159;
**
**
** drv_params.x_ratio_num = ux1 - ux2;
** drv_params.x_ratio_den = mx1 - mx2;
** drv_params.x_offset =
** ux1 - mx1 * drv_params.x_ratio_num / drv_params.x_ratio_den;
**
** drv_params.y_ratio_num = uy1 - uy2;
** drv_params.y_ratio_den = my1 - my2;
** drv_params.y_offset =
** uy1 - my1 * drv_params.y_ratio_num / drv_params.y_ratio_den;
**
**
** printf("\nNew driver settings:\n");
** tsdrv_params_fprint(stdout, &drv_params);
**
** err = ioctl(ts_fd, TS_PARAMS_SET, &drv_params);
** if(err) {
** fprintf(stderr, "%s: ioctl TS_PARAMS_SET error: %s\n",
** argv[0], strerror(errno));
** close(ts_fd);
** return 0;
** }
**
** return ts_fd;
** }
**
**
**
**
**
** main(int argc, char *argv[])
** {
** int ts_fd = 0;
** struct ts_pen_info pen_info;
** int bytes_transfered = 0;
**
**
** ts_fd = tsdrv_init(argc, argv);
** if(ts_fd==0)
** exit(1);
**
**
** while(1) {
** char whats_up;
** int x, y;
** bytes_transfered = read(ts_fd, (void*)&pen_info, sizeof(pen_info));
** x = pen_info.x;
** y = pen_info.y;
**
** switch(pen_info.event) {
**
** case EV_PEN_UP:
** whats_up = 'U';
** break;
**
** case EV_PEN_DOWN:
** whats_up = 'D';
** break;
**
** case EV_PEN_MOVE:
** whats_up = 'M';
** break;
**
** default:
** whats_up = '?';
** }
**
** printf("%c(%i,%i) ", whats_up, x, y);
** printf("ev_no:%d ", pen_info.ev_no);
** printf("ev_usec:%ld ", pen_info.ev_time);
** printf("bytes_transfered:%d ", bytes_transfered);
** printf("\n");
** }
**
**
** close(ts_fd);
** exit(0);
** }
**
**
**
** <<< End of example ----------------------------------------------------------
*/ |
|