LinxuS3C2440LCD driver test program

Source: Internet
Author: User
HOST: VM-RedHat9.0 Development Board: FL2440, linux-2.6.12arm-linux-gcc: 3.4.1 corresponding LCD device driver see: http://www.linuxidc.com/Linux/2011-09/42076.htm#include<unistd.h>#include<stdio.

VM-RedHat 9.0

Board: FL2440, linux-2.6.12

Arm-linux-gcc: 3.4.1

LCD device drivers see: http://www.linuxidc.com/Linux/2011-09/42076.htm

  1. # Include
  2. # Include
  3. # Include
  4. # Include
  5. # Include
  6. # Define RED_COLOR565 0x0F100
  7. # Define GREEN_COLOR565 0x007E0
  8. # Define BLUE_COLOR565 0x0001F
  9. IntMain (Void)
  10. {
  11. IntFd_fb = 0;
  12. StructFb_var_screeninfo vinfo;
  13. StructFb_fix_screeninfo finfo;
  14. Long IntScreen_size = 0;
  15. Short* Fbp565 = NULL;
  16. IntX = 0, y = 0;
  17. Fd_fb = open ("/Dev/fb0", O_RDWR );
  18. If(! Fd_fb)
  19. {
  20. Printf ("Error: cannot open framebuffer device. \ n");
  21. Exit (1 );
  22. }
  23. // Get fixed screen info
  24. If(Ioctl (fd_fb, FBIOGET_FSCREENINFO, & finfo ))
  25. {
  26. Printf ("Error reading fixed information. \ n");
  27. Exit (2 );
  28. }
  29. // Get variable screen info
  30. If(Ioctl (fd_fb, FBIOGET_VSCREENINFO, & vinfo ))
  31. {
  32. Printf ("Error reading variable information. \ n");
  33. Exit (3 );
  34. }
  35. // The size of the screen in bytes
  36. Screen_size = vinfo. xres * vinfo. yres * vinfo. bits_per_pixel/8;
  37. Printf ("% Dx % d, % dbpp, screen_size = % d \ n", Vinfo. xres, vinfo. yres, vinfo. bits_per_pixel, screen_size );
  38. // Map framebuffer to user memory
  39. Fbp565 = (Short*) Mmap (0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0 );
  40. If((Int) Fbp565 =-1)
  41. {
  42. Printf ("Error: failed to map framebuffer device to memory. \ n");
  43. Exit (4 );
  44. }
  45. If(Vinfo. bits_per_pixel = 16)
  46. {
  47. Printf ("16 bpp framebuffer \ n");
  48. // Red Screen
  49. Printf ("Red Screen \ n");
  50. For(Y = 0; y <vinfo. yres/3; y ++)
  51. {
  52. For(X = 0; x <vinfo. xres; x ++)
  53. {
  54. * (Fbp565 + y * vinfo. xres + x) = RED_COLOR565;
  55. }
  56. }
  57. // Green Screen
  58. Printf ("Green Screen \ n");
  59. For(Y = vinfo. yres/3; y <(vinfo. yres * 2)/3; y ++)
  60. {
  61. For(X = 0; x <vinfo. xres; x ++)
  62. {
  63. * (Fbp565 + y * vinfo. xres + x) = GREEN_COLOR565;
  64. }
  65. }
  66. // Blue Screen
  67. Printf ("Blue Screen \ n");
  68. For(Y = (vinfo. yres * 2)/3; y <vinfo. yres; y ++)
  69. {
  70. For(X = 0; x <vinfo. xres; x ++)
  71. {
  72. * (Fbp565 + y * vinfo. xres + x) = BLUE_COLOR565;
  73. }
  74. }
  75. }
  76. Else
  77. {
  78. Printf ("Warnning: bpp is not 16 \ n");
  79. }
  80. Munmap (fbp565, screen_size );
  81. Close (fd_fb );
  82. Return0;
  83. }
# Include <unistd. h> # include <stdio. h> # include <fcntl. h> # include <linux/fb. h> # include <sys/mman. h> # define RED_COLOR565 0x0F100 # define GREEN_COLOR565 highlight # define BLUE_COLOR565 0x0001Fint main (void) {int fd_fb = 0; struct implements vinfo; struct implements finfo; long int screen_size = 0; short * fbp565 = NULL; int x = 0, y = 0; fd_fb = open ("/dev/fb0", O_RDWR); if (! Fd_fb) {printf ("Error: cannot open framebuffer device. \ n "); exit (1) ;}// Get fixed screen info if (ioctl (fd_fb, FBIOGET_FSCREENINFO, & finfo) {printf (" Error reading fixed information. \ n "); exit (2);} // Get variable screen info if (ioctl (fd_fb, FBIOGET_VSCREENINFO, & vinfo) {printf (" Error reading variable information. \ n "); exit (3);} // the size of the screen in bytes screen_size = vinfo. xres * vinfo. yres * vinfo. bits_per_pixel/8; printf ("% dx % d, % dbpp, screen_size = % d \ n", vinfo. xres, vinfo. yres, vinfo. bits_per_pixel, screen_size); // map framebuffer to user memory fbp565 = (short *) mmap (0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0); if (int) fbp565 =-1) {printf ("Error: failed to map framebuffer device to memory. \ n "); exit (4);} if (vinfo. bits_per_pixel = 16) {printf ("16 bpp framebuffer \ n"); // Red Screen printf ("Red Screen \ n"); for (y = 0; y <vinfo. yres/3; y ++) {for (x = 0; x <vinfo. xres; x ++) {* (fbp565 + y * vinfo. xres + x) = RED_COLOR565 ;}// Green Screen printf ("Green Screen \ n"); for (y = vinfo. yres/3; y <(vinfo. yres * 2)/3; y ++) {for (x = 0; x <vinfo. xres; x ++) {* (fbp565 + y * vinfo. xres + x) = GREEN_COLOR565 ;}// Blue Screen printf ("Blue Screen \ n"); for (y = (vinfo. yres * 2)/3; y <vinfo. yres; y ++) {for (x = 0; x <vinfo. xres; x ++) {* (fbp565 + y * vinfo. xres + x) = BLUE_COLOR565 ;}} else {printf ("warnning: bpp is not 16 \ n");} munmap (fbp565, screen_size); close (fd_fb ); return 0 ;}

Test results: the colors from top to bottom are red, green, and blue, respectively.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.