歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 用QT210 LDD平台運行《Linux設備驅動開發詳解》實例

用QT210 LDD平台運行《Linux設備驅動開發詳解》實例

日期:2017/3/1 10:37:29   编辑:Linux編程

QT210 LDD開發平台采用Samsung S5PV210,基於CortexTM-A8,運行主頻1GHz,內置PowerVR SGX540高性能圖形引擎,最高可支持1080p@30fps硬件解碼視頻流暢播放,格式可為MPEG4, H.263, H.264等。

QT210默認運行Android 2.3,是LDD6410硬件軟件的全面升級。下面我們以3個case為例看看如何以QT210 LDD平台運行《Linux設備驅動開發詳解》的實例(http://www.linuxidc.com/Linux/2011-07/38211.htm)。

1. framebuffer測試程序

該測試程序在lcd上繪制r,g,b3個逐漸變化的彩帶,程序源代碼如下:

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