用QT210 LDD平台运行《Linux设备驱动开发详解》实例


QT210 LDD开发平台采用Samsung S5PV210,基于CortexTM-A8,运行主频1GHz,内置PowerVR SGX540高性能图形引擎,最高可支持1080p@30fps硬件解码视频流畅播放,格式可为MPEG4, H.263, H.264等。

用QT210 LDD平台运行《Linux设备驱动开发详解》实例
 
用QT210 LDD平台运行《Linux设备驱动开发详解》实例

QT210默认运行Android 2.3,是LDD6410硬件软件的全面升级。下面我们以3个case为例看看如何以QT210 LDD平台运行《Linux设备驱动开发详解》的实例()。

1. framebuffer测试程序

该测试程序在lcd上绘制r,g,b3个逐渐变化的彩带,程序源代码如下:

  1. /* 
  2.  * LDD6410 framebuffer test programs 
  3.  * Copyright 2011 www.bkjia.com 
  4.  */  
  5. #include <unistd.h>   
  6. #include <stdlib.h>   
  7. #include <stdio.h>   
  8. #include <fcntl.h>   
  9. #include <linux/fb.h>   
  10. #include <sys/mman.h>   
  11.   
  12. int main()  
  13. {  
  14.     int fbfd = 0;  
  15.     struct fb_var_screeninfo vinfo;  
  16.     unsigned long screensize = 0;  
  17.     char *fbp = 0;  
  18.     int x = 0, y = 0;  
  19.     int i = 0;  
  20.   
  21.     // Open the file for reading and writing   
  22.     fbfd = open("/dev/graphics/fb0", O_RDWR);  
  23.     if (!fbfd) {  
  24.         printf("Error: cannot open framebuffer device.\n");  
  25.         exit(1);  
  26.     }  
  27.     printf("The framebuffer device was opened successfully.\n");  
  28.   
  29.     // Get variable screen information   
  30.     if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {  
  31.         printf("Error reading variable information.\n");  
  32.         exit(1);  
  33.     }  
  34.   
  35.     printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);  
  36.     if (vinfo.bits_per_pixel != 16 && vinfo.bits_per_pixel != 32) {  
  37.         printf("Error: not supported bits_per_pixel, it only supports 16/32 bit color\n");  
  38.     }  
  39.   
  40.     // Figure out the size of the screen in bytes   
  41.     screensize = vinfo.xres * vinfo.yres * (vinfo.bits_per_pixel / 8);  
  42.   
  43.     // Map the device to memory   
  44.     fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,  
  45.         fbfd, 0);  
  46.     if ((int)fbp == -1) {  
  47.         printf("Error: failed to map framebuffer device to memory.\n");  
  48.         exit(4);  
  49.     }  
  50.     printf("The framebuffer device was mapped to memory successfully.\n");  
  51.   
  52.     // Draw 3 rect with graduated RED/GREEN/BLUE   
  53.     for (i = 0; i < 3; i++) {  
  54.         for (y = i * (vinfo.yres / 3); y < (i + 1) * (vinfo.yres / 3); y++) {  
  55.             for (x = 0; x < vinfo.xres; x++) {  
  56.                 long location = x * 2 + y *  vinfo.xres * 2;  
  57.                 int r = 0, g = 0, b = 0;  
  58.   
  59.                 if (vinfo.bits_per_pixel == 16) {  
  60.                     unsigned short rgb;  
  61.   
  62.                     if (i == 0)  
  63.                         r = ((x * 1.0) / vinfo.xres) * 32;  
  64.                     if (i == 1)  
  65.                         g = ((x * 1.0) / vinfo.xres) * 64;  
  66.                     if (i == 2)  
  67.                         b = ((x * 1.0) / vinfo.xres) * 32;  
  68.   
  69.                     rgb = (r << 11) | (g << 5) | b;  
  70.                     *((unsigned short*)(fbp + location)) = rgb;  
  71.                 } else {  
  72.                     location = location * 2;  
  73.                     unsigned int rgb;  
  74.   
  75.                     if (i == 0)  
  76.                         r = ((x * 1.0) / vinfo.xres) * 256;  
  77.                     if (i == 1)  
  78.                         g = ((x * 1.0) / vinfo.xres) * 256;  
  79.                     if (i == 2)  
  80.                         b = ((x * 1.0) / vinfo.xres) * 256;  
  81.   
  82.                     rgb = (r << 16) | (g << 8) | b;  
  83.                     *((unsigned int*)(fbp + location)) = rgb;  
  84.                 }  
  85.             }  
  86.         }  
  87.     }  
  88.   
  89.     munmap(fbp, screensize);  
  90.     close(fbfd);  
  91.     return 0;  
  92. }  
  • 1
  • 2
  • 下一页

相关内容