⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 嵌入式下实验的新的驱动设计源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <linux/module.h>/*#include <linux/kernel.h>*/#include <linux/fs.h>#include <linux/sched.h>#include <linux/file.h>#include <linux/config.h>#include <linux/utsname.h>#include <linux/kernel.h>#include <linux/major.h>#include <linux/string.h>#include <linux/fcntl.h>#include <linux/slab.h>#include <linux/timer.h>#include <linux/init.h>#include <asm/proc/pgtable.h>#include <asm/irq.h>#include <asm/io.h>#include "lcd.h"#include "rom8x16.h"#define LCDCON		*(unsigned long *)0xff0002c0#define PALLSW		*(unsigned long *)0xff000580#define PALMSW		*(unsigned long *)0xff000540#define FBADDR		*(unsigned long *)0xff001000#define SYSCON1     *(unsigned long *)0xff000100#define LXMAX		320*3*4#define LEFTMASK        "\x00\x80\xc0\xe0\xf0\xf8\xfc\xfe"#define RIGHTMASK       "\xff\x7f\x3f\x1f\x0f\x07\x03\x01"#define R2MASK          "\x7f\x3f\x1f\x0f\x07\x03\x01\x00"#define L2MASK          "\x80\xc0\xe0\xf0\xf8\xfc\xfe\xff"#define FONT_FILE "./hzk"struct file *fp;static unsigned char *__lcd_base;typedef struct{	unsigned char id[2];	long filesize;	short reserved[2];	long headsize;	long infosize;	long width;	long height;	short planes;	short bits;	long biCompression;	long sizeimage;	long biXpp;	long biYpp;	long biclrused;	long biclrimportant;} BMPHEAD;#define copy_to_user(t,f,n)         (memcpy_tofs(t,f,n), 0)#define LCDMajor 	60static short Ready;#define EOF (-1)#define SEEK_SET 0#define SEEK_CUR 1#define SEEK_END 2#define MAKE_MM_SEG(s)       ((mm_segment_t) { (s) })#define KERNEL_DS	MAKE_MM_SEG(0xFFFFFFFF)#define get_fs()        (current->addr_limit)#define set_fs(x)       (current->addr_limit=(x))// // Function Prototypes // struct file *klib_fopen (const char *filename, int flags, int mode);void klib_fclose (struct file *filp);int klib_fseek (struct file *filp, int offset, int whence);int klib_fread (char *buf, int len, struct file *filp);int klib_fgetc (struct file *filp);char *klib_fgets (char *str, int size, struct file *filp);int klib_fwrite (char *buf, int len, struct file *filp);int klib_fputc (int ch, struct file *filp);int klib_fputs (char *str, struct file *filp);int klib_fprintf (struct file *filp, const char *fmt, ...);// // Library Functions // struct file *klib_fopen (const char *filename, int flags, int mode){	struct file *filp = filp_open (filename, flags, mode);	return (IS_ERR (filp)) ? NULL : filp;}voidklib_fclose (struct file *filp){	if (filp)		fput (filp);}intklib_fseek (struct file *filp, int offset, int whence){	int pos = filp->f_pos;	if (filp)	{		if (whence == SEEK_SET)			pos = offset;		else if (whence == SEEK_CUR)			pos += offset;		if (pos < 0)			pos = 0;		return (filp->f_pos = pos);	}	else		return -ENOENT;}intklib_fread (char *buf, int len, struct file *filp){	int readlen;	mm_segment_t oldfs;	if (filp == NULL)		return -ENOENT;	if (filp->f_op->read == NULL)		return -ENOSYS;	if (((filp->f_flags & O_ACCMODE) & O_RDONLY) != 0)		return -EACCES;	oldfs = get_fs ();	set_fs (KERNEL_DS);	readlen = filp->f_op->read (filp, buf, len, &filp->f_pos);	set_fs (oldfs);	return readlen;}intklib_fgetc (struct file *filp){	int len;	unsigned char buf[4];	len = klib_fread ((char *) buf, 1, filp);	if (len > 0)		return buf[0];	else if (len == 0)		return EOF;	else		return len;}char *klib_fgets (char *str, int size, struct file *filp){	char *cp;	int len, readlen;	mm_segment_t oldfs;	if (filp && filp->f_op->read	    && ((filp->f_flags & O_ACCMODE) & O_WRONLY) == 0)	{		oldfs = get_fs ();		set_fs (KERNEL_DS);		for (cp = str, len = -1, readlen = 0; readlen < size - 1;		     ++cp, ++readlen)		{			if ((len =			     filp->f_op->read (filp, cp, 1,					       &filp->f_pos)) <= 0)				break;			if (*cp == '\n')			{				++cp;				++readlen;				break;			}		}		*cp = 0;		set_fs (oldfs);		return (len < 0 || readlen == 0) ? NULL : str;	}	else		return NULL;}intklib_fwrite (char *buf, int len, struct file *filp){	int writelen;	mm_segment_t oldfs;	if (filp == NULL)		return -ENOENT;	if (filp->f_op->write == NULL)		return -ENOSYS;	if (((filp->f_flags & O_ACCMODE) & (O_WRONLY | O_RDWR)) == 0)		return -EACCES;	oldfs = get_fs ();	set_fs (KERNEL_DS);	writelen = filp->f_op->write (filp, buf, len, &filp->f_pos);	set_fs (oldfs);	return writelen;}intklib_fputc (int ch, struct file *filp){	int len;	unsigned char buf[4];	buf[0] = (unsigned char) ch;	len = klib_fwrite (buf, 1, filp);	if (len > 0)		return buf[0];	else		return EOF;}intklib_fputs (char *str, struct file *filp){	return klib_fwrite (str, strlen (str), filp);}intklib_fprintf (struct file *filp, const char *fmt, ...){	static char s_buf[1024];	va_list args;	va_start (args, fmt);	vsprintf (s_buf, fmt, args);	va_end (args);	return klib_fputs (s_buf, filp);}static voidCloseLCD (struct inode *inode, struct file *file){	// close interrupt	printk ("LCD is closed\n");	return;}static intOpenLCD (struct inode *inode, struct file *file){	Ready = 0;	printk ("LCD is open\n");	return 0;}int_lcd_vline (unsigned char *fbuf, int x, int y, int y1, int color, int xorm){	unsigned char *p;	int tmp;	if (y1 < y)	{		tmp = y;		y = y1;		y1 = tmp;	}	p = fbuf + x * 12 / 8 + y * (320 * 3 * 4 / 8);	for (; y <= y1; y++)	{	        if(color==1)         	{                	if(x&1)	        	{		        	*p&=0x0f;			        *(p+1)=0x00;	         	}	         	else	        	{		        	 *p=0x00;		               	*(p+1)&=0xf0;	         	}                }                else if(color==2)                            {                               if(x&1)                        {                                 *p&=0x0f;                                 *p|=0x70;                                  *(p+1)=0x77;                        }                        else                        {                                 *p=0x77;                                 *(p+1)&=0xf0;                                 *(p+1)|=0x07;                        }                }                else if(color==3)                            {                               if(x&1)                        {                                 *p&=0x0f;                                 *(p+1)=0x70;                        }                        else                        {                                 *p=0x00;                                 *(p+1)&=0xf0;                                 *(p+1)|=0x07;                        }                }                else if(color==4)                            {                               if(x&1)                        {                                 *p&=0x0f;                                 *(p+1)=0x07;                        }                        else                        {                                 *p=0x70;                                 *(p+1)&=0xf0;                        }                }                else if(color==5)                            {                               if(x&1)                        {                                 *p&=0x0f;                                 *p|=0x70;                                 *(p+1)=0x00;                        }                        else                        {                                 *p=0x07;                                 *(p+1)&=0xf0;                        }                }                else if(color==6)                            {                               if(x&1)                        {                                *p&=0x0f;                                *(p+1)=0x77;                        }                        else                        {                                *p=0x70;                                *(p+1)&=0xf0;                                *(p+1)|=0x07;                        }                }                else if(color==7)                {                        if(x&1)                        {                                *p&=0x0f;                                *p|=0x70;                                *(p+1)=0x70;                        }                        else                        {                                *p=0x07;                                *(p+1)&=0xf0;                                *(p+1)|=0x07;                        }                }                else if(color==8)                {                        if(x&1)                        {                                *p&=0x0f;                                *p|=0x70;                                *(p+1)=0x07;                        }                        else                        {                                *p=0x77;                                *(p+1)&=0xf0;                        }                }              else   if(color==9)                {                        if(x&1)                        {                                *p=0x6f;                                                                 *(p+1)=0x06;                        }                        else                        {                                 *p=0x66;                                                                 *(p+1)=0xf0;                        }                }   	                 else    if(color==10)                {                        if(x&1)                        {                                *p&=0x0f;                                *p|=0x30;                                *(p+1)=0x03;                        }                        else                        {                                 *p&=0x03;                                 *p|=0x30;                                *(p+1)&=0xf0;                        }                }             else  if(color==11)                {                        if(x&1)                        {                                *p&=0x0f;                                *(p+1)&=0x60;                                *(p+1)|=0x06;                            }                        else                        {                                 *p=0x60;                                *(p+1)&=0xf6;                        }                }          else  if(color==12)                {                        if(x&1)                        {                                *p&=0x0f;                                *p|=0x60;                                 *(p+1)=0x60;                        }                        else                        {                                 *p=0x06;                                                                        *(p+1)&=0xf0;                                *(p+1)|=0x06;                        }                }           else  if(color==13)                {                        if(x&1)                        {                                *p=0x6f;                                                               *(p+1)=0x66;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -