主题 : 触摸屏与AD的共同使用 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 4935
精华: 0
发帖: 32
金钱: 265 两
威望: 211 点
综合积分: 64 分
注册时间: 2009-04-04
最后登录: 2018-02-08
楼主  发表于: 2009-06-14 21:48

 触摸屏与AD的共同使用

我现在使用mini2440做AD采样,2.6.29的内核,AD驱动和触摸屏驱动使用的是光盘自带的,现在的问题是如何使得触摸屏和AD采样同时运行?
如果把触摸屏驱动给注释掉的话,AD采样可以正常运行,采样数据正确。
问题是如果我触摸屏驱动加载后,如果不加载外部信号的话,触摸屏可以正常使用(此时AD采样得到的数据不正确,全部为“0”),如果一加上外部信号的话,触摸屏马上死掉,请问该如何解决?
下面是我的AD驱动程序,是依照光盘程序修改的,其中有一部分是定时器的使用,触摸屏的驱动是光盘中的程序,没有修改过,希望各位给予指点!
#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/clk.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/uaccess.h>
#include <mach/regs-clock.h>
#include <plat/regs-timer.h>
    
#include <plat/regs-adc.h>
#include <mach/regs-gpio.h>
#include <linux/cdev.h>
#include <linux/miscdevice.h>

#include "s3c24xx-adc.h"

#include <linux/timer.h>

#undef DEBUG
//#define DEBUG
#ifdef DEBUG
#define DPRINTK(x...) {printk(__FUNCTION__"(%d): ",__LINE__);printk(##x);}
#else
#define DPRINTK(x...) (void)(0)
#endif

#define DEVICE_NAME    "adc"

static void __iomem *base_addr;
static void __iomem *timer_addr;

typedef struct {
    wait_queue_head_t wait;
    struct cdev cdev;
    struct semaphore lock;
    int channel;
    int prescale;
}ADC_DEV;

//struct ADC_DEV adc_dev;

DECLARE_MUTEX(ADC_LOCK);
volatile static int OwnADC = 0;

static int TimeNum = 0;

static ADC_DEV adcdev;
static volatile int ev_adc = 0;
static int adc_data;

#define value_count 1000

static spinlock_t lock;

static struct clk    *adc_clock;
#define rTCFG0      (*(volatile unsigned long *)(timer_addr + 0x00))
#define rTCFG1      (*(volatile unsigned long *)(timer_addr + 0x04))
#define rTCON       (*(volatile unsigned long *)(timer_addr + 0x08))
#define rTCNTB0     (*(volatile unsigned long *)(timer_addr + 0x0C))
#define rTCMPB0     (*(volatile unsigned long *)(timer_addr + 0x10))
#define rTCNTO0     (*(volatile unsigned long *)(timer_addr + 0x14))

#define ADCCON      (*(volatile unsigned long *)(base_addr + S3C2410_ADCCON))    //ADC control
#define ADCTSC      (*(volatile unsigned long *)(base_addr + S3C2410_ADCTSC))    //ADC touch screen control
#define ADCDLY      (*(volatile unsigned long *)(base_addr + S3C2410_ADCDLY))    //ADC start or Interval Delay
#define ADCDAT0     (*(volatile unsigned long *)(base_addr + S3C2410_ADCDAT0))    //ADC conversion data 0
#define ADCDAT1     (*(volatile unsigned long *)(base_addr + S3C2410_ADCDAT1))    //ADC conversion data 1
#define ADCUPDN     (*(volatile unsigned long *)(base_addr + 0x14))    //Stylus Up/Down interrupt status

#define PRESCALE_DIS        (0 << 14)
#define PRESCALE_EN         (1 << 14)
#define PRSCVL(x)           ((x) << 6)
#define ADC_INPUT(x)        ((x) << 3)
#define ADC_START           (1 << 0)
#define ADC_ENDCVT          (1 << 15)

#define START_ADC_AIN(ch, prescale) \
    do{ \
        ADCCON = PRESCALE_EN | PRSCVL(prescale) | ADC_INPUT((ch)) ; \
        ADCCON |= ADC_START; \
    }while(0)



static timer0_config()
{
    timer_addr = ioremap(S3C2410_PA_TIMER,0x20);

    
    rTCFG0=12;
    rTCFG1=1;    
      rTCNTB0=26406;
      rTCMPB0=0;
    rTCNTO0=26406;

    
}

static int timer0_start()
{
    rTCON|= 1<<1;
    rTCON=0x09;
}




static ssize_t s3c2410_adc_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{

    int value;
    
    unsigned short ad_buf[value_count];
    memset(ad_buf,0,sizeof(unsigned short) * value_count);
    
    timer0_config();
    
    if (down_trylock(&ADC_LOCK) == 0)
    {
        spin_lock_irq(lock);
        int i = 0;
        int m = 0;
        for (i = 1;i<1000;i++)
        {
            START_ADC_AIN(0x0000, adcdev.prescale);
            wake_up_interruptible(&adcdev.wait);
            while(!(ADCCON & 0x8000))
            {
                ;
            }
            ad_buf[m] = ADCDAT0 & 0x3ff;    
            wake_up_interruptible(&adcdev.wait);
            if(m==0)
            {
                timer0_start();
            }
            if(m==998)
            {
                ad_buf[999] = rTCNTO0 & 0xffff;
                rTCON=0x00;
            }    

            m = m+1;

        }
        up(&ADC_LOCK);
        spin_unlock_irq(lock);
    }
    else
    {
        value = -1;
    }
    
    copy_to_user(buffer,ad_buf, (sizeof(unsigned short))*value_count);

}

static int s3c2410_adc_open(struct inode *inode, struct file *filp)
{
    init_waitqueue_head(&(adcdev.wait));

    adcdev.channel=0x0000;
    adcdev.prescale=0x0031;

    DPRINTK( "adc opened\n");
    return 0;
}

static int s3c2410_adc_release(struct inode *inode, struct file *filp)
{
    DPRINTK( "adc closed\n");
    return 0;
}


static struct file_operations dev_fops = {
    owner:    THIS_MODULE,
    open:    s3c2410_adc_open,
    read:    s3c2410_adc_read,    
    release:    s3c2410_adc_release,
};

static struct miscdevice misc = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = DEVICE_NAME,
    .fops = &dev_fops,
};

static int __init dev_init(void)
{
    int ret;
    
    base_addr=ioremap(S3C2410_PA_ADC,0x20);
    if (base_addr == NULL) {
        printk(KERN_ERR "Failed to remap register block\n");
        return -ENOMEM;
    }

    adc_clock = clk_get(NULL, "adc");
    if (!adc_clock) {
        printk(KERN_ERR "failed to get adc clock source\n");
        return -ENOENT;
    }
    clk_enable(adc_clock);
    
    /* normal ADC */
    ADCTSC = 0;

    ret = misc_register(&misc);

    printk (DEVICE_NAME"\tinitialized\n");
    return ret;
}

static void __exit dev_exit(void)
{

    iounmap(base_addr);
    iounmap(timer_addr);

    if (adc_clock) {
        clk_disable(adc_clock);
        clk_put(adc_clock);
        adc_clock = NULL;
    }

    misc_deregister(&misc);
}

EXPORT_SYMBOL(ADC_LOCK);
module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("FriendlyARM Inc.");
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-06-15 07:22
用这个ADC驱动是不可能和触摸屏做到共存的。它里面对ADC操作时根本没有判断ADC是否正在为触摸屏工作。要做到共存,你需要一个可以统一管理ADC用户的ADC驱动,即接受来自触摸屏和普通AD转换通道的请求,并依次处理这些请求。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."