led驱动详解电子版本.docVIP

  • 2
  • 0
  • 约8.1千字
  • 约 14页
  • 2020-12-30 发布于浙江
  • 举报
led驱动详解 __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ #include linux/module.h #include linux/init.h//头文件:module_init、module_exit等宏定义。 #include linux/fs.h////struct file_operations #include asm/irq.h #include mach/regs-gpio.h// S3C2410 GPIO寄存器定义 #include mach/hardware.h// s3c2410_gpio_setpin, s3c2410_gpio_cfgpin等 #include linux/device.h//class_create device_create(注意,有些2.6.27以前是的可能是class_device_create,如果出现implicate 错误时,看一下这个头问题里边是哪一个),udev,自动在/dev下创建设备节点 #include linux/cdev.h//字符设备节点注册,函数有cdev_init,cdev_add,cdev_del等早期的办法是register_chrdev,unregister_chrdev这种方法应避免使用。 #define DEVICE_NAME leds #define LED_MAJOR 231 #define IOCTL_LED_ON 1#define IOCTL_LED_OFF 0 static unsigned long led_table [] ={S3C2410_GPB5, S3C2410_GPB6, S3C2410_GPB7, S3C2410_GPB8,} static unsigned int led_cfg_table [] ={ S3C2410_GPB5_OUTP,S3C2410_GPB6_OUTP,S3C2410_GPB7_OUTP, S3C2410_GPB8_OUTP,}; struct leds_type { struct cdev cdev; }; struct leds_type *my_leds_dev; static int EmbedSky_leds_open(struct inode *inode, struct file *file) { int i; for (i = 0; i 4; i++) { // 设置GPIO引脚的功能:本驱动中LED所涉及的GPIO引脚设为输出功能 s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]); } return 0;} static int EmbedSky_leds_ioctl( struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { if (arg 4) { return -EINVAL; } switch(cmd) { case IOCTL_LED_ON:// 设置指定引脚的输出电平为0 s3c2410_gpio_setpin(led_table[arg], 0); return 0; case IOCTL_LED_OFF: // 设置指定引脚的输出电平为1 s3c2410_gpio_setpin(led_table[arg],1); return 0; defa

文档评论(0)

1亿VIP精品文档

相关文档