Android抵抗タッチ移植

17896 ワード

ここで使っているのは210の開発ボードシステムAndroid 4.0.4のカーネルlinux 3.0.8です.
抵抗パネルを使うなら、普通はtslibを使って校正します.ここで私がandroidで使うtslibをください.
ダウンロードhttp://download.csdn.net/detail/hclydao/8074069
これを直接androidソースexternalディレクトリに置くと、いくつかの注意が必要です.
tslibでAndroid.mkを変えました.以前はモジュール名のinputが使われていたはずです.だからinput 1に変えました.
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE:= input1
LOCAL_PRELINK_MODULE := false
LOCAL_CFLAGS = $(CFLAGS)
LOCAL_C_INCLUDES = $(C_INCLUDES)
LOCAL_SRC_FILES =  plugins/input-raw.c
LOCAL_SHARED_LIBRARIES += libts
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/ts
include $(BUILD_SHARED_LIBRARY)
ですので、該当するts.comでも私のts.comの内容を以下のように変更します.
# Uncomment if you wish to use the linux input layer event interface
module_raw input1

# Uncomment if you're using a Sharp Zaurus SL-5500/SL-5000d
# module_raw collie

# Uncomment if you're using a Sharp Zaurus SL-C700/C750/C760/C860
# module_raw corgi

# Uncomment if you're using a device with a UCB1200/1300/1400 TS interface
# module_raw ucb1x00

# Uncomment if you're using an HP iPaq h3600 or similar
# module_raw h3600

# Uncomment if you're using a Hitachi Webpad
# module_raw mk712

# Uncomment if you're using an IBM Arctic II
# module_raw arctic2

module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear
はそのままsystem/etc/下に置くといいです.
module_raw input1
後ろのinput 1は上のモジュール名と同じです.
ts.com nfは、システムのコンパイルが完了したら、コピーしたり、tslibの下に直接変更してファイルシステムを作成したりすることができます.
	mkdir rootfs_dir/dev/input
	mkdir rootfs_dir/dev/graphics
	mknod rootfs_dir/dev/graphics/fb0 c 29 0
	mknod rootfs_dir/dev/input/event1  c 13 65
キャリブレーションをinitの前に置いたので、基本的にはデバイスノードがありません.ここで私が自分で抵抗タッチドライバを作成するのはevent 1です.ここに加えます.
そしてcalibrateシナリオです.
#!/bin/sh
export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CALIBFILE=/system/etc/pointercal
export TSLIB_CONFFILE=/system/etc/ts.conf
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/graphics/fb0
export TSLIB_PLUGINDIR=/system/lib/ts
exec /sbin/ts_calibrate
ここのTSDEVICEとFBDEVICEは具体的に自分の改
そして、キャリブレーション後のデータをドライバに戻してキャリブレーションを完了したら、これを実行します.
/system/bin/cat /etc/pointercal > /proc/driver/micc_ts
後ろの/proc/driver/micc_tsドライバから来たこれによってサービスを実行してもいいです.
それから、idcを入れて、これを直接コピーして、名前をドライバの名前に変えたらいいです.ここはs 3 c-tsです.
ファイルシステムの変更は基本的にこのようになりました.
/* linux/drivers/input/touchscreen/s3c-ts.c
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Copyright (c) 2004 Arnaud Patard <[email protected]>
 * iPAQ H1940 touchscreen support
 *
 * ChangeLog
 *
 * 2004-09-05: Herbert Potzl <[email protected]>
 *	- added clock (de-)allocation code
 *
 * 2005-03-06: Arnaud Patard <[email protected]>
 *      - h1940_ -> s3c24xx (this driver is now also used on the n30
 *        machines :P)
 *      - Debug messages are now enabled with the config option
 *        TOUCHSCREEN_S3C_DEBUG
 *      - Changed the way the value are read
 *      - Input subsystem should now work
 *      - Use ioremap and readl/writel
 *
 * 2005-03-23: Arnaud Patard <[email protected]>
 *      - Make use of some undocumented features of the touchscreen
 *        controller
 *
 * 2006-09-05: Ryu Euiyoul <[email protected]>
 *      - added power management suspend and resume code
 *
 */

#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/serio.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
#include <linux/io.h>
#include <asm/irq.h>
#include <mach/hardware.h>

#include <mach/regs-adc.h>
#include <mach/ts-s3c.h>
#include <mach/irqs.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>

/* For ts->dev.id.version */
#define S3C_TSVERSION	0x0101

#define WAIT4INT(x)	(((x)<<8) | \
			S3C_ADCTSC_YM_SEN | S3C_ADCTSC_YP_SEN | \
			S3C_ADCTSC_XP_SEN | S3C_ADCTSC_XY_PST(3))

#define AUTOPST	(S3C_ADCTSC_YM_SEN | S3C_ADCTSC_YP_SEN | \
		 S3C_ADCTSC_XP_SEN | S3C_ADCTSC_AUTO_PST | \
		 S3C_ADCTSC_XY_PST(0))

#ifdef CONFIG_HAS_EARLYSUSPEND
static void ts_early_suspend(struct early_suspend *h);
static void ts_late_resume(struct early_suspend *h);
#endif

/* Touchscreen default configuration */
struct s3c_ts_mach_info s3c_ts_default_cfg __initdata = {
	.delay			= 10000,
	.presc			= 49,
	.oversampling_shift	= 2,
	.resol_bit		= 10
};

/*
 * Definitions & global arrays.
 */
static char *s3c_ts_name = "s3c-ts";
static void __iomem		*ts_base;
static struct resource		*ts_mem;
static struct resource		*ts_irq;
static struct clk		*ts_clock;
static struct s3c_ts_info	*ts;

static struct proc_dir_entry *ts_proc_entry;

signed long pointercal[7] = {1,0,0,0,1,0,1};

static int SCREEN_X=800;
static int SCREEN_Y=480;

#define  TSNUM  8
static   int  ts_x[TSNUM];
static   int  ts_y[TSNUM];
//        tslib      
static int ts_proc_write(struct file *file, const char *buffer,
			     unsigned long count, void *data)
{
	char buf[256];
	unsigned long len;
	char *p = (char *)buf;
	int i,j;
	int flag = 1;
	memset(buf,0,256);
	len = min_t(unsigned long, sizeof(buf) - 1, count);

	if (copy_from_user(buf, buffer, len))
		return count;

	j = 0;
	for(i=0;i<len;i++)
	{
		if(flag)
		{
			pointercal[j] = simple_strtol(p, &p, 10);
			j++; 
			if(j>=7)
				break;
			flag = 0;
		}

		if(p[0] == ' ')
		{
			flag = 1;
		}
		if(p[0] == '\t')
		{
			flag = 1;
		}
		p++;
	}
	return count;
}

static void data_select() {
}

static void touch_timer_fire(unsigned long data)
{
	unsigned long data0;
	unsigned long data1;
	int updown;
	int x, y;
	long a,b,c,d,e,f,div;
	int i,j,tmp;

	data0 = readl(ts_base+S3C_ADCDAT0);
	data1 = readl(ts_base+S3C_ADCDAT1);

	updown = (!(data0 & S3C_ADCDAT0_UPDOWN)) &&
		 (!(data1 & S3C_ADCDAT1_UPDOWN));

	if (updown) {
		if (ts->count) {
			a = pointercal[0];
			b = pointercal[1];
			c = pointercal[2];
			d = pointercal[3];
			e = pointercal[4];
			f = pointercal[5];
			div = pointercal[6];
			for(j=(TSNUM-1);j>0;j--)
			  for(i = 0; i < j;i++)
			  {	
			      if (ts_x[i] < ts_x[i+1])
			      {
					tmp = ts_x[i+1];
					ts_x[i+1]  = ts_x[i];
					ts_x[i] = tmp;
			      }
			     if (ts_y[i] < ts_y[i+1])
			      {
					tmp = ts_y[i+1];
					ts_y[i+1]  = ts_y[i];
					ts_y[i] = tmp;
			      }
	
			 }  

			tmp = 0;
			for (i=TSNUM/4;i<(TSNUM*3/4);i++)
			   tmp+=ts_x[i];
			ts->xp = tmp*2/TSNUM;

			tmp = 0;
			for (i=TSNUM/4;i<(TSNUM*3/4);i++)
			   tmp+=ts_y[i];
			ts->yp  = tmp*2/TSNUM;
                        //     
			x = (a*ts->xp + b*ts->yp + c)/div;
			y = (d*ts->xp + e*ts->yp + f)/div;
			input_report_abs(ts->dev, ABS_X, x);
			input_report_abs(ts->dev, ABS_Y, y);

			input_report_key(ts->dev, BTN_TOUCH, 1);
			input_report_abs(ts->dev, ABS_PRESSURE, 1);//          abs
			input_sync(ts->dev);
		}

		ts->xp = 0;
		ts->yp = 0;
		ts->count = 0;

		writel(S3C_ADCTSC_PULL_UP_DISABLE | AUTOPST,
				ts_base + S3C_ADCTSC);
		writel(readl(ts_base+S3C_ADCCON) | S3C_ADCCON_ENABLE_START,
				ts_base + S3C_ADCCON);
	} else {
		ts->count = 0;
		input_report_key(ts->dev, BTN_TOUCH, 0);
		input_report_abs(ts->dev, ABS_PRESSURE, 0);
		input_sync(ts->dev);
		writel(WAIT4INT(0), ts_base+S3C_ADCTSC);
	}
}

static struct timer_list touch_timer =
		TIMER_INITIALIZER(touch_timer_fire, 0, 0);

static irqreturn_t stylus_updown(int irqno, void *param)
{
	unsigned long data0;
	unsigned long data1;
	int updown;

	data0 = readl(ts_base + S3C_ADCDAT0);
	data1 = readl(ts_base + S3C_ADCDAT1);
	updown = (!(data0 & S3C_ADCDAT0_UPDOWN)) &&
		 (!(data1 & S3C_ADCDAT1_UPDOWN));

	/* TODO we should never get an interrupt with updown set while
	 * the timer is running, but maybe we ought to verify that the
	 * timer isn't running anyways. */

	if (updown)
		touch_timer_fire(0);

	if (ts->s3c_adc_con == ADC_TYPE_2) {
		__raw_writel(0x0, ts_base + S3C_ADCCLRWK);
		__raw_writel(0x0, ts_base + S3C_ADCCLRINT);
	}

	return IRQ_HANDLED;
}

static irqreturn_t stylus_action(int irqno, void *param)
{
	unsigned long data0;
	unsigned long data1;

	data0 = readl(ts_base + S3C_ADCDAT0);
	data1 = readl(ts_base + S3C_ADCDAT1);
	if (ts->resol_bit == 12) {
		ts_x[ts->count] =  (data0 & S3C_ADCDAT0_XPDATA_MASK_12BIT);
		ts_y[ts->count] =  data1 & S3C_ADCDAT1_YPDATA_MASK_12BIT;
	} else {
		ts_x[ts->count] = S3C_ADCDAT0_XPDATA_MASK_12BIT - (data0 & S3C_ADCDAT0_XPDATA_MASK_12BIT);
		ts_y[ts->count] = S3C_ADCDAT1_YPDATA_MASK_12BIT - (data1 & S3C_ADCDAT1_YPDATA_MASK_12BIT);
	}

	ts->count++;

	if (ts->count < TSNUM) {
		writel(S3C_ADCTSC_PULL_UP_DISABLE | AUTOPST,
				ts_base + S3C_ADCTSC);
		writel(readl(ts_base + S3C_ADCCON) | S3C_ADCCON_ENABLE_START,
				ts_base + S3C_ADCCON);
	} else {
		mod_timer(&touch_timer, jiffies + 1);
		writel(WAIT4INT(1), ts_base + S3C_ADCTSC);
	}

	if (ts->s3c_adc_con == ADC_TYPE_2) {
		__raw_writel(0x0, ts_base+S3C_ADCCLRWK);
		__raw_writel(0x0, ts_base+S3C_ADCCLRINT);
	}
	return IRQ_HANDLED;
}

static struct s3c_ts_mach_info *s3c_ts_get_platdata(struct device *dev)
{
	if (dev->platform_data != NULL)
		return (struct s3c_ts_mach_info *)dev->platform_data;

	return &s3c_ts_default_cfg;
}

/*
 * The functions for inserting/removing us as a module.
 */
static int __init s3c_ts_probe(struct platform_device *pdev)
{
	struct resource *res;
	struct device *dev;
	struct input_dev *input_dev;
	struct s3c_ts_mach_info *s3c_ts_cfg;
	int ret, size;
	int irq_flags = 0;
#if defined(CONFIG_FB_S3C_AT070)
		SCREEN_X = 800;
		SCREEN_Y = 480;
#endif
	dev = &pdev->dev;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (res == NULL) {
		dev_err(dev, "no memory resource specified
"); return -ENOENT; } size = (res->end - res->start) + 1; ts_mem = request_mem_region(res->start, size, pdev->name); if (ts_mem == NULL) { dev_err(dev, "failed to get memory region
"); ret = -ENOENT; goto err_req; } ts_base = ioremap(res->start, size); if (ts_base == NULL) { dev_err(dev, "failed to ioremap() region
"); ret = -EINVAL; goto err_map; } ts_clock = clk_get(&pdev->dev, "adc"); if (IS_ERR(ts_clock)) { dev_err(dev, "failed to find watchdog clock source
"); ret = PTR_ERR(ts_clock); goto err_clk; } clk_enable(ts_clock); s3c_ts_cfg = s3c_ts_get_platdata(&pdev->dev); if ((s3c_ts_cfg->presc & 0xff) > 0) writel(S3C_ADCCON_PRSCEN | S3C_ADCCON_PRSCVL(s3c_ts_cfg->presc & 0xFF), ts_base+S3C_ADCCON); else writel(0, ts_base + S3C_ADCCON); /* Initialise registers */ if ((s3c_ts_cfg->delay & 0xffff) > 0) writel(s3c_ts_cfg->delay & 0xffff, ts_base + S3C_ADCDLY); if (s3c_ts_cfg->resol_bit == 12) { switch (s3c_ts_cfg->s3c_adc_con) { case ADC_TYPE_2: writel(readl(ts_base + S3C_ADCCON) | S3C_ADCCON_RESSEL_12BIT, ts_base + S3C_ADCCON); break; case ADC_TYPE_1: writel(readl(ts_base + S3C_ADCCON) | S3C_ADCCON_RESSEL_12BIT_1, ts_base + S3C_ADCCON); break; default: dev_err(dev, "this type of AP isn't supported !
"); break; } } writel(WAIT4INT(0), ts_base + S3C_ADCTSC); ts = kzalloc(sizeof(struct s3c_ts_info), GFP_KERNEL); input_dev = input_allocate_device(); if (!input_dev) { ret = -ENOMEM; goto err_alloc; } ts->dev = input_dev; ts->dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); ts->dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); if (s3c_ts_cfg->resol_bit == 12) { input_set_abs_params(ts->dev,ABS_X, 0, SCREEN_X, 0, 0); input_set_abs_params(ts->dev,ABS_Y, 0, SCREEN_Y, 0, 0); } else { input_set_abs_params(ts->dev, ABS_X, 0, SCREEN_X, 0, 0); input_set_abs_params(ts->dev, ABS_Y, 0, SCREEN_Y, 0, 0); } input_set_abs_params(ts->dev, ABS_PRESSURE, 0, 1, 0, 0); sprintf(ts->phys, "input(ts)"); ts->dev->name = s3c_ts_name;// idc ts->dev->phys = ts->phys; ts->dev->id.bustype = BUS_RS232; ts->dev->id.vendor = 0xDEAD; ts->dev->id.product = 0xBEEF; ts->dev->id.version = S3C_TSVERSION; ts->shift = s3c_ts_cfg->oversampling_shift; ts->resol_bit = s3c_ts_cfg->resol_bit; ts->s3c_adc_con = s3c_ts_cfg->s3c_adc_con; #ifdef CONFIG_HAS_EARLYSUSPEND ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; ts->early_suspend.suspend = ts_early_suspend; ts->early_suspend.resume = ts_late_resume; register_early_suspend(&ts->early_suspend); #endif /* For IRQ_PENDUP */ ts_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (ts_irq == NULL) { dev_err(dev, "no irq resource specified
"); ret = -ENOENT; goto err_irq; } ret = request_irq(ts_irq->start, stylus_updown, irq_flags, "s3c_updown", ts); if (ret != 0) { dev_err(dev, "s3c_ts.c: Could not allocate ts IRQ_PENDN !
"); ret = -EIO; goto err_irq; } /* For IRQ_ADC */ ts_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 1); if (ts_irq == NULL) { dev_err(dev, "no irq resource specified
"); ret = -ENOENT; goto err_irq; } ret = request_irq(ts_irq->start, stylus_action, irq_flags, "s3c_action", ts); if (ret != 0) { dev_err(dev, "s3c_ts.c: Could not allocate ts IRQ_ADC !
"); ret = -EIO; goto err_irq; } printk(KERN_INFO "%s got loaded successfully : %d bits
", s3c_ts_name, s3c_ts_cfg->resol_bit); /* All went ok, so register to the input system */ ret = input_register_device(ts->dev); if (ret) { dev_err(dev, "Could not register input device(touchscreen)!
"); ret = -EIO; goto fail; } ts_proc_entry = create_proc_entry("driver/micc_ts", 0, NULL); // if (ts_proc_entry) { ts_proc_entry->write_proc = ts_proc_write; } return 0; fail: free_irq(ts_irq->start, ts->dev); free_irq(ts_irq->end, ts->dev); err_irq: input_free_device(input_dev); kfree(ts); err_alloc: clk_disable(ts_clock); clk_put(ts_clock); err_clk: iounmap(ts_base); err_map: release_resource(ts_mem); kfree(ts_mem); err_req: return ret; } static int s3c_ts_remove(struct platform_device *dev) { printk(KERN_INFO "s3c_ts_remove() of TS called !
"); disable_irq(IRQ_ADC); disable_irq(IRQ_PENDN); free_irq(IRQ_PENDN, ts->dev); free_irq(IRQ_ADC, ts->dev); if (ts_clock) { clk_disable(ts_clock); clk_put(ts_clock); ts_clock = NULL; } #ifdef CONFIG_HAS_EARLYSUSPEND unregister_early_suspend(&ts->early_suspend); #endif input_unregister_device(ts->dev); iounmap(ts_base); return 0; } #ifdef CONFIG_PM static unsigned int adccon, adctsc, adcdly; static int s3c_ts_suspend(struct platform_device *dev, pm_message_t state) { adccon = readl(ts_base+S3C_ADCCON); adctsc = readl(ts_base+S3C_ADCTSC); adcdly = readl(ts_base+S3C_ADCDLY); disable_irq(IRQ_ADC); disable_irq(IRQ_PENDN); clk_disable(ts_clock); return 0; } static int s3c_ts_resume(struct platform_device *pdev) { clk_enable(ts_clock); writel(adccon, ts_base+S3C_ADCCON); writel(adctsc, ts_base+S3C_ADCTSC); writel(adcdly, ts_base+S3C_ADCDLY); writel(WAIT4INT(0), ts_base+S3C_ADCTSC); enable_irq(IRQ_ADC); enable_irq(IRQ_PENDN); return 0; } #else #define s3c_ts_suspend NULL #define s3c_ts_resume NULL #endif #ifdef CONFIG_HAS_EARLYSUSPEND static void ts_early_suspend(struct early_suspend *h) { struct s3c_ts_info *ts; ts = container_of(h, struct s3c_ts_info, early_suspend); s3c_ts_suspend(NULL, PMSG_SUSPEND); } static void ts_late_resume(struct early_suspend *h) { struct s3c_ts_info *ts; ts = container_of(h, struct s3c_ts_info, early_suspend); s3c_ts_resume(NULL); } #endif static struct platform_driver s3c_ts_driver = { .probe = s3c_ts_probe, .remove = s3c_ts_remove, .suspend = s3c_ts_suspend, .resume = s3c_ts_resume, .driver = { .owner = THIS_MODULE, .name = "s3c-ts", }, }; static char banner[] __initdata = KERN_INFO \ "S5P Touchscreen driver, (c) 2008 Samsung Electronics
"; static int __init s3c_ts_init(void) { printk(banner); return platform_driver_register(&s3c_ts_driver); } static void __exit s3c_ts_exit(void) { platform_driver_unregister(&s3c_ts_driver); } module_init(s3c_ts_init); module_exit(s3c_ts_exit); MODULE_AUTHOR("Samsung AP"); MODULE_DESCRIPTION("S5P touchscreen driver"); MODULE_LICENSE("GPL");
ADCがリガを駆動しているだけで、具体的なADCドライバはもちろんです.大体の説明は全部書いてあります.基本的にはこれです.
修正が完了したらテストの効果は悪くないです.