📄 xf86dmc.c
字号:
/* * Copyright (c) 2004 DMC Co., Ltd. * * Copyright (c) 1999 Machine Vision Holdings Incorporated * Author: Mayk Langer <langer@vsys.de> * * Template driver used: Copyright (c) 1998 Metro Link Incorporated * * 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, cpy, 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 Metro Link shall not be * used in advertising or otherwise to promote the sale, use or other dealings * in this Software without prior written authorization from Metro Link. * *//* $XFree86: xc/programs/Xserver/hw/xfree86/input/dmc/xf86DMC.c,v 1.2 2001/11/26 16:25:52 dawes Exp $ *///#define _3MEX2 1#define _DMC_C_#define DEBUG_DMC 0#define DEBUG_CMD 0#define DEBUG_PROM 0#define DEBUG_DISP_POINT 0#define DEBUG_CALIB_AREA 0#define CALIB_PAT_A 1#define EASY_CALIB 1#define LOG_PROM_RD 1#define LOG_PROM_WR 1#if _3MEX2#define TP_MAX_X 1024#define TP_MAX_Y 1024#endif//#include <misc.h>#include <Xos.h>#include <xf86.h>#define NEED_XF86_TYPES#include <xf86_ansic.h>#include <xf86_OSproc.h>#include <xf86Xinput.h>#include <xisb.h>#include <exevents.h>#include <sys/timeb.h>#include "../vers.h"#include "xf86DMC.h"#if _3MEX2#else#include "../usb26/usbdmc.h"#endif#ifndef true#define true 1#define false 0#endif#define SYSCALL(call) while(((call) == -1) && (errno == EINTR))#if 0#ifndef u_chartypedef unsigned char u_char;#endif#ifndef u_shorttypedef unsigned short u_short;#endif#ifndef u_inttypedef unsigned int u_int;#endif#endif/* comm command */#define INI_2_IDLE 0x05#define S_RATE 0x40#define RESET 0x55#define IDLE_2_XYP 0x31#define XYP_2_IDLE 0x02#define IDLE_2_RomRd 0x1d#define IDEL_2_RomWr 0x0d#define ACK 0x06#define NAK 0x15static int asleep(DMCPrivatePtr priv,int sec);static int ring_beep(DMCPrivatePtr priv);BOOL adjust_xy(DMCPrivatePtr priv,int inx,int iny,int *x,int *y);static int calib_cmd_exec(DMCPrivatePtr priv,int mode,InputInfoPtr pInfo);static Bool calib_set(DMCPrivatePtr priv,int type,unsigned char a,int fd);static int set_calib_area(DMCPrivatePtr priv,BOOL use_temp);static int set_temp_data(DMCPrivatePtr priv,int calib_point,int ofs,unsigned int a[][2]);static int set_temp_data_rs(DMCPrivatePtr priv,int calib_point,int ofs,unsigned int a[][2]);static void disp_calib_data(DMCPrivatePtr priv,char *s,unsigned int d[][4]);static void caldif(u_int *d,u_int *a,u_int *b);static void aaacpy(u_int *d,u_int *a,u_int *b);static Bool specify_set(DMCPrivatePtr priv,int fd);static Bool tx_reset_goto_init(DMCPrivatePtr priv,Bool wait_ack);static Bool tx_specify_goto_idle(DMCPrivatePtr priv,Bool wait_ack);static Bool tx_xyp_exit_goto_idle(DMCPrivatePtr priv,Bool wait_ack);static Bool goto_rom_read(DMCPrivatePtr priv);static Bool goto_xyp(DMCPrivatePtr priv);static Bool exec_cmd_send(DMCPrivatePtr priv,u_char s[],int len,Bool wait_ack);static Bool get_status(DMCPrivatePtr priv);static int read_eeprom(DMCPrivatePtr priv);static Bool write_eeprom(DMCPrivatePtr priv);static void set_1_pkt_calib_dat(Pkt_Calib *p,u_int dat[]);static void adj_pkt_calib_dat(Bool write_exec,void *top,int max_x,int max_y);static void adj_1_pkt_calib_dat(u_short *st,int plus,u_short *ed ,int def,u_short omax,u_short nmax);static void cnv_lowhigh_calib_dat(Bool write_exec,void *top);static void cnv_1_lowhigh_calib_dat(Pkt_Calib *p);#define CONV_LOWHIGH(a) ((a>>8)|(a<<8))static Bool read_save_file(DMCPrivatePtr priv);static Bool write_save_file(DMCPrivatePtr priv);static int get_cfg_calib_str(char *str,unsigned int *a,unsigned int *b);static int StrCmp(char *s1,char *s2);static void adj_read_save_file(DMCPrivatePtr priv);static void adj_write_save_file(DMCPrivatePtr priv);static NTIME get_time();static int diff_time(NTIME t2,NTIME t1);InputDriverRec DMC = { 1, "dmc", NULL, DMCPreInit, /*DMCUnInit*/NULL, NULL, 0}; #ifdef XFree86LOADERstatic XF86ModuleVersionInfo VersionRec ={ "dmc", MODULEVENDORSTRING, MODINFOSTRING1, MODINFOSTRING2, XF86_VERSION_CURRENT, 1, 0, 0, ABI_CLASS_XINPUT, ABI_XINPUT_VERSION, MOD_CLASS_XINPUT, {0, 0, 0, 0} /* signature, to be patched into the file by * a tool */};static const char *reqSymbols[] = { "AddEnabledDevice", "ErrorF", "InitButtonClassDeviceStruct", "InitProximityClassDeviceStruct", "InitValuatorAxisStruct", "InitValuatorClassDeviceStruct", "InitPtrFeedbackClassDeviceStruct", "RemoveEnabledDevice", "Xcalloc", "Xfree", "XisbBlockDuration", "XisbFree", "XisbNew", "XisbRead", "XisbTrace", "screenInfo", "xf86AddInputDriver", "xf86AllocateInput", "xf86CloseSerial", "xf86CollectInputOptions", "xf86ErrorFVerb", "xf86FindOptionValue", "xf86GetMotionEvents", "xf86GetVerbosity", "xf86MotionHistoryAllocate", "xf86NameCmp", "xf86OpenSerial", "xf86OptionListCreate", "xf86OptionListMerge", "xf86OptionListReport", "xf86PostButtonEvent", "xf86PostMotionEvent", "xf86PostProximityEvent", "xf86ProcessCommonOptions", "xf86ScaleAxis", "xf86SetIntOption", "xf86SetStrOption", "xf86XInputSetScreen", "xf86XInputSetSendCoreEvents", "xf86getsecs", NULL};static pointer DMCSetupProc(pointer module,pointer options,int *errmaj,int *errmin ){ xf86LoaderReqSymLists(reqSymbols, NULL); xf86AddInputDriver(&DMC, module, 0); return (pointer) 1;}XF86ModuleData dmcModuleData = { &VersionRec, DMCSetupProc, NULL };#endif /* XFree86LOADER *//* * Be sure to set vmin appropriately for your device's protocol. You want to * read a full packet before returning */static const char *default_options[] ={ /* "Device", "/dev/ttyS1",*/ "BaudRate", "9600", "StopBits", "1", "DataBits", "8", "Parity", "None", "Vmin", "3", "Vtime", "1", "FlowControl", "None", NULL,};/* * calibration config file */#define CFG_CALIB_DATA_FILE "/etc/X11/dmc_calib.dat"static char *cfgetcstr[] ={ "PenDownBeep","PenUpBeep","SamplingRate",NULL};static char *cfgrawstr[] ={ "RawX0","RawY0","RawX1","RawY1","RawX2","RawY2","RawX3","RawY3","RawX4","RawY4", "RawX5","RawY5","RawX6","RawY6","RawX7","RawY7","RawX8","RawY8",NULL};static char *cfgcalstr[] ={ "CalX0","CalY0","CalX1","CalY1","CalX2","CalY2","CalX3","CalY3","CalX4","CalY4", "CalX5","CalY5","CalX6","CalY6","CalX7","CalY7","CalX8","CalY8",NULL};/***************************************************************************** * Function Definitions ****************************************************************************/static InputInfoPtr DMCPreInit(InputDriverPtr drv, IDevPtr dev, int flags){ int i; InputInfoPtr pInfo; DMCPrivatePtr priv = xcalloc (1, sizeof (DMCPrivateRec)); char *s; xf86Msg(X_WARNING, "DMC : Touch-Panel Driver %s\n",TBDRV_VERSION); if (!priv) return NULL; if (!(pInfo = xf86AllocateInput(drv, 0))) { xfree(priv); return NULL; } priv->usb_dev = 0; priv->min_x = 0; priv->max_x = 0; priv->min_y = 0; priv->max_y = 0; priv->screen_num = 0; priv->screen_width = -1; priv->screen_height = -1; priv->lex_mode = DMC_byte0; priv->swap_xy = 0; priv->button_down = FALSE; priv->button_number = 1; priv->proximity = FALSE; priv->pen_down = 0; pInfo->type_name = XI_TOUCHSCREEN; pInfo->device_control = DeviceControl; pInfo->read_input = ReadInput; pInfo->control_proc = ControlProc; pInfo->close_proc = CloseProc; pInfo->switch_mode = SwitchMode; pInfo->conversion_proc = ConvertProc; pInfo->dev = NULL; pInfo->private = priv; pInfo->private_flags = 0; pInfo->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS; pInfo->conf_idev = dev; xf86CollectInputOptions(pInfo, default_options, NULL); xf86OptionListReport( pInfo->options ); pInfo->fd = xf86OpenSerial (pInfo->options); if (pInfo->fd == -1) { ErrorF ("DMC driver unable to open device\n"); goto SetupProc_fail; } xf86CloseSerial(pInfo->fd); /* * Process the options for your device like this */ priv->usb_dev = xf86SetIntOption( pInfo->options, "USB", 0 ); priv->fd = pInfo->fd; priv->screen_num = xf86SetIntOption( pInfo->options, "ScreenNumber", 0 ); priv->button_number = xf86SetIntOption( pInfo->options, "ButtonNumber", 1 ); priv->swap_xy = xf86SetIntOption( pInfo->options, "SwapXY", 0 ); priv->buffer = NULL; priv->reporting_mode = TS_Scaled; priv->do_calib = 0; priv->tp_state = 0; priv->calib_point = xf86SetIntOption( pInfo->options, "CalibPoint", 2 ); priv->save_file = xf86SetStrOption( pInfo->options, "SaveFile", CFG_CALIB_DATA_FILE); //read_save_file(priv); priv->proximity = FALSE; priv->button_down = FALSE; priv->lex_mode = DMC_byte0; priv->eeprom_read_ok = FALSE; if (QueryHardware (priv) != Success) { ErrorF ("Unable to query/initialize DMC hardware.\n"); goto SetupProc_fail; } /* this results in an xstrdup that must be freed later */ pInfo->name = xf86SetStrOption( pInfo->options, "DeviceName", "DMC"); xf86ProcessCommonOptions(pInfo, pInfo->options); pInfo->flags |= XI86_CONFIGURED; return (pInfo); SetupProc_fail: if ((pInfo) && (pInfo->fd)) xf86CloseSerial (pInfo->fd); if ((pInfo) && (pInfo->name)) xfree (pInfo->name); if ((priv) && (priv->buffer)) XisbFree (priv->buffer); if (priv) xfree (priv); return (pInfo);}static Bool DeviceControl (DeviceIntPtr dev, int mode){ InputInfoPtr pInfo = dev->public.devicePrivate; DMCPrivatePtr priv = (DMCPrivatePtr) (pInfo->private); unsigned char map[] = {0, 1, 2, 3}; switch (mode) { case DEVICE_INIT: #if 1 #if _3MEX2 xf86Msg(X_WARNING, "DMC : DeviceControl INIT [HW:3M-EXII]\n"); #else xf86Msg(X_WARNING, "DMC : DeviceControl INIT [HW:TSC10]\n"); #endif #endif /* * these have to be here instead of in the SetupProc, because when the * SetupProc is run at server startup, screenInfo is not setup yet */ priv->screen_width = screenInfo.screens[priv->screen_num]->width; priv->screen_height = screenInfo.screens[priv->screen_num]->height; priv->max_x = priv->screen_width; priv->max_y = priv->screen_height; xf86Msg(X_WARNING, "DMC : SCREEN %d x %d max=%d,%d\n" ,priv->screen_width,priv->screen_height,priv->max_x,priv->max_y); read_save_file(priv); /* * Device reports button press for 1 button. */ if (InitButtonClassDeviceStruct (dev, 3, map) == FALSE) { ErrorF ("Unable to allocate DMC ButtonClassDeviceStruct\n"); return !Success; } /* * Device reports motions on 2 axes in absolute coordinates. * Axes min and max values are reported in raw coordinates. */ if (InitValuatorClassDeviceStruct (dev, 2, xf86GetMotionEvents, pInfo->history_size, Absolute) == FALSE) { ErrorF ("Unable to allocate DMC ValuatorClassDeviceStruct\n"); return !Success; } else { InitValuatorAxisStruct (dev, 0, priv->min_x, priv->max_x, 9500, 0 /* min_res */ , 9500 /* max_res */ ); InitValuatorAxisStruct (dev, 1, priv->min_y, priv->max_y, 10500, 0 /* min_res */ , 10500 /* max_res */ ); } if (InitProximityClassDeviceStruct (dev) == FALSE) { ErrorF ("unable to allocate DMC ProximityClassDeviceStruct\n"); return !Success; } if (InitPtrFeedbackClassDeviceStruct(dev, DMCPtrCtrl) == FALSE) { ErrorF ("unable to allocate DMC PtrFeedbackClassDeviceStruct\n"); return !Success; } /* * Allocate the motion events buffer. */ xf86MotionHistoryAllocate (pInfo); return (Success); case DEVICE_ON:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -