linux LCD 测试代码

转载地址:http://blog.csdn.net/huangjingbin/article/details/19544383
  1. *************************************************************************  
  2.   
  3.                                测试代码:  
  4.   
  5. *************************************************************************  
  6.   
  7. #include <stdio.h>  
  8. #include <stdlib.h>  
  9. #include <fcntl.h>  
  10. #include <sys/mman.h>  
  11. #include <linux/fb.h>  
  12.   
  13. #define COLOR_RED 0x000000FF  
  14. #define COLOR_GREEN 0x0000FF00  
  15. #define COLOR_BLUE 0x00FF0000  
  16.   
  17.   
  18. int fdfb = -1;  
  19.   
  20.   
  21. struct fb_fix_screeninfo fbfix = { 0 };  
  22. struct fb_var_screeninfo fbvar = { 0 };  
  23. long screensize = 0;  
  24.   
  25.   
  26. int *fb32 = NULL;  
  27.   
  28.   
  29. int x = 0;  
  30. int y = 0;  
  31. long location = 0;  
  32.   
  33.   
  34. int main(int argc, char **argv)  
  35. {  
  36. // open framebuffer device  
  37. fdfb = open( argv[1], O_RDWR );  
  38. if( 0 > fdfb ) {  
  39. printf("Failure to open framebuffer device: /dev/fb0 !\n");  
  40. exit( -1 );  
  41. }  
  42. printf("Success to open framebuffer device: /dev/fb0 !\n");  
  43.   
  44.   
  45. // get fixed screen information  
  46. if( ioctl( fdfb, FBIOGET_FSCREENINFO, &fbfix ) ) {  
  47. printf("Failure to get fixed screen information !\n");  
  48. exit( -2 );  
  49. }  
  50. printf("Success to get fixed screen information !\n");  
  51.   
  52.   
  53. // get varible screen information  
  54. if( ioctl( fdfb, FBIOGET_VSCREENINFO, &fbvar ) ) {  
  55. printf("Failure to get varible screen information !\n");  
  56. exit( -3 );  
  57. }  
  58. printf("Success to get varible screen information !\n");  
  59.   
  60.   
  61. // calculate the number of bytes for screen size  
  62. screensize = fbvar.xres * fbvar.yres * ( fbvar.bits_per_pixel / 8 );  
  63. printf("sceeninfo.xres = %d, screeninfo.yres = %d, screeninfo.bits_per_pixel = %dbpp, screensize = %d !\n", fbvar.xres, fbvar.yres, fbvar.bits_per_pixel, screensize);  
  64.   
  65.   
  66. // mmap framebuffer to process memory space  
  67. fb32 = (int *)mmap( 0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fdfb, 0 );  
  68. if( NULL == fb32 ) {  
  69. printf("Failure to map framebuffer device memory to process's memory !\n");  
  70. exit( -4 );  
  71. }  
  72. printf("Success to map framebuffer device memory to process's memory !\n");  
  73.   
  74.   
  75. // draw pixel  
  76. if( 8 == fbvar.bits_per_pixel ) {  
  77. printf("Starting 8 bpp framebuffer test...\n");  
  78. }  
  79. else if( 16 == fbvar.bits_per_pixel ) {  
  80. printf("Starting 16 bpp framebuffer test...\n");  
  81.   
  82.   
  83. }  
  84. else if( 24 == fbvar.bits_per_pixel ) {  
  85. printf("Starting 24 bpp framebuffer test...\n");  
  86. }  
  87. else {  
  88. printf("Supporting 32 bpp !\n");  
  89. // draw red color area  
  90. printf("Starting to show RED area !\n");  
  91. for( y = 0; y < fbvar.yres / 3; y++ ) {  
  92. for( x = 0; x < fbvar.xres; x++ ) {  
  93. *( fb32 + y * fbvar.xres + x ) = COLOR_RED;  
  94. }  
  95. }  
  96.   
  97.   
  98. // draw green color area  
  99. printf("Starting to show GREEN area !\n");  
  100. for( y = ( fbvar.yres / 3 ); y < ( fbvar.yres * 2 / 3); y++ ) {  
  101. for( x = 0; x < fbvar.xres; x++ ) {  
  102. *( fb32 + y * fbvar.xres + x ) = COLOR_GREEN;  
  103. }  
  104. }  
  105.   
  106.   
  107. // draw blue color area   
  108. printf("Starting to show BLUE area !\n");  
  109. for( y = ( fbvar.yres * 2 / 3 ); y < fbvar.yres; y++ ) {  
  110. for( x = 0; x < fbvar.xres; x++ ) {  
  111. *( fb32 + y * fbvar.xres + x ) = COLOR_BLUE;  
  112. }  
  113. }  
  114. }  
  115.   
  116.   
  117. // unmap framebuffer memory  
  118. munmap( fb32, screensize );  
  119.   
  120.   
  121. printf("Finished to demo to operate framebuffer !\n");  
  122.   
  123.   
  124. // close device handle  
  125. close( fdfb );  
  126.   
  127.   
  128. return 0;  

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值