首先,需要编写一个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

 void lcd_test(void)
{
unsigned int fb_base;
int xres, yres, bpp;
int x, y;
unsigned short *p;
unsigned int *p2; /* 初始化LCD */
lcd_init(); /* 使能LCD */
lcd_enable(); /* 获得LCD的参数: fb_base, xres, yres, bpp */
get_lcd_params(&fb_base, &xres, &yres, &bpp); /* 往framebuffer中写数据 */
if (bpp == )
{
/* 让LCD输出整屏的红色 */ /* 565: 0xf800 */ p = (unsigned short *)fb_base;
for (x = ; x < xres; x++)
for (y = ; y < yres; y++)
*p++ = 0xf800; /* green */
p = (unsigned short *)fb_base;
for (x = ; x < xres; x++)
for (y = ; y < yres; y++)
*p++ = 0x7e0; /* blue */
p = (unsigned short *)fb_base;
for (x = ; x < xres; x++)
for (y = ; y < yres; y++)
*p++ = 0x1f; } }

led.c

 #include "lcd.h"
#include "lcd_controller.h" #define LCD_NUM 10 static p_lcd_params p_array_lcd[LCD_NUM];
static p_lcd_params g_p_lcd_selected; int register_lcd(p_lcd_params plcd)
{
int i;
for (i = ; i < LCD_NUM; i++)
{
if (!p_array_lcd[i])
{
p_array_lcd[i] = plcd;
return i;
}
}
return -;
} int select_lcd(char *name)
{
int i;
for (i = ; i < LCD_NUM; i++)
{
if (p_array_lcd[i] && !strcmp(p_array_lcd[i]->name, name))
{
g_p_lcd_selected = p_array_lcd[i];
return i;
}
}
return -;
} void get_lcd_params(unsigned int *fb_base, int *xres, int *yres, int *bpp)
{
*fb_base = g_p_lcd_selected->fb_base;
*xres = g_p_lcd_selected->xres;
*yres = g_p_lcd_selected->yres;
*bpp = g_p_lcd_selected->bpp;
} void lcd_enable(void)
46 {
47 lcd_controller_enable();
48 }
49
void lcd_disable(void)
51 {
52 lcd_controller_disable();
53 } int lcd_init(void)
{
/* 注册LCD */
lcd_4_3_add(); /* 注册LCD控制器 */
lcd_contoller_add(); /* 选择某款LCD */
select_lcd("lcd_4.3"); /* 选择某款LCD控制器 */
select_lcd_controller("s3c2440"); /* 使用LCD的参数, 初始化LCD控制器 */
lcd_controller_init(g_p_lcd_selected);
}

lcd_controller.c

 #include "lcd_controller.h"

 #define LCD_CONTROLLER_NUM 10

 static p_lcd_controller p_array_lcd_controller[LCD_CONTROLLER_NUM];
static p_lcd_controller g_p_lcd_controller_selected; int register_lcd_controller(p_lcd_controller plcdcon)
{
int i;
for (i = ; i < LCD_CONTROLLER_NUM; i++)
{
if (!p_array_lcd_controller[i])
{
p_array_lcd_controller[i] = plcdcon;
return i;
}
}
return -;
} int select_lcd_controller(char *name)
{
int i;
for (i = ; i < LCD_CONTROLLER_NUM; i++)
{
if (p_array_lcd_controller[i] && !strcmp(p_array_lcd_controller[i]->name, name))
{
g_p_lcd_controller_selected = p_array_lcd_controller[i];
return i;
}
}
return -;
} /* 向上: 接收不同LCD的参数
* 向下: 使用这些参数设置对应的LCD控制器
*/ int lcd_controller_init(p_lcd_params plcdparams)
{
/* 调用所选择的LCD控制器的初始化函数 */
if (g_p_lcd_controller_selected)
{
g_p_lcd_controller_selected->init(plcdparams);
return ;
}
return -;
} 52 void lcd_controller_enable(void)
53 {
54 if (g_p_lcd_controller_selected)
55 {
56 g_p_lcd_controller_selected->enable();
57 }
58 } void lcd_controller_disable(void)
61 {
62 if (g_p_lcd_controller_selected)
63 {
64 g_p_lcd_controller_selected->disable();
65 }
66 } void lcd_contoller_add(void)
{
s3c2440_lcd_contoller_add();
}

最新文章

  1. M端总结
  2. java web学习总结(十) -------------------HttpServletRequest对象
  3. idea转eclipse 设置注意。
  4. QThread
  5. tmp_table_size
  6. java动态加载类和静态加载类笔记
  7. 跟我一起学WCF(13)——WCF系列总结
  8. python socket 选项
  9. [JAVA]在linux中设置JDK环境,ZendStudio,Eclipse
  10. 【leetcode】Multiply Strings(middle)
  11. android开发设置dialog的高宽
  12. C# Winform 拖放操作
  13. PICT实现组合测试用例(一)
  14. C#_dropdownlist_1
  15. mysql 5.5 升级到 mysql 5.6
  16. SQL数据库知识二(Day 25)
  17. 关于Symfony2+nginx搭建过程总结
  18. 【搬运工】——初识Lua(转)
  19. 【学习】如何用jQuery获取iframe中的元素
  20. 关于C/S框架网单表绑定,查询

热门文章

  1. 关于指针与引用的差别——C++
  2. 把 DataTable 输出到 excel 文件
  3. classLoader双亲委托与类加载隔离
  4. Mac修改hosts方法
  5. 第20课 unique_ptr独占型智能指针
  6. iptables如何安全的清空规则
  7. 基于Kafka的实时计算引擎如何选择?Flink or Spark?
  8. centos 7 安装python3 &amp; pip3
  9. torch_03_二分类
  10. 多年老项目添加cocoapod管理之后的各种问题解决方案