觸控螢幕驅動程式

2021-06-20 16:24:57 字數 4337 閱讀 2727

觸控螢幕工作原理:

s3c2440觸控螢幕目標是獲取

x/y座標資訊,座標資訊獲取分兩種: 1:

x/y位置分布轉換模式,先獲取其中乙個座標,再獲取另外乙個。 2:

x/y自動轉換模式,兩個座標同時獲取到。

工作流程

一:選擇x/y

座標獲取模式,分別還是自動。

二:設定觸控螢幕到等待終端的狀態。

三:如果中斷發生啟動相應數模轉換。四:數模轉換完成後獲取座標x/y

值,返回等待中斷狀態,到二之後三之前,繼續迴圈。

流程裡有兩個重要中斷int_tc

中斷和int_adc

中斷:1

:int_tc

中斷,當按下彈起觸控螢幕產生。2:

int_adc

中斷,當

tc中斷開始後,啟動

ad轉換,通過

adc中斷告訴

cpu轉換完成。  中斷

->file_operation

#include #include #include #include #include #include #include #include #include #include #include #include /* debug macros */

#undef debug

#ifdef debug

#define dprintk( x... ) printk("s3c2410-ts: " ##x)

#else

#define dprintk( x... )

#endif

#define pen_up 0

#define pen_down 1

#define pen_fleeting 2

#define max_ts_buf 8 /* how many do we want to buffer */

#define device_name "s3c2410-ts"

#define tsraw_minor 1

typedef struct ts_dev;

static ts_dev tsdev;

#define buf_head (tsdev.buf[tsdev.head])

#define buf_tail (tsdev.buf[tsdev.tail])

#define incbuf(x,mod) ((++(x)) & ((mod) - 1))

static int tsmajor = 0;

static void (*tsevent)(void);

#define hook_for_drag

#ifdef hook_for_drag

#define ts_timer_delay (hz/100) /* 10 ms */

static struct timer_list ts_timer;

#endif

#define wait_down_int()

#define wait_up_int()

#define mode_x_axis()

#define mode_x_axis_n()

#define mode_y_axis()

#define start_adc_x()

#define start_adc_y()

#define disable_ts_adc()

static int adc_state = 0;

static int x, y; /* touch screen coorinates */

static void tsevent_raw(void)

else

tsdev.head = incbuf(tsdev.head, max_ts_buf);

wake_up_interruptible(&(tsdev.wq)); /* 喚醒程序 */

}static int tsread(ts_ret * ts_ret)

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

else

return sizeof(ts_ret);

}static unsigned int s3c2410_ts_poll(struct file *filp, struct poll_table_struct *wait)

static inline void start_ts_adc(void)

static inline void s3c2410_get_xy(void)

else if (adc_state == 1)

}static void s3c2410_isr_adc(int irq, void *dev_id, struct pt_regs *reg)

/* 當按鍵按下時首先產生的中斷,數模轉換 */

static void s3c2410_isr_tc(int irq, void *dev_id, struct pt_regs *reg)

else

spin_unlock_irq(&(tsdev.lock));

}#ifdef hook_for_drag

static void ts_timer_handler(unsigned long data)

//按下時每隔0.1s啟動超時函式,獲取按下的座標,筆移動一直獲取座標軌跡

spin_unlock_irq(&(tsdev.lock));

}#endif

static int s3c2410_ts_open(struct inode *inode, struct file *filp)

static int s3c2410_ts_release(struct inode *inode, struct file *filp)

static struct file_operations s3c2410_fops = ;

void tsevent_dummy(void) {}

#ifdef config_devfs_fs

static devfs_handle_t devfs_ts_dir, devfs_tsraw;

#endif

static int __init s3c2410_ts_init(void)

tsmajor = ret;

/* 相應gpio暫存器操作設定為xp, ym, yp and ym */

set_gpio_ctrl(gpio_ypon);

set_gpio_ctrl(gpio_ymon);

set_gpio_ctrl(gpio_xpon);

set_gpio_ctrl(gpio_xmon);

/* 註冊中斷tc, adc */

ret = request_irq(irq_adc_done, s3c2410_isr_adc, sa_interrupt,

device_name, s3c2410_isr_adc);

if (ret) goto adc_failed;

ret = request_irq(irq_tc, s3c2410_isr_tc, sa_interrupt,

device_name, s3c2410_isr_tc);

if (ret) goto tc_failed;

/* 設定暫存器讓觸控螢幕等待被按下的中斷 */

wait_down_int();

#ifdef config_devfs_fs

//建立裝置檔案

devfs_ts_dir = devfs_mk_dir(null, "touchscreen", null);

devfs_tsraw = devfs_register(devfs_ts_dir, "0raw", devfs_fl_default,

tsmajor, tsraw_minor, s_ifchr | s_irusr | s_iwusr,

&s3c2410_fops, null);

#endif

adcdly = 0xffff;

printk(device_name " initialized\n");

return 0;

tc_failed:

free_irq(irq_adc_done, s3c2410_isr_adc);

adc_failed:

return ret;

}static void __exit s3c2410_ts_exit(void)

module_init(s3c2410_ts_init);

module_exit(s3c2410_ts_exit);

多點觸控螢幕 電容屏驅動程式

上面部落格中講解了電阻屏觸控螢幕的驅動程式,它是乙個單點觸控的裝置。現在大多數裝置都支援了多點觸控,多點觸控的好處 1 利用兩個手指可以放大或縮小 2 在乙個觸控螢幕上,可以同時供多人使用 在上述這兩個簡單的例子中,單點觸控就無法實現。必須使用多點觸控,顧名思義多點觸控就是在同一時間內,螢幕上可能有...

觸控螢幕驅動

輸入子系統體系 核心層 linux dir drivers input input.c 提供最核心函式 裝置事件層 linux dir drivers input evdev.c 提供handler 提供輸入裝置產生的原始資料並上報給應用程式,這適用於 所有輸入裝置,該觸控螢幕也不例外 編寫基於輸入...

QT 觸控螢幕 驅動

要 本文主要介紹了在嵌入式 linux 系統下基於 qt embeded 的觸控螢幕驅動的設計,通過對 linux 裝置 驅動和qt embedded裝置驅動介面的工作原理和機制介紹,並結合大量源 進行分析,提出了基於qt embeded 的觸控螢幕驅動的開發方案。linux 下的裝置驅動基礎 li...