linux中断机制影响tsc2007,ns2009触摸芯片太**了,出来的原始数据偶尔经常出现大偏差,戳东出西,TI的I2C触摸芯片TSC2007价格吓人,只好用新唐单片机模拟...

&i2c0 {

status = "okay";

tsc2007: tsc2007@48 {

compatible = "ti,tsc2007";

reg = <0x48>;

gpios = ;

ti,x-plate-ohms = <500>;

status = "okay";

};

rtc@51 {

compatible = "nxp,pcf8563";

reg = <0x51>;

};

};

tsc2007_core.c:

/*

* drivers/input/touchscreen/tsc2007.c

*

* Copyright (c) 2008 MtekVision Co., Ltd.

*Kwangwoo Lee

*

* Using code from:

* - ads7846.c

*Copyright (c) 2005 David Brownell

*Copyright (c) 2006 Nokia Corporation

* - corgi_ts.c

*Copyright (C) 2004-2005 Richard Purdie

* - omap_ts.[hc], ads7846.h, ts_osk.c

*Copyright (C) 2002 MontaVista Software

*Copyright (C) 2004 Texas Instruments

*Copyright (C) 2005 Dirk Behme

*

* This program is free software; you can redistribute it and/or modify

* it under the terms of the GNU General Public License version 2 as

* published by the Free Software Foundation.

*/

#include

#include

#include

#include

#include

#include "tsc2007.h"

#include

#include

#include

#include

#define TSC2007_MEASURE_TEMP0(0x0 << 4)

#define TSC2007_MEASURE_AUX(0x2 << 4)

#define TSC2007_MEASURE_TEMP1(0x4 << 4)

#define TSC2007_ACTIVATE_XN(0x8 << 4)

#define TSC2007_ACTIVATE_YN(0x9 << 4)

#define TSC2007_ACTIVATE_YP_XN(0xa << 4)

#define TSC2007_SETUP(0xb << 4)

#define TSC2007_MEASURE_X(0xc << 4)

#define TSC2007_MEASURE_Y(0xd << 4)

#define TSC2007_MEASURE_Z1(0xe << 4)

#define TSC2007_MEASURE_Z2(0xf << 4)

#define TSC2007_POWER_OFF_IRQ_EN(0x0 << 2)

#define TSC2007_ADC_ON_IRQ_DIS0(0x1 << 2)

#define TSC2007_ADC_OFF_IRQ_EN(0x2 << 2)

#define TSC2007_ADC_ON_IRQ_DIS1(0x3 << 2)

#define TSC2007_12BIT(0x0 << 1)

#define TSC2007_8BIT(0x1 << 1)

#defineMAX_12BIT((1 << 12) - 1)

#define ADC_ON_12BIT(TSC2007_12BIT | TSC2007_ADC_ON_IRQ_DIS0)

#define READ_Y(ADC_ON_12BIT | TSC2007_MEASURE_Y)

#define READ_Z1(ADC_ON_12BIT | TSC2007_MEASURE_Z1)

#define READ_Z2(ADC_ON_12BIT | TSC2007_MEASURE_Z2)

#define READ_X(ADC_ON_12BIT | TSC2007_MEASURE_X)

#define PWRDOWN(TSC2007_12BIT | TSC2007_POWER_OFF_IRQ_EN)

/*

* This define forces debug prints during development

*/

#define DEBUG_PRINT(1)

#if(DEBUG_PRINT == 1)

#define SR_DEBUGdev_err

#else

#define SR_DEBUGdev_dbg

#endif

static inline int tsc2007_xfer(struct tsc2007 *tsc, u8 cmd)

{

s32 data;

u16 val;

data = i2c_smbus_read_word_data(tsc->client, cmd);

if (data < 0) {

dev_err(&tsc->client->dev, "i2c io error: %d\n", data);

return data;

}

/* The protocol and raw data format from i2c interface:

* S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P

* Where DataLow has [D11-D4], DataHigh has [D3-D0 << 4 | Dummy 4bit].

*/

val = swab16(data) >> 4;

dev_dbg(&tsc->client->dev, "data: 0x%x, val: 0x%x\n", data, val);

return val;

}

static void tsc2007_read_values(struct tsc2007 *tsc, struct ts_event *tc)

{

/* y- still on

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值