天天看點

LCD驅動

1,概念

電子槍:用來打像素點

像素點:即分辨率

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

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

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

framebuffer:導出LCD實體緩沖區(顯存)到使用者空間(0~3G),使用者空間要顯示一副圖像到LCD屏,在使用者空間直接操作顯存,在使用者空間直接操作顯存,将要顯示的圖像拷貝到顯存中的相應位置,要實作mmap

LCD驅動

#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++)

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

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

  *(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相應極性可配置

linux中 framebuffer架構

linux下LCD驅動開發的最主要資料結構

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手冊中

thpw:1~40:20

thb:46

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連接配接方式

1,gpio連接配接  

2. 類似于記憶體接口,有資料線,位址線,控制線 BANK

3,協定類接口

繼續閱讀