📄 lcd.c
字号:
} else { *p=0x66; *(p+1)=0xf6; } } p += (320 * 3 * 4 / 8); } return 0;}intlcd_vline (short x, short y1, short y2, unsigned char c, int xorm){ return _lcd_vline (__lcd_base, x, y1, y2, c, xorm);} voidlcd_clear (void){ { unsigned char *base = __lcd_base; int i; for (i = 0; i < 320 * 240 * 12 / 8; i++) { *base++ = 0x00; // 00: black; FF: white ; } }}int_lcd_chinese (void *fbuf, short x0, short y0, short width, short height, unsigned char *pcc, int xorm){ unsigned char *dst; unsigned char *src; int xi; dst = fbuf + y0 * 320 * 3 * 4 / 8 + x0 * 3 * 4 / 8; src = pcc; for (xi = 0; xi < 16; xi++) { if (*(src + xi * 2) & (0x80 >> 0)){ *(dst + 0) = 0x77; *(dst + 1) &=0xf0; *(dst + 1) |=0x07; } else { *(dst + 0) = 0x00; *(dst + 1) &=0xf0; } if (*(src + xi * 2) & (0x80 >> 1)){ *(dst + 1) &=0x0f; *(dst + 1) |=0x70; *(dst + 2) = 0x77; } else { *(dst + 1) &= 0x0f; *(dst + 2) = 0x00; } if (*(src + xi * 2) & (0x80 >> 2)){ *(dst + 3) = 0x77; *(dst + 4) &=0xf0; *(dst + 4) |=0x07; } else { *(dst + 3) = 0x00; *(dst + 4) &=0xf0; } if (*(src + xi * 2) & (0x80 >> 3)){ *(dst + 4) &=0x0f; *(dst + 4) |=0x70; *(dst + 5) = 0x77; } else { *(dst + 4) &= 0x0f; *(dst + 5) = 0x00; } if (*(src + xi * 2) & (0x80 >> 4)){ *(dst + 6) = 0x77; *(dst + 7) &=0xf0; *(dst + 7) |=0x07; } else { *(dst + 6) = 0x00; *(dst + 7) &=0xf0; } if (*(src + xi * 2) & (0x80 >> 5)){ *(dst + 7) &=0x0f; *(dst + 7) |=0x70; *(dst + 8) = 0x77; } else { *(dst + 7) &= 0x0f; *(dst + 8) = 0x00; } if (*(src + xi * 2) & (0x80 >> 6)){ *(dst + 9) = 0x77; *(dst + 10) &=0xf0; *(dst + 10) |=0x07; } else { *(dst + 9) = 0x00; *(dst + 10) &=0xf0; } if (*(src + xi * 2) & (0x80 >> 7)){ *(dst + 10) &=0x0f; *(dst + 10) |=0x70; *(dst + 11) = 0x77; } else { *(dst + 10) &= 0x0f; *(dst + 11) = 0x00; } if (*(src + xi * 2 + 1) & (0x80 >> 0)){ *(dst + 12) = 0x77; *(dst + 13) &=0xf0; *(dst + 13) |=0x07; } else { *(dst + 12) = 0x00; *(dst + 13) &=0xf0; } if (*(src + xi * 2 + 1) & (0x80 >> 1)){ *(dst + 13) &=0x0f; *(dst + 13) |=0x70; *(dst + 14) = 0x77; } else { *(dst + 13) &= 0x0f; *(dst + 14) = 0x00; } if (*(src + xi * 2 + 1) & (0x80 >> 2)){ *(dst + 15) = 0x77; *(dst + 16) &=0xf0; *(dst + 16) |=0x07; } else { *(dst + 15) = 0x00; *(dst + 16) &=0xf0; } if (*(src + xi * 2 + 1) & (0x80 >> 3)){ *(dst + 16) &=0x0f; *(dst + 16) |=0x70; *(dst + 17) = 0x77; } else { *(dst + 16) &= 0x0f; *(dst + 17) = 0x00; } if (*(src + xi * 2 + 1) & (0x80 >> 4)){ *(dst + 18) = 0x77; *(dst + 19) &=0xf0; *(dst + 19) |=0x07; } else { *(dst + 18) = 0x00; *(dst + 19) &=0xf0; } if (*(src + xi * 2 + 1) & (0x80 >> 5)){ *(dst + 19) &=0x0f; *(dst + 19) |=0x70; *(dst + 20) = 0x77; } else { *(dst + 19) &= 0x0f; *(dst + 20) = 0x00; } if (*(src + xi * 2 + 1) & (0x80 >> 6)){ *(dst + 21) = 0x77; *(dst + 22) &=0xf0; *(dst + 22) |=0x07; } else { *(dst + 21) = 0x00; *(dst + 22) &=0xf0; } if (*(src + xi * 2 + 1) & (0x80 >> 7)){ *(dst + 22) &=0x0f; *(dst + 22) |=0x70; *(dst + 23) = 0x77; } else { *(dst + 22) &= 0x0f; *(dst + 23) = 0x00; } dst += 320 * 3 * 4 / 8; } return 0;}int_lcd_bitmap (void *fbuf, int x, int y, int width, int height, unsigned char *bitmap, int xorm){ unsigned char *dst; unsigned char *src; int width_bytes; int yi; int i; dst = fbuf + y * (320 * 3 * 4 / 8) + x * 12 / 8; width_bytes = width * 3 * 4 / 8; src = bitmap; for (yi = 0; yi < height; yi++) { for (i = 0; i < 8; i++) { if (*(src + yi) & (0x80 >> 0)) { *(dst + 0) = 0x77; *(dst + 1) &=0xf0; *(dst + 1) |=0x07; } else { *(dst + 0) = 0x00; *(dst + 1) &=0xf0; } if (*(src + yi) & (0x80 >> 1)) { *(dst + 1) &=0x0f; *(dst + 1) |=0x70; *(dst + 2) = 0x77; } else { *(dst + 1) &= 0x0f; *(dst + 2) = 0x00; } if (*(src + yi) & (0x80 >> 2)) { *(dst + 3) = 0x77; *(dst + 4) &=0xf0; *(dst + 4) |=0x07; } else { *(dst + 3) = 0x00; *(dst + 4) &=0xf0; } if (*(src + yi) & (0x80 >> 3)) { *(dst + 4) &=0x0f; *(dst + 4) |=0x70; *(dst + 5) =0x77; } else { *(dst + 4) &=0x0f; *(dst + 5) = 0x00; } if (*(src + yi) & (0x80 >> 4)) { *(dst + 6) = 0x77; *(dst + 7) &=0xf0; *(dst + 7) |=0x07; } else { *(dst + 6) = 0x00; *(dst + 7) &=0xf0; } if (*(src + yi) & (0x80 >> 5)) { *(dst + 7) &= 0x0f; *(dst + 7) |=0x70; *(dst + 8) =0x77; } else { *(dst + 7) &= 0x0f; *(dst + 8) = 0x00; } if (*(src + yi) & (0x80 >> 6)) { *(dst + 9) = 0x77; *(dst + 10) &= 0xf0; *(dst + 10) |= 0x07; } else { *(dst + 9) = 0x00; *(dst + 10) &=0xf0; } if (*(src + yi) & (0x80 >> 7)) { *(dst + 10) &= 0x0f; *(dst + 11) |= 0x70; *(dst + 12) =0x77; } else { *(dst + 10) &= 0x0f; *(dst + 11) = 0x00; } } dst += 320 * 3 * 4 / 8; } return 0;}intlcd_bitmap (short x0, short y0, short width, short height, int *pcc, int xorm){ return _lcd_bitmap (__lcd_base, x0, y0, width, height, (unsigned char *)pcc, xorm);}intlcd_chinese (short x0, short y0, short width, short height, unsigned char *pcc, int xorm){ return _lcd_chinese (__lcd_base, x0, y0, width, height, pcc, xorm);}intlcd_textout (short x, short y, unsigned char *buf){ unsigned short *ptr1; int CH, CL; long Pos; unsigned char pixel[32]; unsigned short p[16]; memset (p, '\0', sizeof (unsigned char)); while (*buf) { CH = buf[0]; CL = buf[1]; if (CH >= 0xA1 && CH < 0xF8 && CL >= 0xA1 && CL < 0xFF) { /* * Chinese character */ Pos = ((CH - 0xA1) * 94 + (CL - 0xA1)) * 32L; // printk("Pos = %d\n", Pos); klib_fseek (fp, Pos, SEEK_SET); klib_fread (pixel, 32, fp); // printk("Value read bytes= %d ",i); lcd_chinese (x, y, 16, 16, pixel, 0); x += 16; buf += 2; } else { ptr1 = (void *) (rom8x16_bits + 16 * CH); lcd_bitmap (x, y, 8, 32, (int *)ptr1, 0); x += 8; buf++; } } return 0;}static intLCDIoctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){ textout_t *buffer; chinese_t *cbuffer; vline_t *vline; switch (cmd) { case 2: lcd_clear (); return 1; case 3: buffer = (textout_t *) arg; lcd_textout (buffer->x, buffer->y, buffer->buf); return 1; case 4: cbuffer = (chinese_t *) arg; lcd_chinese (cbuffer->x0, cbuffer->y0, cbuffer->width, cbuffer->height, cbuffer->pcc, cbuffer->xorm); return 1; case 5: vline = (vline_t *)arg; lcd_vline(vline->x, vline->y1, vline->y2, (unsigned char)vline->c,vline->xorm); return 1; default: return -EINVAL; } return 1;}static struct file_operations LCDfops = { ioctl:LCDIoctl, /* ioctl */ open:OpenLCD, /* just a selector for the real open */ release:CloseLCD, /* release */};// /////////////////////////////////////////////////intinit_module (){ int rc; Ready = 0; __lcd_base = (unsigned char *) __ioremap (0xc0000000, 0x20000, 0); /* * disable LCD first */ SYSCON1 &= ~0x00001000; LCDCON = 0xE60f7c1f; PALLSW = 0x76543210; PALMSW = 0xFEDCBA98; /* * setup LCDFRAME */ FBADDR = 0x0000000c; /* * Enable LCD */ SYSCON1 |= 0x00001000; rc = register_chrdev (LCDMajor, "LCD", &LCDfops); if (rc < 0) { printk (KERN_WARNING "LCD: can't get Major %d\n", LCDMajor); return rc; } printk ("LCD init OK!\n"); lcd_clear (); return 0;}voidcleanup_module (void){ int rt; rt = unregister_chrdev (LCDMajor, "LCD"); if (rt < 0) { printk (KERN_WARNING "LCD unregister failed.\n"); } lcd_clear (); printk ("Unload LCD OK!\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -