基于PXA255的觸摸屏控制器ADS7843驅(qū)動程序設(shè)計
1) ADS7843 向Linux 內(nèi)核注冊設(shè)備時的初始化函數(shù)
int __init ads7843_t s_init (void) / / 設(shè)備初始化函數(shù)
{int ret ;
if ( ( ret = devf s _ register _ chrdev ( TS _ MAJOR , TS _ NAME , ads7843_t s_fops) ) ! = 0)
{ print k (“ registering of ” TS_NAME “ is failed n” ) ; return ret ;}
devf s_t s_dir = devf s_mk_dir (NULL , “ touchscreen” , NULL) ; / / 建立觸摸屏設(shè)備目錄
devf s_handle = devf s_register ( devf s_t s_dir , “ t s” ,DEVFS_ FL_ DEFAUL T , TS _ MAJOR , 0 , S _ IFCHR | S _ IRUSR | S _ IWUSR , ads7843_t s_fops , NULL) ; / / 注冊設(shè)備
if ( ( ret = request_irq( IRQ_ GPIO_ADS7843 , ads7843_t s_inter-rupt ,
SA_SHIRQ| SA_INTERRUPT , TS_NAME , dev_ id) ) ) / / 申請中斷
{ print k (“ads7843_t s_init : failed to register IRQ n” ) ;
f ree_irq( IRQ_GPIO_ADS7843 , dev_id) ; return ret ;}
if ( ( ret = ads7843_init () ) ! = 0) / / 初始化觸摸屏
{f ree_irq( IRQ_GPIO_ADS7843 , dev_id) ; return ret ;}
GPDR0 = ~GPIO_bit (ADS7843_BUSY) ;
GPDR0 = ~GPIO_bit (ADS7843_DOU T) ;
Ads7843_Enable_IRQ() ;/ / 開啟中斷
print k (“ads7843 touch screen driver initialized n” ) ;
return 0 ;}
2) 系統(tǒng)卸載ADS7843 驅(qū)動程序功能函數(shù)
void __exit ads7843_t s_cleanup (void) / / 卸載驅(qū)動程序函數(shù)
{ if (in_timehandle)
del_timer ( timer) ;
f ree_irq( IRQ_GPIO_ADS7843 , dev_id) ; / / 釋放中斷
devf s_unregister_chrdev( TS_MAJOR , TS_NAME) ;/ / 從系統(tǒng)中刪除設(shè)備驅(qū)動程序
print k (“ ads7843 touch screen driver removed n” ) ;}
3) 在驅(qū)動程序最后用于模塊初始化和刪除驅(qū)動的功能函數(shù)
module_init (ads7843_t s_init) ;/ / 初始化驅(qū)動模塊函數(shù)
module_exit (ads7843_t s_cleanup) ;/ / 刪除驅(qū)動模塊函數(shù)
4) ADS7843 設(shè)備文件操作結(jié)構(gòu)體
static st ruct file_operations ads7843_t s_fops = {
read :ads7843_t s_read , / / 從設(shè)備中讀數(shù)據(jù)操作
poll :ads7843_t s_poll , / / 查詢設(shè)備操作
ioctl : ads7843_t s_ioctl , / / 設(shè)備IO 控制操作
fasync : ads7843_t s_fasync , / / 異步通知操作
open : ads7843_t s_open , / / 打開設(shè)備操作
release : ads7843_t s_release , } ; / / 當(dāng)文件結(jié)構(gòu)被釋放時,調(diào)用釋放操作
由于文章篇幅所限,對設(shè)備文件操作的功能函數(shù)不再一一列出。
評論