标签:info 控制器 一个 src res short clu test 框架
首先,需要编写一个led_test.c的文件,依据代码框架,在led_test.c中我们能够看到的只是led.c。我们是看不到led_controller.c的。比如说,在led_test.c中,需要使用led_controller.c中的函数,需要在led.c中对led_controller.c中的函数进行封装。
怎样去使用lcd呢,框图如下:
秉承上述的思想,于是就有了下面的代码。
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 /* 初始化LCD */
10 lcd_init();
11
12 /* 使能LCD */
13 lcd_enable();
14
15 /* 获得LCD的参数: fb_base, xres, yres, bpp */
16 get_lcd_params(&fb_base, &xres, &yres, &bpp);
17
18 /* 往framebuffer中写数据 */
19 if (bpp == 16)
20 {
21 /* 让LCD输出整屏的红色 */
22
23 /* 565: 0xf800 */
24
25 p = (unsigned short *)fb_base;
26 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; y++)
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 }
标签:info 控制器 一个 src res short clu test 框架
原文地址:https://www.cnblogs.com/-glb/p/11371373.html