LCD programming _ simple test

First, you need to write a led_test.c file, according to the source frameworks, in led_test.c we can see only led.c. We can not see the led_controller.c. For example, in led_test.c it is necessary to use the function led_controller.c, the need for the function led_controller.c encapsulated in led.c.

Lcd how to use it, diagram is as follows:

 

Adhering to the above ideas, so there is the following code.

led_test.c

. 1  void lcd_test ( void )
 2  {
 . 3      unsigned int fb_base;
 . 4      int XRES, yres, BPP;
 . 5      int X, Y;
 . 6      unsigned Short * P;
 . 7      unsigned int * P2;
 . 8          
. 9      / * initialize the LCD * / 
10      lcd_init ( );
 . 11  
12 is      / * enable LCD * / 
13 is      lcd_enable ();
 14  
15      / * parameters obtained an LCD: fb_base, XRES, yres, BPP * /
16      get_lcd_params (& fb_base, & XRES, & yres, & BPP);
 . 17      
18 is      / * to framebuffer write data * / 
. 19      IF (BPP == 16 )
 20 is      {
 21 is          / * make the LCD output of the entire screen red * / 
22 is  
23 is          / * 565: 0xF800 * / 
24  
25          P = (unsigned Short * ) fb_base;
 26 is          for (X = 0 ; X <XRES; X ++ )
 27              for (Y = 0 ; Y <yres; Y ++ )
 28                  * = P ++0xf800;
29 
30         /* green */
31         p = (unsigned short *)fb_base;
32         for (x = 0; x < xres; x++)
33             for (y = 0; y < yres; y++)
34                 *p++ = 0x7e0;
35 
36         /* blue */
37         p = (unsigned short *)fb_base;
38         for (x = 0; x < xres; x++)
39             for(y = 0 ; y <yres; and ++ )
 40                  * p ++ = 0x1f ;
41              
42      } 66 }

led.c

 1 #include "lcd.h"
 2 #include "lcd_controller.h"
 3 
 4 #define LCD_NUM 10
 5 
 6 static p_lcd_params p_array_lcd[LCD_NUM];
 7 static p_lcd_params g_p_lcd_selected;
 8 
 9 int register_lcd(p_lcd_params plcd)
10 {
11     int i;
12     for (i = 0; i < LCD_NUM; i++)
13     {
14         if (!p_array_lcd[i])
15         {
16             p_array_lcd[i] = plcd;
17             return i;
18         }
19     }
20     return -1;        
21 }
22 
23 int select_lcd(char *name)
24 {
25     int i;
26     for (i = 0; i < LCD_NUM; i++)
27     {
28         if (p_array_lcd[i] && !strcmp(p_array_lcd[i]->name, name))
29         {
30             g_p_lcd_selected = p_array_lcd[i];
31             return i;
32         }
33     }
34     return -1;        
35 }
36 
37 void get_lcd_params(unsigned int *fb_base, int *xres, int *yres, int *bpp)
38 {
39     *fb_base = g_p_lcd_selected->fb_base;
40     *xres = g_p_lcd_selected->xres;
41     *yres = g_p_lcd_selected->yres;
42     *bpp = g_p_lcd_selected->bpp;
43 }
44 
45 void lcd_enable(void)
46 {
47     lcd_controller_enable();
48 }
49 
50 void lcd_disable(void)
51 {
52     lcd_controller_disable();
53 }
54 
55 int lcd_init(void)
56 {
57     /* 注册LCD */
58     lcd_4_3_add();
59 
60     /* 注册LCD控制器 */
61     lcd_contoller_add();
62     
63     /* 选择某款LCD */
64     select_lcd("lcd_4.3");
65 
66     /* 选择某款LCD控制器 */
67     select_lcd_controller("s3c2440");
68 
69     /* 使用LCD的参数, 初始化LCD控制器 */
70     lcd_controller_init(g_p_lcd_selected);
71 }

lcd_controller.c

 1 #include "lcd_controller.h"
 2 
 3 #define LCD_CONTROLLER_NUM 10
 4 
 5 static p_lcd_controller p_array_lcd_controller[LCD_CONTROLLER_NUM];
 6 static p_lcd_controller g_p_lcd_controller_selected;
 7 
 8 int register_lcd_controller(p_lcd_controller plcdcon)
 9 {
10     int i;
11     for (i = 0; i < LCD_CONTROLLER_NUM; i++)
12     {
13         if (!p_array_lcd_controller[i])
14         {
15             p_array_lcd_controller[i] = plcdcon;
16             return i;
17         }
18     }
19     return -1;        
20 }
21 
22 int select_lcd_controller(char *name)
23 {
24     int i;
25     for (i = 0; i < LCD_CONTROLLER_NUM; i++)
26     {
27         if (p_array_lcd_controller[i] && !strcmp(p_array_lcd_controller[i]->name, name))
28         {
29             g_p_lcd_controller_selected = p_array_lcd_controller[i];
30             return i;
31         }
32     }
33     return -1;        
34 }
35 
36 
37 /* 向上: 接收不同LCD的参数
38  * 向下: 使用这些参数设置对应的LCD控制器
39  */
40 
41 int lcd_controller_init(p_lcd_params plcdparams)
42 {
43     /* 调用所选择的LCD控制器的初始化函数 */
44     if (g_p_lcd_controller_selected)
45     {
46         g_p_lcd_controller_selected->init(plcdparams);
47         return 0;
48     }
49     return -1;
50 }
51 
52 void lcd_controller_enable(void)
53 {
54     if (g_p_lcd_controller_selected)
55     {
56         g_p_lcd_controller_selected->enable();
57     }
58 }
59 
60 void lcd_controller_disable(void)
61 {
62     if (g_p_lcd_controller_selected)
63     {
64         g_p_lcd_controller_selected->disable();
65     }
66 }
67 
68 
69 void lcd_contoller_add(void)
70 {
71     s3c2440_lcd_contoller_add();
72 }

 

Guess you like

Origin www.cnblogs.com/-glb/p/11371373.html