📄 sed_drv.c~
字号:
#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 "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>BYTE *pRegAddr;//address of registers BYTE *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 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]; wmb(); }}//********************************// Clean LCD...)void CleanLCD(void){ memset_io(GRAPH_MEM_REGION+SAD1,0x20,SAD2-1); memset_io(GRAPH_MEM_REGION+SAD2,0,SAD3-1);}//********************************void ShowLogo(void){ memcpy_toio(GRAPH_MEM_REGION+SAD2,(BYTE*)logo,(long)WIDTH*HEIGHT/8);}//********************************// void pixel(int x, int y, BYTE c){ long int addr; BYTE bt; BYTE mask; if ((x < 0) || (x >= WIDTH) || (y < 0) || (y >= HEIGHT)) return; addr = SAD2 + (WIDTH/8)*y + (x/8); bt = GRAPH_MEM_REGION[addr]; rmb(); c = c & 1; c = c << (7 - (x % 8)); mask = 1 << (7 - (x % 8)); bt = (bt & (~mask)) | c; GRAPH_MEM_REGION[addr]=bt; wmb();}//********************************// void line(int x, int y, int x2, int y2, BYTE c){if ((x>319)||(x<0)) return;if ((y>239)||(y<0)) return;if ((x2>319)||(x2<0)) return;if ((y2>239)||(y2<0)) return;int i, steep = 0, sx, sy, dx, dy, e; dx = abs(x2 - x); sx = ((x2 - x) > 0) ? 1 : -1; dy = abs(y2 - y); sy = ((y2 - y) > 0) ? 1 : -1; if (dy > dx) { steep = 1; x = x^y; y = y^x; x = x^y; dx = dx^dy; dy = dy^dx; dx = dx^dy; sx = sx^sy; sy = sy^sx; sx = sx^sy; } e = 2*dy - dx; for (i=0; i<dx; i++) { if (steep) pixel(y, x, c); else pixel(x, y, c); while( e >= 0) { y = y + sy; e = e - 2*dx; } x = x + sx; e = e + 2*dy; } pixel(x2, y2, c);}//********************************************************// void dotline(int x, int y, int x2, int y2, BYTE c){ int i, steep = 0, sx, sy, dx, dy, e; dx = abs(x2 - x); sx = ((x2 - x) > 0) ? 1 : -1; dy = abs(y2 - y); sy = ((y2 - y) > 0) ? 1 : -1; if (dy > dx) { steep = 1; x = x^y; y = y^x; x = x^y; dx = dx^dy; dy = dy^dx; dx = dx^dy; sx = sx^sy; sy = sy^sx; sx = sx^sy; } e = 2*dy - dx; for (i=0; i<dx; i++) {// mx = x - (x div y) * y; // my = y mod 2; if (((x%2)^(y%2))>0) { if (steep) pixel(y, x, c); else pixel(x, y, c); } while( e >= 0) { y = y + sy; e = e - 2*dx; } x = x + sx; e = e + 2*dy; } if (((x2%2)^(y2%2))>0) pixel(x2, y2, c);}//********************************// void circle(int xc, int yc, int r, BYTE c){ int x = 0, y = r, d = 2*(1 - r); while (y > 0) { pixel(xc+x, yc+y, c); pixel(xc+x, yc-y, c); pixel(xc-x, yc+y, c); pixel(xc-x, yc-y, c); if ((d + y) > 0) { y = y - 1; d = d - (int)(2*y*1) - 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -