📄 lcd_driver2.c
字号:
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#include <asm/arch/iic.h>
#include <linux/config.h>
#include <linux/module.h>
#include <linux/devfs_fs_kernel.h>
#include <linux/init.h>
#include <linux/kernel.h> /* printk() */
#include <linux/slab.h> /* kmalloc() */
#include <linux/fs.h> /* everything... */
#include <linux/errno.h> /* error codes */
#include <linux/types.h> /* size_t */
#include <linux/proc_fs.h>
#include <linux/fcntl.h> /* O_ACCMODE */
#include <linux/poll.h> /* COPY_TO_USER */
#include <asm/system.h> /* cli(), *_flags */
#define DEVICE_NAME "led"
#define led_MAJOR 250
#define led_MINOR 0
static int MAX_BUF_LEN=1024;
static int WRI_LENGTH=0;
/*********************************************************************/
/*********************************************************************/
static ssize_t led_write(struct file *filp,const char *buffer, size_t count)
{
char drv_buf[2];
if(count > MAX_BUF_LEN)count = MAX_BUF_LEN;
copy_from_user(drv_buf , buffer, count);
WRI_LENGTH = count;
printk("user write data to driver\n");
IIC_WriteSerial(0x70,0x07,drv_buf,2);//根据输入指令控制指令寄存器(0x70 这个基址在每次写的时候要不要变?)sleep_on函数可以用!
return count;
}
static int led_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
switch(cmd){
case 1:printk("runing command 1 \n");break;
case 2:printk("runing command 2 \n");break;
default:
printk("error cmd number\n");break;
}
return 0;
}
/*********************************************************************/
static int led_open(struct inode *inode, struct file *file)
{
MOD_INC_USE_COUNT;
sprintf(drv_buf,"device open sucess!\n");
printk("device open sucess!\n");
return 0;
}
/*********************************************************************/
static int led_release(struct inode *inode, struct file *filp)
{
MOD_DEC_USE_COUNT;
printk("device release\n");
return 0;
}
/*********************************************************************/
static struct file_operations led_fops = {
owner: THIS_MODULE,
write:led_write,
read: led_read,
ioctl: led_ioctl,
open: led_open,
release: led_release,
};
/*********************************************************************/
#ifdef CONFIG_DEVFS_FS
static devfs_handle_t devfs_led_dir, devfs_ledraw;
#endif
/*********************************************************************/
static int __init led_init(void)
{
int result;
SET_MODULE_OWNER(&led_fops);
result = register_chrdev(led_MAJOR, "scullc", &led_fops);
if (result < 0) return result;
// if (led_MAJOR == 0) led_MAJOR = result; /* dynamic */
printk(DEVICE_NAME " initialized\n");
return 0;
}
/*********************************************************************/
static void __exit led_exit(void)
{
unregister_chrdev(led_MAJOR, "led");
//kfree(led_devices);
printk(DEVICE_NAME " unloaded\n");
}
/*********************************************************************/
module_init(led_init);
module_exit(led_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -