微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 应用调试-----输入模拟器之编写测试模拟功能

应用调试-----输入模拟器之编写测试模拟功能

时间:11-21 来源:互联网 点击:

{

// 上报事件 //

input_event(s3c_ts_dev, type, code, val);

if (pre_time == 0)

pre_time = time;

}

else

{

// 根据下一个要上报的数据的时间 mod_timer //

mod_timer(&replay_timer, jiffies + (time - pre_time));

pre_time = time;

pre_type = type;

pre_code = code;

pre_val = val;

break;

}

}

}

}

static struct file_operations replay_fops = {

.owner = THIS_MODULE,

.write = replay_write,

.ioctl = replay_ioctl,

};

static void enter_wait_pen_down_mode(void)

{

s3c_ts_regs-"adctsc = 0xd3;

}

static void enter_wait_pen_up_mode(void)

{

s3c_ts_regs-"adctsc = 0x1d3;

}

static void enter_measure_xy_mode(void)

{

s3c_ts_regs-"adctsc = (1""3)|(1""2);

}

static void start_adc(void)

{

s3c_ts_regs-"adccon |= (1""0);

}

void write_input_event_to_file(unsigned int time, unsigned int type, unsigned int code, int val)

{

myprintk("0xx 0xx 0xx %d\n", time, type, code, val);

}

static int s3c_filter_ts(int x[], int y[])

{

#define ERR_LIMIT 10

int avr_x, avr_y;

int det_x, det_y;

avr_x = (x[0] + x[1])/2;

avr_y = (y[0] + y[1])/2;

det_x = (x[2] " avr_x) ? (x[2] - avr_x) : (avr_x - x[2]);

det_y = (y[2] " avr_y) ? (y[2] - avr_y) : (avr_y - y[2]);

if ((det_x " ERR_LIMIT) || (det_y " ERR_LIMIT))

return 0;

avr_x = (x[1] + x[2])/2;

avr_y = (y[1] + y[2])/2;

det_x = (x[3] " avr_x) ? (x[3] - avr_x) : (avr_x - x[3]);

det_y = (y[3] " avr_y) ? (y[3] - avr_y) : (avr_y - y[3]);

if ((det_x " ERR_LIMIT) || (det_y " ERR_LIMIT))

return 0;

return 1;

}

static void s3c_ts_timer_function(unsigned long data)

{

if (s3c_ts_regs-"adcdat0 & (1""15))

{

// 已经松开 : 上报并且打印到proc去

* jiffies, type, code, value

//

input_report_abs(s3c_ts_dev, ABS_PRESSURE, 0);

write_input_event_to_file(jiffies, EV_ABS, ABS_PRESSURE, 0);

input_report_key(s3c_ts_dev, BTN_TOUCH, 0);

write_input_event_to_file(jiffies, EV_KEY, BTN_TOUCH, 0);

input_sync(s3c_ts_dev);

write_input_event_to_file(jiffies, EV_SYN, SYN_REPORT, 0);

enter_wait_pen_down_mode();

}

else

{

// 测量X/Y坐标 //

enter_measure_xy_mode();

start_adc();

}

}

static irqreturn_t pen_down_up_irq(int irq, void *dev_id)

{

if (s3c_ts_regs-"adcdat0 & (1""15))

{

//printk("pen up\n");

input_report_abs(s3c_ts_dev, ABS_PRESSURE, 0);

write_input_event_to_file(jiffies, EV_ABS, ABS_PRESSURE, 0);

input_report_key(s3c_ts_dev, BTN_TOUCH, 0);

write_input_event_to_file(jiffies, EV_KEY, BTN_TOUCH, 0);

input_sync(s3c_ts_dev);

write_input_event_to_file(jiffies, EV_SYN, SYN_REPORT, 0);

enter_wait_pen_down_mode();

}

else

{

//printk("pen down\n");

//enter_wait_pen_up_mode();

enter_measure_xy_mode();

start_adc();

}

return IRQ_HANDLED;

}

static irqreturn_t adc_irq(int irq, void *dev_id)

{

static int cnt = 0;

static int x[4], y[4];

int adcdat0, adcdat1;

// 优化措施2: 如果ADC完成时, 发现触摸笔已经松开, 则丢弃此次结果 //

adcdat0 = s3c_ts_regs-"adcdat0;

adcdat1 = s3c_ts_regs-"adcdat1;

if (s3c_ts_regs-"adcdat0 & (1""15))

{

// 已经松开 //

cnt = 0;

input_report_abs(s3c_ts_dev, ABS_PRESSURE, 0);

write_input_event_to_file(jiffies, EV_ABS, ABS_PRESSURE, 0);

input_report_key(s3c_ts_dev, BTN_TOUCH, 0);

write_input_event_to_file(jiffies, EV_KEY, BTN_TOUCH, 0);

input_sync(s3c_ts_dev);

write_input_event_to_file(jiffies, EV_SYN, SYN_REPORT, 0);

enter_wait_pen_down_mode();

}

else

{

// printk("adc_irq cnt = %d, x = %d, y = %d\n", ++cnt, adcdat0 & 0x3ff, adcdat1 & 0x3ff);

// 优化措施3: 多次测量求平均值 //

x[cnt] = adcdat0 & 0x3ff;

y[cnt] = adcdat1 & 0x3ff;

++cnt;

if (cnt == 4)

{

// 优化措施4: 软件过滤 //

if (s3c_filter_ts(x, y))

{

//printk("x = %d, y = %d\n", (x[0]+x[1]+x[2]+x[3])/4, (y[0]+y[1]+y[2]+y[3])/4);

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top