LCD驅動

1,概念

電子槍:用來打像素點

像素點:即分辨率

RGD:三原色 在計算機領域中,每個像素點又RGB三原色組成像素點的要素值。屏幕上的一個點對應一個具體的數值,該初始值包含紅綠藍三者的值

 

顯存:它會從DDRAM中劃出一部分當顯存用,操作LCD就變成操作顯存和LCD對應的值。那我們LCD驅動主要工作就是配置LCD控制器,往顯卡中傳輸要在LED上顯示的內容,

LCD驅動開發的主要工作:申請顯存,配置LED控制器,讓LED控制器自動的,週期性的,讀取顯存中的數據,按照一定的時序(點和點時間間隔,換行時間,換屏時間)將讀取到的數據發送給LCD屏LCD硬件會完成像素點的顯示,也就是配置他們之間傳數據要和它打點速度兼容

framebuffer:導出LCD物理緩衝區(顯存)到用戶空間(0~3G),用戶空間要顯示一副圖像到LCD屏,在用戶空間直接操作顯存,在用戶空間直接操作顯存,將要顯示的圖像拷貝到顯存中的相應位置,要實現mmap

spacer.gif

 

 

 

#include<stdio.h>

#include<stdlib.h>

#include<fcntl.h>

#include<sys/mmap.h>

#include<linux/fb.h>

srtuct fb_fix_screeninfo fbfix = {0};

struct fb_var_screeninfo fbvar = {0};

int *fb32 = NULL;

 

#define COLOR_RED 0x00ff0000

#define COLOR_GREEN 0X0000FF00

#define COLOR_BLUE  0X000000FF

/*記錄顯存大小*/

long screensize = 0;

int main()

    intfd = -1;

    int x = 0;

    int y = 0;

    fd = open;

    fd = open("/dev/fb0");

if(fd<0)

  printf("open /dev/fb0/ failed! \n");

   return -1;

/*獲取屏幕固定信息*/

ioctl(fd,FBIOGET_FSCREENINFO,&fbfox);

/*獲得屏幕可變信息*/

ioctl(fd,FBIOGET_VSCREENINFO,&fbvar);

screensize = fbvar.xres *fbvar.yres *(fbvar.bits_per_pixel);

fb32 = mmap(0,screensize,PROT_READ,MAP_SHARED,fd,0);

 

if(fb32 = =NULL)

     printf("mmap framebuffer to user space failed! \n");

return -1;

/*操作顯存*/

if(fbvar.bits_per_pixel ==8)

 printf("starting 8 bpp framebuffer test ... \n");

else if(fbvar.bits_per_pixel ==16)

 printf("starting 16 bpp framebuffer test ... \n");

if(fbvar.bits_per_pixel ==24)

 printf("starting 24 bpp framebuffer test ... \n");

 

if(fbvar.bits_per_pixel ==32)

 printf("starting 32 bpp framebuffer test ... \n");

for(;y<fbvar.yres/3;y++)

for(x=0;x<fbvar.xres;x++)

  *(fb32 + x+y*fbvar.xres)= COLOR_RED;

 

for(;y<fbvar.yres2/3;y++)

for(x=0;x<fbvar.xres;x++)

  *(fb32 + x+y*fbvar.xres)= COLOR_GREEN;

 

 

for(;y<fbvar.yres;y++)

for(x=0;x<fbvar.xres;x++)

  *(fb32 + x+y*fbvar.xres)= COLOR_BLUE;

munmap(fd32,screensize);

close(fd);

return 0;

 

一般芯片把不確定的信息變成可調節的信息

LCD 管腳:VD0~VD23:數據管腳   傳送RGB

HSYNC:當該管腳收到信號是,電子槍由最右端跳回最左端

VSYNC:該管腳收到信號時,電子槍由右下角跳回左上角

VCLK::每個VCLK信號使電子槍跳到下一個像素點

VNEN:視頻數據使能電子槍接收VD0~VD23上的數據。

3.時序圖

 HSPW:水平同步脈衝寬度

 HBPD:從水平同步信號到下一行有效信號的寬度,即電子槍從最右端回到最左端的時間

HOZVAL:一行像素個數

HFPD:打完一行像素到下一個水平同步信號,

VSPW垂直同步脈衝寬度

VBPD:一針結束後,垂直同步信號以後的無效行數

 LINEVAL:一共有多少行

VFPD:一針結束後,垂直同步信號以前的無效行數

極性:信號的極性根據外接LCD相應極性可配置

 

 

 

linuxframebuffer框架

linuxLCD驅動開發的最主要數據結構

struct fb_info{

atomic_t count;

int node;

int flags;

struct mutex lock;/* Lock for open/release/ioctl funcs */

struct mutex mm_lock;/* Lock for fb_mmap and smem_* fields */

struct fb_var_screeninfo var;/* Current var */

struct fb_fix_screeninfo fix;/* Current fix */

struct fb_monspecs monspecs;/* Current Monitor specs */

struct work_struct queue;/* Framebuffer event queue */

struct fb_pixmap pixmap;/* Image hardware mapper */

struct fb_pixmap sprite;/* Cursor hardware mapper */

struct fb_cmap cmap;/* Current cmap */

struct list_head modelist;      /* mode list */

struct fb_videomode *mode;/* current mode */

 

struct fb_ops *fbops; //重點

#endif

char __iomem *screen_base;/* Virtual address *///顯存的起始虛擬地址3G~4G

unsigned long screen_size;/* Amount of ioremapped VRAM or 0 */ //記錄顯存大小


}

 

 

struct fb_var_screeninfo {

__u32 xres;/* visible resolution*/

__u32 yres;

__u32 xres_virtual;/* virtual resolution*/

__u32 yres_virtual;

__u32 xoffset;/* offset from virtual to visible */

__u32 yoffset;/* resolution*/

 

__u32 bits_per_pixel;/* guess what*/

__u32 grayscale;/* != 0 Graylevels instead of colors */

 

struct fb_bitfield red;/* bitfield in fb mem if true color, */

struct fb_bitfield green;/* else only length is significant */

struct fb_bitfield blue;

struct fb_bitfield transp;

}

 

struct fb_fix_screeninfo {

char id[16];/* identification string eg "TT Builtin" */

unsigned long smem_start;/* Start of frame buffer mem */顯存的起始位置且是物理的

/* (physical address) */

__u32 smem_len;/* Length of frame buffer mem */顯存大小

__u32 type;/* see FB_TYPE_**/


__u16 reserved[3];/* Reserved for future compatibility */

};

 

 

如果要自己寫個LCD驅動,框架應該怎麼寫

1)分配一個fb_info

  s3cfb_alloc_framebffer()

2)設置/填充該結構體

3)初始化硬件 如:配置GPIO管腳功能,時序初始化配置,申請顯存,將申請到的顯存起始地址告訴LCD控制器

4)註冊fb_info結構

  s3cfb_register_framebuffer(...);

5)內核中的驅動程序

通過make menuconfig可以得到一個路徑和變量。我的變量和路徑是:Graphics support->Support for frame buffer devices(S5P Framebuffer support (Defined at drivers/video/samsung/Kconfig:5  CONFIG_FB_S5P  )  )  Select LCD Type (WA101S)(CONFIG_FB_S5P_WA101S)

->Select LCD Type

平臺設備總線架構

bus

device:evs.c

driver:s3cfb.c

資源 static struct resource s3cfb_resource={}

platfirm_data

核心文件是 fbmen.c

s3cfb.c   s3cfb_fimd6x.c

s3cfb.c ->需要完成的驅動程序   ,s3cfb_fimd6x.c封裝了功能函數,供s3cfb.c調用

LCD手冊中

thpw1~40:20

thb46

HBPD:46-20

s3cfb_init_global(fbdev)

{

s3cfb_set_polarity(ctrl);

s3cfb_set_timing(ctrl);

}

struct file_operations fb_fops

{

.opem

.read

.write

.mmap

.ioctl

      

}

找對應關係的算法register_fb[minor] =fb_info

用戶空間 open()

fb_ops.open()

{

/dev/fbn對應的fb_info.fbops->ops

存在則調用fb_info.fbops->open不存在執行默認操作

}

5驅動程序要驅動的硬件和CPU連接方式

1gpio連接  

2. 類似於內存接口,有數據線,地址線,控制線 BANK

3,協議類接口


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章