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

本文介绍了如何在QT210平台上运行《Linux设备驱动开发详解》的实例,包括framebuffer测试、key test程序和i2c读写操作。通过这些实例,展示了在QT210开发平台上进行Linux设备驱动开发的过程和步骤。
摘要由CSDN通过智能技术生成
 

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



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


1. framebuffer测试程序

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

  1. /* 
  2.  * LDD6410 framebuffer test programs 
  3.  * Copyright 2011 www.linuxdriver.cn 
  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.     
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值