CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 19923|回复: 19

a33GPIO口中断问题

[复制链接]
发表于 2015-6-6 12:24:53 | 显示全部楼层 |阅读模式
  1. #include <linux/module.h>
  2. #include<linux/errno.h>
  3. #include<linux/types.h>
  4. #include<linux/init.h>
  5. #include<linux/kernel.h>
  6. #include<linux/cdev.h>
  7. #include<linux/interrupt.h>
  8. #include<linux/irq.h>
  9. #include<linux/gpio.h>
  10. #include<linux/fs.h>
  11. #include<linux/device.h>
  12. #include<linux/uaccess.h>
  13. #include<linux/wait.h>
  14. #include<asm/io.h>
  15. #include<asm/irq.h>
  16. #include<linux/slab.h>
  17. #include<linux/kthread.h>
  18. struct cdev btn_cdev;
  19. wait_queue_head_t btn_wq;
  20. static int major;
  21. static struct class*cls;
  22. static int is_press;
  23. static unsigned char key_val;
  24. //static int press_num;
  25. static int irq;
  26. static void led_on(void)
  27. {
  28. printk("<0>""the lcd is on work\n");
  29. __gpio_set_value(GPIOH(6),1); //点亮lcd屏幕
  30. }
  31. static void led_off(void)
  32. {
  33. printk("<0>""the lcd is off work\n");
  34. __gpio_set_value(GPIOH(6),0); //灭掉lcd屏幕
  35. }
  36. static int button_open(struct inode*inode,struct file*file)
  37. {
  38. return 0;
  39. }
  40. static int button_close(struct inode*inode,struct file*file)
  41. {
  42. return 0;
  43. }
  44. static ssize_t button_read(struct file*file,char __user *buf,size_t count,loff_t *ppos)
  45. {
  46. unsigned long ret;
  47. wait_event_interruptible(btn_wq,is_press!=0);
  48. is_press=0;
  49. ret=copy_to_user(buf,&key_val,sizeof(key_val));
  50. return count;
  51. }
  52. static struct file_operations btn_fops={
  53. .owner=THIS_MODULE,
  54. .open=button_open,
  55. .release=button_close,
  56. .read=button_read
  57. };
  58. static irqreturn_t button_isr(int irq, void*dev_id)
  59. {
  60. unsigned int status;
  61. status=__gpio_get_value(GPIOG(0)); //获取gpiog0的电平值
  62. printk("<0>""the gpio value is %u\n",status);
  63. if(status==1){
  64. led_on();
  65. key_val=0x50;
  66. }else if(status==0){
  67. led_off();
  68. key_val=0x51;
  69. }
  70. printk("<0>""the isr is ok\n");
  71. wake_up_interruptible(&btn_wq);
  72. is_press=1;
  73. return IRQ_HANDLED;
  74. }
  75. static int button_init(void)
  76. {
  77. dev_t dev_id;
  78. int ret;
  79. int error;
  80. if(major){
  81. dev_id=MKDEV(major,0);
  82. register_chrdev_region(dev_id,1,"button_1"); //注册设备

  83. }else{
  84. alloc_chrdev_region(&dev_id,0,1,"button_1");
  85. major=MAJOR(dev_id);
  86. }
  87. printk("<0>""the major is on job\n");
  88. cdev_init(&btn_cdev,&btn_fops);
  89. init_waitqueue_head(&btn_wq);
  90. cdev_add(&btn_cdev,dev_id,1);
  91. cls=class_create(THIS_MODULE,"button_1");
  92. device_create(cls,NULL,dev_id,NULL,"button_1");
  93. ret=gpio_is_valid(GPIOG(0)); //判断gpio是否合法
  94. printk("<0>""the valid value is %d\n",ret);
  95. if(gpio_request(GPIOG(0),"gpio_pin")){
  96. printk("request gpio error\n");
  97. }
  98. gpio_direction_input(GPIOG(0)); //把pg0设置为输入
  99. irq=gpio_to_irq(GPIOG(0)); //gpio实现虚拟irq
  100. printk("<0>""the irq value is %d\n",irq);
  101. error=request_irq(irq,button_isr,IRQF_TRIGGER_FALLING|IRQF_TRIGGER_RISING,"KEY_111",NULL); //上升沿下降沿触发
  102. if(error){
  103. printk("request irq error\n");
  104. }
  105. printk("<0>""the value of error is %d\n",error);
  106. return 0;
  107. }
  108. static void button_exit(void)
  109. {
  110. dev_t dev_id=MKDEV(major,0);
  111. free_irq(irq,NULL); //释放irq
  112. gpio_free(GPIOG(0)); //释放gpio口
  113. device_destroy(cls,dev_id);
  114. class_destroy(cls);
  115. cdev_del(&btn_cdev);
  116. unregister_chrdev_region(dev_id,1); //释放设备
  117. printk("<0>""the dev is unregister\n");
  118. }
  119. module_init(button_init);
  120. module_exit(button_exit);
  121. MODULE_LICENSE("GPL");
  122. MODULE_AUTHOR("LZF");
复制代码
全志a33使用gpio口中断功能,检测一个gpio口,上升沿触发中断,开启背光,点亮lcd屏幕,下降沿,关闭背光,关掉lcd,注册为一个字符设备,设备也注册伤了,proc/interrupts下的irq分配的是1,但是按开关也没反应,大家帮我看看,调了好几天了,我在sys_config里面也加了【gpio_para】。图在下面

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

发表于 2015-6-6 13:27:33 | 显示全部楼层
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-6-6 13:46:32 | 显示全部楼层
jiangdou 发表于 2015-6-6 13:27
http://forum.cubietech.com/forum.php?mod=viewthread&tid=3217&extra=

我想问一下我具体错在哪里啊,你那2个define我看不太懂。
回复 支持 反对

使用道具 举报

发表于 2015-6-8 09:28:40 | 显示全部楼层
按键按下去和释放完全没有打印信息出来吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-6-8 11:24:32 | 显示全部楼层
sunbeyond 发表于 2015-6-8 09:28
按键按下去和释放完全没有打印信息出来吗?

是啊,帮我看看我错在哪里
回复 支持 反对

使用道具 举报

发表于 2015-6-9 11:07:46 | 显示全部楼层
luozf 发表于 2015-6-8 11:24
是啊,帮我看看我错在哪里

驱动我在a80上测了,有反应有打印信息。  把测试程序贴出来看看。另外你按键怎么接的啊。你是用开发板吗?  
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-6-10 14:30:42 | 显示全部楼层
sunbeyond 发表于 2015-6-9 11:07
驱动我在a80上测了,有反应有打印信息。  把测试程序贴出来看看。另外你按键怎么接的啊。你是用开发板吗 ...

是有反应了,但是我开关屏幕实现不了,但是使用gpio_set_value可以改变GPIOH(6)的电平,我错在哪里
回复 支持 反对

使用道具 举报

发表于 2015-6-12 14:54:48 | 显示全部楼层
luozf 发表于 2015-6-10 14:30
是有反应了,但是我开关屏幕实现不了,但是使用gpio_set_value可以改变GPIOH(6)的电平,我错在哪里
...

先单独控制 GPIOH(6)电平看看  屏幕开关能否实现。
回复 支持 反对

使用道具 举报

发表于 2015-6-12 14:54:48 | 显示全部楼层
luozf 发表于 2015-6-10 14:30
是有反应了,但是我开关屏幕实现不了,但是使用gpio_set_value可以改变GPIOH(6)的电平,我错在哪里
...

先单独控制 GPIOH(6)电平看看  屏幕开关能否实现。
回复 支持 反对

使用道具 举报

发表于 2016-3-9 19:24:34 | 显示全部楼层
jiangdou 发表于 2015-6-6 13:27
http://forum.cubietech.com/forum.php?mod=viewthread&tid=3217&extra=

你这个好像是a20上面的,我在a20上面是调通过了,但是移植到a33上面的话
就会出现报错,你有没有在a33上面一直过的?。
我觉得cubiebord论坛,不应该仅仅只是局限于a10或者a20才对
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-5-2 16:05 , Processed in 0.027870 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部