📄 lcd_driver.c
字号:
#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 <linux/poll.h>#include <linux/errno.h>#include <linux/sched.h>#include <linux/tty.h>#include <linux/module.h>#include <linux/types.h>#include <linux/fs.h>#include <linux/mm.h>#include <asm/uaccess.h>#include <asm/hardware.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/system.h>#include <asm/proc/pgtable.h>#include <asm/io.h>#include <linux/poll.h>#include <asm/arch/memory.h>#include <asm/arch/io.h>#include <asm/arch/smdk.h>#include "def.h"#define MVAL (13)#define MVAL_USED (0)#define M5D(n) ((n) & 0x1fffff) // To get lower 21bits#define LCD_XSIZE_CSTN (320)#define LCD_YSIZE_CSTN (240)#define SCR_XSIZE_CSTN (LCD_XSIZE_CSTN) //*2for virtual screen #define SCR_YSIZE_CSTN (LCD_YSIZE_CSTN) //*2#define HOZVAL_CSTN (LCD_XSIZE_CSTN*3/8-1) // Valid VD data line number is 8.#define LINEVAL_CSTN (LCD_YSIZE_CSTN-1)#define WLH_CSTN (0)#define WDLY_CSTN (0)#define LINEBLANK_CSTN (16 &0xff)#define CLKVAL_CSTN (6) #define LCDFRAMEBUFFER LCD_BASE //_NONCACHE_STARTADDRESS set in the smdk.c#define BYTESPERLINE (LCD_XSIZE_CSTN)typedef unsigned long tOff;#define XY2OFF(x,y) (tOff)((tOff)y*(tOff)BYTESPERLINE + (x))#define READ_MEM(Off, Data) Data = LCD_READ_MEM(Off)#define WRITE_MEM(Off, Data) LCD_WRITE_MEM(Off, Data)#define GETPIXEL(x, y) GetPixelIndex(x, y)#define SETPIXEL(x, y, c) SetPixel(x, y, c)unsigned lcd_count;void Lcd_CstnOnOff(int onoff);U8 LCD_COLOR = 0x00;U16 LCD_BKCOLOR;#define LCD_MAJOR 60 /**************************************************************************************************************- 函数名称 : void CloseLCD(struct inode * inode, struct file * file)- 函数说明 : LCD关闭- 输入参数 : struct inode * inode, struct file * file- 输出参数 : 0**************************************************************************************************************/static void CloseLCD(struct inode * inode, struct file * file){ printk("LCD is closed\n"); return ;}/**************************************************************************************************************- 函数名称 : static int OpenLCD(struct inode * inode, struct file * file)- 函数说明 : LCD打开- 输入参数 : struct inode * inode, struct file * file- 输出参数 : 0**************************************************************************************************************/static int OpenLCD(struct inode * inode, struct file * file){ printk("LCD is open\n"); return 0;}/**************************************************************************************************************- 函数名称 : static int LCDIoctl(struct inode *inode,struct file * file,unsigned int cmd,unsigned long arg)- 函数说明 : LCD控制输出- 输入参数 : - 输出参数 : 0**************************************************************************************************************/static int LCDIoctl(struct inode *inode,struct file * file,unsigned long cmd,unsigned long arg){//char color; struct para { unsigned long a; unsigned long b; unsigned long c; unsigned long d; }*p_arg; switch(cmd) { case 0: printk("set color\n"); Set_Color(arg); printk("LCD_COLOR =%x\n",LCD_COLOR); return 1; case 1: printk("draw h_line\n"); p_arg =(struct para *)arg; LCD_DrawHLine(p_arg->a,p_arg->b,p_arg->c); // draw h_line LCD_DrawHLine(p_arg->a,p_arg->b+15,p_arg->c); // draw h_line LCD_DrawHLine(p_arg->a,p_arg->b+30,p_arg->c); // draw h_line return 1; case 2: printk("draw v_line\n"); p_arg =(struct para *)arg; LCD_DrawVLine(p_arg->a,p_arg->b,p_arg->c); // draw v_line LCD_DrawVLine(p_arg->a+15,p_arg->b,p_arg->c); // draw v_line LCD_DrawVLine(p_arg->a+30,p_arg->b,p_arg->c); // draw v_line return 1; case 3 : printk("drwa circle\n"); p_arg =(struct para *)arg; LCD_DrawCircle(p_arg->a,p_arg->b,p_arg->c); // draw circle return 1; case 4: printk("draw rect\n"); p_arg =(struct para *)arg; LCD_FillRect(p_arg->a,p_arg->b,p_arg->c,p_arg->d); // draw rect return 1; case 5: printk("draw fillcircle\n"); p_arg =(struct para *)arg; LCD_FillCircle(p_arg->a, p_arg->b, p_arg->c);// draw fillcircle return 1; case 6 : printk("LCD is clear\n"); LCD_Clear(0,0,319,239); // clear screen return 1; case 7: printk("draw rect\n"); p_arg =(struct para *)arg; LCD_FillRect(p_arg->a,p_arg->b,p_arg->c,p_arg->d); // draw rect return 1; default: return -EINVAL; } return 1;}/**************************************************************************************************************- 函数名称 : struct file_operations LCD_fops- 函数说明 : 文件结构- 输入参数 : 无- 输出参数 : 无**************************************************************************************************************/static struct file_operations LCD_fops = { ioctl: LCDIoctl, /* ioctl */ open: OpenLCD, /* just a selector for the real open */ release: CloseLCD, /* release */};/**************************************************************************************************************- 函数名称 : U16 LCD_Init(U8 Lcd_Bpp) - 函数说明 : LCD硬件初始化函数- 输入参数 : - 输出参数 : 无**************************************************************************************************************/U16 Setup_LCDInit(void) { long i; unsigned char * base; GPCUP = 0xffffffff; // Disable Pull-up register GPCCON= 0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND GPDUP = 0xffffffff; // Disable Pull-up register GPDCON= 0xaaaaaaaa; //Initialize VD[23:8] // Packed Type : The L.C.M of 12 and 32 is 96. LCDCON1 = (CLKVAL_CSTN<<8)|(MVAL_USED<<7)|(2<<5)|(3<<1)|0; // 8-bit single scan,8bpp CSTN,ENVID=off LCDCON2 = (0<<24)|(LINEVAL_CSTN<<14)|(0<<6)|0; LCDCON3 = (WDLY_CSTN<<19)|(HOZVAL_CSTN<<8)|(LINEBLANK_CSTN<<0); LCDCON4 = (MVAL<<8)|(WLH_CSTN<<0); LCDCON5 = 2; LCDADDR1 = ((U32)0x33800000>>22)<<21; //use th physical address LCDADDR2 = M5D((((SCR_XSIZE_CSTN )*LCD_YSIZE_CSTN))>>1); LCDADDR3 = (((SCR_XSIZE_CSTN - LCD_XSIZE_CSTN)/2)<<11)|(LCD_XSIZE_CSTN / 2); DITHMODE = 0; REDLUT = 0xfdb96420; GREENLUT = 0xfdb96420; BLUELUT = 0xfb40; base =(unsigned char*)LCD_BASE; Lcd_CstnOnOff(1); for(i=0;i<320*240;i++) { *base++ = 0xff; } return 0; }/**************************************************************************************************************- 函数名称 : U16 LCD_READ_MEM(U32 off)- 函数说明 : 针对硬件的读点函数- 输入参数 : x,y,c- 输出参数 : 无**************************************************************************************************************/U16 LCD_READ_MEM(U32 off){ return (*((U8*)LCDFRAMEBUFFER + (off)));}/**************************************************************************************************************- 函数名称 : void LCD_WRITE_MEM( U32 off,U8 Data)- 函数说明 : 针对硬件的画点函数- 输入参数 : x,y,c- 输出参数 : 无**************************************************************************************************************/ void LCD_WRITE_MEM( U32 off,U8 Data){ (* ((U8*)LCDFRAMEBUFFER + (off)) ) = Data;}/**************************************************************************************************************- 函数名称 : static void SetPixel(U16 x,U16 y,int c)- 函数说明 : 针对硬件的画点函数- 输入参数 : x,y,c- 输出参数 : 无**************************************************************************************************************/static void SetPixel(U16 x, U16 y, U32 c) { tOff Off = XY2OFF(x,y); WRITE_MEM(Off, c);}/**************************************************************************************************************- 函数名称 : void LCD_DrawPixel (U16 x, U16 y) - 函数说明 : 画点函数- 输入参数 : x,y- 输出参数 : 无**************************************************************************************************************/void LCD_DrawPixel (U16 x, U16 y) { SETPIXEL(x, y, LCD_COLOR);}/**************************************************************************************************************- 函数名称 : U32 GetPixelIndex(U16 x, U16 y)- 函数说明 : 针对硬件的得到点的颜色的函数- 输入参数 : x,y- 输出参数 : color**************************************************************************************************************/U32 GetPixelIndex(U16 x, U16 y) { U32 col; U8 Data; tOff Off = XY2OFF(x,y); READ_MEM(Off,Data); col = Data; return col;} /**************************************************************************************************************- 函数名称 : U32 LCD_GetPixel(U16 x, U16 y) - 函数说明 : 得到点值的函数- 输入参数 : x,y- 输出参数 : colof
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -