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

📄 sed_drv.c

📁 Linux kernel driver for Epson s1d13700 LCD controller.
💻 C
📖 第 1 页 / 共 3 页
字号:
#include <linux/init.h>#include <linux/module.h>#include <linux/interrupt.h>#include <linux/ioport.h>#include <linux/fs.h>#include <asm/uaccess.h>#include <asm/gpio.h>#include <asm/io.h>#include <asm/arch/at91sam926x_mc.h>//#include <linux/smp_lock.h>#include "def_unix_types.h"#include "graph_ctl.h"#include "font.h"#include "sed_drv.h"#include "core.h"#include "logo.h"#include <linux/delay.h>//#include <linux/spinlock.h>//#include <linux/tqueue.h>BYTE *pRegAddr;//address of registersBYTE *p;BYTE *GRAPH_MEM_REGION;DWORD cur_dir;//current dirrection of cursorDWORD cur_pos=0;// ######################################################################// fuctions prototypesint init_module(void);void cleanup_module(void);static int device_open(struct inode *, struct file *);static int device_release(struct inode *, struct file *);int device_ioctl (struct inode *inode, struct file *file, unsigned int ioctl_num, unsigned long ioctl_param);static ssize_t device_read(struct file *, char *, size_t, loff_t *);static ssize_t device_write(struct file *, const char *, size_t, loff_t *);void SystemSet(void);void Display(int on, BYTE FC);void Scroll(int SAD10,int SAD20,int SAD30,int SAD40);void CursorForm(BYTE CRX,BYTE CRY,BYTE CM);int CursorDir(int dir);void HScroll(void);void Overlay(void);void CGRAMAddress(void);void WriteCursorAddress(DWORD addr);DWORD ReadCursorAddress(void);void LoadFont(void);void InitLCD(void);void CleanLCD(void);void ShowLogo(void);void pixel(int x, int y, BYTE c);void line(int x, int y, int x2, int y2, BYTE c);void dotline(int x, int y, int x2, int y2, BYTE c);void circle(int xc, int yc, int r, BYTE c);void hor_line(int x1,int x2, int y,BYTE c);// ПХЯСЕЛ ЦНПХГНМРЮКЭМСЧ КХМХЧ ЯКЕБЮ МЮОПЮБН => x2>x1void vert_line(int x,int y1,int y2,BYTE c);//ПХЯСЕР БЕПРХЙХКЭМСЧ КХМХЧ ЯБЕПУС БМХГ => y2>y1void vert_line_xor(int x,int y1,int y2);//ПХЯСЕР БЕПРХЙХКЭМСЧ КХМХЧ ЯБЕПУС БМХГ => y2>y1void rect(int x1, int y1, int x2, int y2, BYTE c);void fill_rect(int x1, int y1, int x2, int y2, BYTE c);void fill_rect_gr(int x1, int y1, int x2, int y2, BYTE c);void SetCursorP(int x, int y);void GetCursorP(int *x, int *y);void OutCharXY(char ch, int x, int y);void OutChar(char ch);void OutString(char* text);void OutStringXY(char* text,int x,int y);static struct file_operations fops = {    .read    = device_read,    .write   = device_write,    .ioctl   = device_ioctl,    .open    = device_open,    .release = device_release};// ######################################################################// Methods/* Called when a process tries to open the device file */static int device_open(struct inode *inode, struct file *file){    printk("%s Device opened\n", DEVICE_NAME);    return 0;}// ----------------------------------------------------------------------// Called when a process closes the device file.static int device_release(struct inode *inode, struct file *file){    printk("%s device closed blalbalba\n", DEVICE_NAME);    return 0;}// ----------------------------------------------------------------------// Called when a process attempts to write to dev file: echo hi > /dev/u2devstatic ssize_t device_write(struct file *filp, const char *buffer, size_t length, loff_t *off){	printk("This function is unsupported on device %s: \n", DEVICE_NAME);    return 0;}// ----------------------------------------------------------------------// Called when a process attempts to read from dev file: cat /dev/u2devstatic ssize_t device_read(struct file *filp, char *buffer, size_t length, loff_t *offset){	printk("This function is unsupported on device %s: \n", DEVICE_NAME);    return 0;}//*************************// system set upvoid SystemSet(void){    BYTE bt;//---------Setting REG[00h]----------------	bt = 0x10;	bt = bt | (BYTE)(M0 & 1);	bt = bt | (BYTE)((M1 << 1) & 2);	bt = bt | (BYTE)((M2 << 2) & 4);	bt = bt | (BYTE)((WS << 3) & 8);	bt = bt | (BYTE)((IV << 5) & 0x20);     aS1DRegs[0].Value = bt;     pRegAddr[aS1DRegs[0].Index] = bt;     wmb();//------------------------------------------//---------Setting REG[01h]-----------------	bt = (BYTE)(FX & 0xf) | (BYTE)((WF << 7) & 0x80);	aS1DRegs[1].Value = bt;	pRegAddr[aS1DRegs[1].Index] = bt;	wmb();//------------------------------------------//---------Setting REG[02h]-----------------	bt = (BYTE)(FY & 0xf);	aS1DRegs[2].Value = bt;	pRegAddr[aS1DRegs[2].Index] = bt;	wmb();//------------------------------------------//---------Setting REG[03h]-----------------	bt = (BYTE)CR;	aS1DRegs[3].Value = bt;	pRegAddr[aS1DRegs[3].Index] = bt;	wmb();//------------------------------------------//---------Setting REG[04h]-----------------	bt = (BYTE)TCR;	aS1DRegs[4].Value = bt;	pRegAddr[aS1DRegs[4].Index] = bt;	wmb();//------------------------------------------//---------Setting REG[05h]-----------------	bt = (BYTE)LF;	aS1DRegs[5].Value = bt;	pRegAddr[aS1DRegs[5].Index] = bt;	wmb();//------------------------------------------//---------Setting REG[06h]-----------------	bt = (BYTE)(AP & 0xff);	aS1DRegs[6].Value = bt;	pRegAddr[aS1DRegs[6].Index] = bt;	wmb();//------------------------------------------//---------Setting REG[07h]-----------------	bt = (BYTE)(AP >> 8);	aS1DRegs[7].Value = bt;	pRegAddr[aS1DRegs[7].Index] = bt;	wmb();//------------------------------------------}//*************************************// function for control display// 1- on; 2- off;void Display(int on, BYTE FC){  BYTE bt;  bt = FC & 3;  bt = bt | (BYTE)((FP1 << 2) & 0xc);  bt = bt | (BYTE)((FP2 << 4) & 0x30);  bt = bt | (BYTE)((FP3 << 6) & 0xc0);  if (on==1)  	{	 aS1DRegs[9].Value = 1;	 pRegAddr[aS1DRegs[9].Index] = 1;	 wmb();	}  else	{	 aS1DRegs[9].Value = 0;	 pRegAddr[aS1DRegs[9].Index] = 0;	 wmb();	}  aS1DRegs[10].Value = bt;  pRegAddr[aS1DRegs[10].Index] = bt;  wmb();}// ----------------------------------------------------------------------//*************************************************************************//setting params for the screens, e.g. pushing screens addresses to registersvoid Scroll(int SAD10,int SAD20,int SAD30,int SAD40){  BYTE bt;//---REG0Bh------------------  bt = SAD10 & 0xff;  aS1DRegs[11].Value = bt;  pRegAddr[aS1DRegs[11].Index] = bt;  wmb();//---REG0Ch------------------  bt = SAD10 >> 8;  aS1DRegs[12].Value = bt;  pRegAddr[aS1DRegs[12].Index] = bt;  wmb();//---REG0Dh------------------  bt = SL1;  aS1DRegs[13].Value = bt;  pRegAddr[aS1DRegs[13].Index] = bt;  wmb();//---REG0Eh------------------  bt = SAD20 & 0xff;  aS1DRegs[14].Value = bt;  pRegAddr[aS1DRegs[14].Index] = bt;  wmb();//---REG0Fh------------------  bt = SAD20 >> 8;  aS1DRegs[15].Value = bt;  pRegAddr[aS1DRegs[15].Index] = bt;  wmb();//---REG10h------------------  bt = SL2;  aS1DRegs[16].Value = bt;  pRegAddr[aS1DRegs[16].Index] = bt;  wmb();//---REG11h------------------  bt = SAD30 & 0xff;  aS1DRegs[17].Value = bt;  pRegAddr[aS1DRegs[17].Index] = bt;  wmb();//---REG12h------------------  bt = SAD30 >> 8;  aS1DRegs[18].Value = bt;  pRegAddr[aS1DRegs[18].Index] = bt;  wmb();//---REG13h------------------  bt = SAD40 & 0xff;  aS1DRegs[19].Value = bt;  pRegAddr[aS1DRegs[19].Index] = bt;  wmb();//---REG14h------------------  bt = SAD40 >> 8;  aS1DRegs[20].Value = bt;  pRegAddr[aS1DRegs[20].Index] = bt;  wmb();}//-------------------------------------// setting up the form of the cursor// CRX - width in pixels from left side of symbol// CRY - heigth in pixels from top corner of symbolvoid CursorForm(BYTE CRX,BYTE CRY,BYTE CM){  BYTE bt;//---REG15h-------------------  aS1DRegs[21].Value = CRX;  pRegAddr[aS1DRegs[21].Index] = CRX;  wmb();//---REG16h-------------------  bt = CRY & 0x0f;  bt = bt | (BYTE)((CM << 7) & 0x80);  aS1DRegs[22].Value = bt;  pRegAddr[aS1DRegs[22].Index] = bt;  wmb();}//********************************// setting direction for movement of the cursorint CursorDir(int dir){  BYTE bt;  DWORD old_dir;  old_dir = cur_dir;  cur_dir = dir & 3;//---REG17h-------------------  bt = 0x4c | (dir & 3);  aS1DRegs[23].Value = bt;  pRegAddr[aS1DRegs[23].Index] = bt;  wmb();  return old_dir;}//********************************// horizontal scrollingvoid HScroll(void){//---REG[1Bh]-------------------  BYTE bt;  bt = DX & 7;  aS1DRegs[27].Value = bt;  pRegAddr[aS1DRegs[27].Index] = bt;  wmb();}//********************************// setting up overlayingvoid Overlay(void){  BYTE bt;  bt = MX & 3;  bt = bt | (BYTE)((DM1 << 2) & 4);  bt = bt | (BYTE)((DM2 << 3) & 8);  bt = bt | (BYTE)((OV << 4) & 0x10);//---REG[18h]-------------------  aS1DRegs[24].Value = bt;  pRegAddr[aS1DRegs[24].Index] = bt;  wmb();}//********************************// start address for char generatorvoid CGRAMAddress(void){  BYTE bt;  bt = SAG & 0xff;//---REG[19h]-------------------  aS1DRegs[25].Value = bt;  pRegAddr[aS1DRegs[25].Index] = bt;  wmb();#ifdef DEBUG_MSG  printk("-----------%s SAG low byte = %d \n",DEVICE_NAME,bt);#endif  bt = SAG >> 8;//---REG[1Ah]-------------------  aS1DRegs[26].Value = bt;  pRegAddr[aS1DRegs[26].Index] = bt;  wmb();#ifdef DEBUG_MSG  printk("-----------%s SAG high byte = %d \n",DEVICE_NAME,bt);#endif}//********************************// writes cursor's addressvoid WriteCursorAddress(DWORD addr){  BYTE bt;  bt = addr & 0xff;//---REG[1Ch]-------------------  aS1DRegs[28].Value = bt;  pRegAddr[aS1DRegs[28].Index] = bt;  wmb();  bt = addr >> 8;//---REG[1Dh]-------------------  aS1DRegs[29].Value = bt;  pRegAddr[aS1DRegs[29].Index] = bt;  wmb();  cur_pos = addr;}//********************************// reads cursor's addressDWORD ReadCursorAddress(void){  DWORD addr;  DWORD bt;  bt = pRegAddr[REG001E_CSRR_P1];  rmb();  addr = bt;  bt = pRegAddr[REG001F_CSRR_P2];  rmb();  addr = addr | (bt << 8);  return addr;}//********************************// loading font to memoryvoid LoadFont(void){  BYTE *cg;  int i,j;  CGRAMAddress();  cg = (BYTE*)chargen;  for (i=0;i<256;i++)	for (j=0;j<8;j++)	{	GRAPH_MEM_REGION[SAG+i*8+j] = chargen[i*8+j];

⌨️ 快捷键说明

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