xilib.c
来自「一份介绍在S3C2410上液晶屏驱动程序的实现」· C语言 代码 · 共 306 行
C
306 行
/* * * Copyright (c) 2004 DMC Co., Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of the DMC Co., Ltd shall not * be used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from DMC Co., Ltd. *//* * EUC * tab=4 */#include <X11/Xlib.h>#include <X11/extensions/XI.h>#include <X11/extensions/XInput.h>#include <stdio.h>//#include <curses.h>#include "tb.h"#define SELCT_CMD 0xa0#define SELCT_LEFT_CMD (SELCT_CMD+0)#define SELCT_MID_CMD (SELCT_CMD+1)#define SELCT_RIGHT_CMD (SELCT_CMD+2)#define GET_SELCT_LEFT_CMD (SELCT_CMD+3)#define GET_SELCT_MID_CMD (SELCT_CMD+4)#define GET_SELCT_RIGHT_CMD (SELCT_CMD+5)#define S_RATE_CMD 0xB0 /* S_RATE_CMD+n : n=d2-d0 bit=rate */#define BEEP_ON_UP_CMD 0xB8#define BEEP_OFF_UP_CMD 0xB9#define BEEP_ON_DOWN_CMD 0xBA#define BEEP_OFF_DOWN_CMD 0xBB#define RESET_CMD 0xBC// c0-c8 ,d0-df#define CALIB_CMD_RANGE_S 0xc0#define CALIB_CMD_RANGE_E 0xdf#define CALIB_MASK 0x0f#define CALIB_ADJ_DAT_CMD 0xc0 /* CALIB_ADJ_DAT_CMD+n : n=d3-d0 bit=calib point */#define CALIB_1_DAT 0xd0 /* CALIB_1_DAT+n : n=d3-d0 bit=calib data(nibble) */#define CALIB_PRE_FIRST_CMD 0xca#define CALIB_FIRST_CMD 0xcb#define CALIB_NEXT_CMD 0xcc#define CALIB_END_CMD 0xcd#define CALIB_OK_CMD 0xce#define CALIB_CANCEL_CMD 0xcf#if 1#define PRINT(a,b,c,d,e) printf(a,b,c,d,e)#else#define PRINT(a,b,c,d,e)#endifstatic XDeviceInfo *info = NULL;static XDevice *dev = NULL;static XDeviceControl *dctl = NULL;static char drvname[100];static int do_set_calib(u_short dat);static XDeviceInfo *find_device_info(Display *display,char *name, Bool only_extended);int open_xinput_driver(char *driver_name){int ctype,res;char s[512]; strcpy(drvname,driver_name); if( info == NULL && (info = find_device_info(gDisp, drvname, 1)) == NULL ) { PRINT("error : find device [%s]\n",drvname,0,0,0); return(-1); } PRINT("device [%s]\n",drvname,0,0,0); if( dev == NULL && (dev = XOpenDevice(gDisp,info->id)) == NULL ) { PRINT("error : open device [%s]\n",drvname,0,0,0); return(-1); } PRINT("open device [%s]\n",drvname,0,0,0);#if 0 ctype = DEVICE_RESOLUTION; if( dctl == NULL && (dctl = XGetDeviceControl(gDisp,dev,ctype)) == NULL ) { PRINT("error : get device [%s]\n",drvname,0,0,0); return(-1); } PRINT("get device [%s]\n",drvname,0,0,0);#endif return(0);}int test_xidrv(){int res;unsigned long a; if( dev == NULL ) return(-1); a = 0xf8; res = XSetDeviceMode(gDisp,dev,a); PRINT("test_xidrv [%s] res=%d \n",drvname,res,a,0); return( 0 );}int set_raw_mode(int on){int res;unsigned long a; if( dev == NULL ) return(-1); a = on ? TS_Raw : TS_Scaled; res = XSetDeviceMode(gDisp,dev,a); PRINT("set_raw_mode [%s] res=%d \n",drvname,res,a,0); return( 0 );}int is_selector_on(){int res;unsigned long a; if( dev == NULL ) return(-1); a = GET_SELCT_MID_CMD; if( XSetDeviceMode(gDisp,dev,a) == Success ) return( 1 ); a = GET_SELCT_RIGHT_CMD; if( XSetDeviceMode(gDisp,dev,a) == Success ) return( 2 ); return( 0 );}int select_button(int bttn) /* 0=left/1=middle/2=right */{int res;unsigned long a; if( dev == NULL ) return(-1); a = SELCT_CMD + bttn; res = XSetDeviceMode(gDisp,dev,a); PRINT("select_tb [%s] res=%d cmd=$%x \n",drvname,res,a,0); return( (res == 0 ? 0 : -1) );}int reset_tb(){int res;unsigned long a; if( dev == NULL ) return(-1); a = RESET_CMD; res = XSetDeviceMode(gDisp,dev,a); PRINT("reset_tb [%s] res=%d cmd=$%x \n",drvname,res,a,0); return( (res == 0 ? 0 : -1) );}int set_samp_rate(int s_rate){int res;unsigned long a; if( dev == NULL ) return(-1); if( s_rate < 0 || s_rate > 5 ) return(-1); a = S_RATE_CMD + s_rate; res = XSetDeviceMode(gDisp,dev,a); PRINT("set_samp_rate [%s] res=%d cmd=$%x \n",drvname,res,a,0); return( (res == 0 ? 0 : -1) );}int set_beep(int pen_down,int on){int res;unsigned long a; if( dev == NULL ) return(-1); if( pen_down ) a = on ? BEEP_ON_DOWN_CMD : BEEP_OFF_DOWN_CMD; else a = on ? BEEP_ON_UP_CMD : BEEP_OFF_UP_CMD; res = XSetDeviceMode(gDisp,dev,a); PRINT("set_beep [%s] res=%d cmd=$%x \n",drvname,res,a,0); return( (res == 0 ? 0 : -1) );}int set_next_calib(){int res;unsigned long a; if( dev == NULL ) return(-1); a = CALIB_NEXT_CMD; res = XSetDeviceMode(gDisp,dev,a); PRINT("set_next_calib [%s] res=%d cmd=$%x \n",drvname,res,a,0); return( (res == 0 ? 0 : -1) );}int set_end_calib(){int res;unsigned long a; if( dev == NULL ) return(-1); a = CALIB_END_CMD; res = XSetDeviceMode(gDisp,dev,a); PRINT("set_end_calib [%s] res=%d cmd=$%x \n",drvname,res,a,0); return( (res == 0 ? 0 : -1) );}int cancel_calib(){int res;unsigned long a; if( dev == NULL ) return(-1); a = CALIB_CANCEL_CMD; res = XSetDeviceMode(gDisp,dev,a); PRINT("cancel_calib [%s] res=%d cmd=$%x \n",drvname,res,a,0); return( (res == 0 ? 0 : -1) );}int ok_calib(){int res;unsigned long a; if( dev == NULL ) return(-1); a = CALIB_OK_CMD; res = XSetDeviceMode(gDisp,dev,a); PRINT("ok_calib [%s] res=%d cmd=$%x \n",drvname,res,a,0); return( (res == 0 ? 0 : -1) );}int set_start_calib(uRect adj[],int count){int res,i,n;unsigned long a; PRINT("set_start_calib : XSetDeviceMode -> SwitchMode\n",0,0,0,0); if( dev == NULL ) return(-1); if( count > 9 || count < 2 ) return(-1); a = CALIB_PRE_FIRST_CMD; res = XSetDeviceMode(gDisp,dev,a); PRINT("set_start_calib [%s] res=%d cmd=$%x \n",drvname,res,a,0); for( i=0 ; i < count ; i++ ) { a = CALIB_ADJ_DAT_CMD + i; res = XSetDeviceMode(gDisp,dev,a); PRINT("set_start_calib [%s] res=%d cmd=$%x \n",drvname,res,a,0); do_set_calib(0); // raw x do_set_calib(0); // raw y do_set_calib((u_short)adj[i].x); do_set_calib((u_short)adj[i].y); } a = CALIB_FIRST_CMD; res = XSetDeviceMode(gDisp,dev,a); PRINT("set_start_calib [%s] res=%d cmd=$%x \n",drvname,res,a,0); return( (res == 0 ? 0 : -1) );}static int do_set_calib(u_short dat){int n,res;u_char a; for( n=12 ; n >= 0 ; n-=4 ) { a = CALIB_1_DAT | ((dat >> n) & 0x0f); res = XSetDeviceMode(gDisp,dev,a); //PRINT("set mode [%s] res=%d dat=$%x \n",drvname,res,a,0); } return(0);}static XDeviceInfo *find_device_info(Display *display,char *name, Bool only_extended){XDeviceInfo *devices;int loop;int num_devices;int len = strlen(name);Bool is_id = True;XID id; for( loop=0 ; loop < len; loop++ ) { if( !isdigit(name[loop]) ) { is_id = False; break; } } if( is_id ) id = atoi(name); devices = XListInputDevices(display, &num_devices); for( loop=0 ; loop < num_devices ; loop++ ) { if( (!only_extended || (devices[loop].use == IsXExtensionDevice)) && ((!is_id && strcmp(devices[loop].name, name) == 0) || (is_id && devices[loop].id == id))) { return &devices[loop]; } } return NULL;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?