📄 led.c
字号:
#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/delay.h>#include <linux/poll.h>#include <linux/spinlock.h>#include <linux/irq.h>#include <asm-arm/hardware.h>#define DEVICE_NAME "led"#define LED_MAJOR 231static unsigned long led_table[]={GPIO_B0,GPIO_B1,GPIO_B2,GPIO_B3};static int led_ioctl(struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg){ write_gpio_bit(led_table[arg],!cmd); return -EINVAL;}static struct file_operations led_fops={ owner:THIS_MODULE,ioctl:led_ioctl};static devfs_handle_t devfs_handle;static int __init led_int(void){ int ret; int i; ret=register_chrdev(LED_MAJOR,DEVICE_NAME,&led_fops); if(ret<0) { printk(DEVICE_NAME"can't register major number\n"); return ret; } devfs_handle=devfs_register(NULL,DEVICE_NAME,DEVFS_FL_DEFAULT,LED_MAJOR,0,S_IFCHR|S_IRUSR|S_IWUSR,&led_fops,NULL); for(i=0;i<4;i++) { set_gpio_ctrl(led_table[i]|GPIO_PULLUP_EN|GPIO_MODE_OUT); write_gpio_bit(led_table[i],1); } printk(DEVICE_NAME"is initialized!Made by fsgu\n"); return 0;}static void __exit led_exit(void){ devfs_unregister(devfs_handle); unregister_chrdev(LED_MAJOR,DEVICE_NAME); printk(DEVICE_NAME" is uninstalled! Made by fsgu\n");}module_init(led_int);module_exit(led_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -