新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 嵌入式Linux設(shè)備驅(qū)動(dòng)開發(fā)之:GPIO驅(qū)動(dòng)程序?qū)嵗?/p>

嵌入式Linux設(shè)備驅(qū)動(dòng)開發(fā)之:GPIO驅(qū)動(dòng)程序?qū)嵗?/h1>
作者: 時(shí)間:2013-09-13 來源:網(wǎng)絡(luò) 收藏

本文引用地址:http://m.butianyuan.cn/article/257110.htm

staticintgpio_ioctl(structinode*inode,structfile*file,

unsignedintcmd,unsignedlongarg)

{/*ioctl函數(shù)接口:主要接口的實(shí)現(xiàn)。對(duì)5個(gè)GPIO設(shè)備進(jìn)行控制(發(fā)亮或發(fā)聲)*/

unsignedintswt=(unsignedint)arg;

switch(cmd)

{

caseLED_D09_SWT:

{

switch_gpio(S3C2410_GPF7,swt);

}

break;

caseLED_D10_SWT:

{

switch_gpio(S3C2410_GPF6,swt);

}

break;

caseLED_D11_SWT:

{

switch_gpio(S3C2410_GPF5,swt);

}

break;

caseLED_D12_SWT:

{

switch_gpio(S3C2410_GPF4,swt);

}

break;

caseBEEP_SWT:

{

switch_gpio(S3C2410_GPB0,swt);

break;

}

default:

{

printk(Unsupportedcommandn);

break;

}

}

return0;

}

staticintgpio_release(structinode*node,structfile*file)

{/*release操作函數(shù),熄滅所有燈和關(guān)閉蜂鳴器*/

switch_gpio(S3C2410_GPB0,BEEP_SWT_OFF);

switch_gpio(S3C2410_GPF4,LED_SWT_OFF);

switch_gpio(S3C2410_GPF5,LED_SWT_OFF);

switch_gpio(S3C2410_GPF6,LED_SWT_OFF);

switch_gpio(S3C2410_GPF7,LED_SWT_OFF);

return0;

}

staticvoidgpio_setup_cdev(structcdev*dev,intminor,

structfile_operations*fops)

{/*字符設(shè)備的創(chuàng)建和注冊(cè)*/

interr,devno=MKDEV(major,minor);

cdev_init(dev,fops);

dev->owner=THIS_MODULE;

dev->ops=fops;

err=cdev_add(dev,devno,1);

if(err)

{

printk(KERN_NOTICEError%daddinggpio%d,err,minor);

}

}

staticstructfile_operationsgpio_fops=

{/*gpio設(shè)備的file_operations結(jié)構(gòu)定義*/

.owner=THIS_MODULE,

.open=gpio_open,/*進(jìn)行初始化配置*/

.release=gpio_release,/*關(guān)閉設(shè)備*/

.read=gpio_read,

.write=gpio_write,

.ioctl=gpio_ioctl,/*實(shí)現(xiàn)主要控制功能*/

};

staticstructcdevgpio_devs;

staticintgpio_init(void)

{

intresult;

dev_tdev=MKDEV(major,0);

if(major)

{/*設(shè)備號(hào)的動(dòng)態(tài)分配*/

result=register_chrdev_region(dev,1,GPIO_DEVICE_NAME);

}

else

{/*設(shè)備號(hào)的動(dòng)態(tài)分配*/

result=alloc_chrdev_region(dev,0,1,GPIO_DEVICE_NAME);

major=MAJOR(dev);

}

if(result0)

{

printk(KERN_WARNINGGpio:unabletogetmajor%dn,major);

returnresult;

}

gpio_setup_cdev(gpio_devs,0,gpio_fops);

printk(Themajorofthegpiodeviceis%dn,major);

return0;

}

linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)

linux相關(guān)文章:linux教程


蜂鳴器相關(guān)文章:蜂鳴器原理


評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉