📄 led.c
字号:
//#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include <linux/delay.h>
#include <asm/hardware.h>
#include <asm/arch/regs-gpio.h>
#include <linux/device.h>
//#include <linux/devfs_fs_kernel.h>
#include <linux/types.h>
#include <linux/cdev.h>
#include <linux/errno.h>
#include <asm/uaccess.h>
#define DEVICE_NAME "led"
#define LED_MAJOR 233
MODULE_LICENSE("GPL");
MODULE_ALIAS("led");
static unsigned long led_table [] = {
S3C2410_GPF4, //IO define
S3C2410_GPF5,
S3C2410_GPF6,
S3C2410_GPF7,
S3C2410_GPF4_OUTP, //IO pullup define
S3C2410_GPF5_OUTP,
S3C2410_GPF6_OUTP,
S3C2410_GPF7_OUTP,
};
static int leds_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
switch(cmd) {
case 0:
case 1:
if (arg > 3) {
return -EINVAL;
}
s3c2410_gpio_setpin(led_table[arg],!cmd);//send 0 to led IO,so led is on
break;
default:
return -EINVAL;
}
return 0;
}
static struct file_operations leds_fops = {
.owner = THIS_MODULE,
.ioctl = leds_ioctl, //define ioctl
};
static int __init leds_init(void)
{
int i;
if(register_chrdev(LED_MAJOR,"led",&leds_fops))//register /dev/led with leds_fops OPERATE
{
printk("led driver:Unable to register driver\n");
return -ENODEV;
}
for(i=0;i<4;i++){
s3c2410_gpio_cfgpin(led_table[i],led_table[i+4]); //set all LED IO mode to PULLUP
s3c2410_gpio_setpin(led_table[i],1); //send 1 to all LED IO,close all leds.
}
printk("led driver initialized\n");
}
static void __exit leds_exit(void)
{
unregister_chrdev(LED_MAJOR,"led"); //unregister module
printk("led driver removed\n");
}
module_init(leds_init);
module_exit(leds_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -