完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
使用MISCDEVICE 对gpio 进行操作,使用linux驱动框架 更方便的操作
#include #include #include #include //#include #include #include #include #include #include #include //#include #define AM335X_GPIO(bank,gpio) (32*(bank)+(gpio)) //define gpio port number #define REV_DEV_MINOR 112 //unsigned int irq = 0; char kbuf[100]; static ssize_t fop_write(struct file *filp, const char __user *ubuf, size_t count, loff_t *ppos) { if (copy_from_user(kbuf,ubuf,1)){ printk("write is error n"); } switch (kbuf[0]){ case '1': gpio_set_value(AM335X_GPIO(3,4),1); break; case '0': gpio_set_value(AM335X_GPIO(3,4),0); break; default : break; } return 0; } int fop_open(struct inode *inode, struct file *filp) { printk("success open the file n"); return 0; } int fop_release(struct inode *inode, struct file *filp) { printk("success close the file n"); return 0; } static const struct file_operations rev_fops = { .owner = THIS_MODULE, .write = fop_write, .open = fop_open, .release = fop_release, }; static struct miscdevice rev_dev = { .minor = REV_DEV_MINOR, .name = "rev_dev", .fops = &rev_fops, }; static int __init leds_init(void) { /* * interrupt port */ int rc = -1; //irq = gpio_to_irq(AM335X_GPIO(3,16)); /* * mis_device port */ rc = misc_register(&rev_dev); if (rc){ printk("misc rigester is error n"); } if(gpio_request(AM335X_GPIO(3,16),"rec_gpio")){ printk("gpio_request is error n"); return -EINVAL; } gpio_direction_output(AM335X_GPIO(3,16),0); return 0; } static void __exit leds_exit(void) { printk(KERN_INFO "success fress n"); gpio_free(AM335X_GPIO(3,16)); //misc_deregister(&rev_dev); } module_init(leds_init); module_exit(leds_exit); MODULE_LICENSE("GPL"); |
|
相关推荐
1 个讨论
|
|
只有小组成员才能发言,加入小组>>
【盈鹏飞RK3399安卓主板 XPC-3399Pro免费试用】+烧写出厂固件
10320 浏览 0 评论
【盈鹏飞EVB-T335开发板试用体验】debian系统烧写
3348 浏览 1 评论
【盈鹏飞I.MX6UL工控开发板试用体验】linux can 测试
3226 浏览 0 评论
303浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-19 13:35 , Processed in 0.834044 second(s), Total 69, Slave 53 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191