Posted By

akiko on 06/05/12


Tagged

omap framebufferomapfb


Versions (?)

/dev/fb poking on OMAP


 / Published in: C
 

URL: dev.modmancer.com

demonstrates how to open, mmap, and communicate with /dev/fbN devices on OMAP. won't compile such as, but it's enough to give an insight in how-to.

  1. // written by Boris Posavec (akiko/agt), 2012.
  2. // this is just a snippet, not compilable without some other files from the project.
  3. // demonstrates how to open, mmap, and communicate with /dev/fbN devices
  4. // on OMAP.
  5.  
  6. #include "sys/omapfb.h"
  7.  
  8. int fb0_fd = 0;
  9. int fb1_fd = 0;
  10. #define TS_DEV0 "/dev/fb0"
  11. #define TS_DEV1 "/dev/fb1"
  12.  
  13. struct fb_fix_screeninfo fixinfo;
  14. struct fb_var_screeninfo varinfo;
  15. struct omapfb_mem_info meminfo;
  16. struct omapfb_plane_info planeinfo;
  17.  
  18. enum fbdev_t
  19. {
  20. FBDEV_0,
  21. FBDEV_1,
  22. };
  23.  
  24. int __read_varinfo(fbdev_t dev)
  25. {
  26. int fb = (dev == FBDEV_0 ? fb0_fd : fb1_fd);
  27. if (ioctl(fb, FBIOGET_VSCREENINFO, &varinfo) == -1)
  28. {
  29. LOG("error: %s\n", strerror(errno));
  30. return -1;
  31. }
  32. return 0;
  33. }
  34.  
  35. int __write_varinfo(fbdev_t dev)
  36. {
  37. int fb = (dev == FBDEV_0 ? fb0_fd : fb1_fd);
  38. if (ioctl(fb, FBIOPUT_VSCREENINFO, &varinfo) == -1)
  39. {
  40. LOG("error: %s\n", strerror(errno));
  41. return -1;
  42. }
  43. return 0;
  44. }
  45.  
  46. bool fb_init()
  47. {
  48. int res;
  49. fb0_fd = open(TS_DEV, O_RDWR);
  50. if (fb0_fd == -1)
  51. {
  52. LOG("Error: cannot open %s \n", TS_DEV);
  53. return false;
  54. }
  55.  
  56. res = ioctl(fb0_fd, OMAPFB_QUERY_MEM, &meminfo);
  57. if (res != 0)
  58. {
  59. LOG("Error: cannot query omap mem for %s, %d\n", TS_DEV, res);
  60. return false;
  61. }
  62. LOG("fb memsize: %d\n", meminfo.size);
  63.  
  64. // mmap it
  65. fb0 = (unsigned char*) mmap(NULL, meminfo.size, PROT_WRITE, MAP_SHARED, fb0_fd, 0);
  66. if (fb0 == MAP_FAILED)
  67. {
  68. LOG("Error: cannot map %s\n", TS_DEV0);
  69. return false;
  70. }
  71. LOG("%s mapped OK.\n", TS_DEV1);
  72.  
  73. // Setup overlay.
  74. fb1_fd = open(TS_DEV1, O_RDWR);
  75. if (fb1_fd == -1)
  76. {
  77. LOG("Error: cannot open %s \n", TS_DEV1);
  78. return false;
  79. }
  80.  
  81. res = ioctl(fb1_fd, OMAPFB_QUERY_MEM, &meminfo);
  82. if (res != 0)
  83. {
  84. LOG("Error: cannot query omap mem for %s, %d\n", TS_DEV1, res);
  85. return false;
  86. }
  87. LOG("fb memsize: %d\n", meminfo.size);
  88.  
  89. // mmap it
  90. fb1 = (unsigned char*) mmap(NULL, meminfo.size, PROT_WRITE, MAP_SHARED, fb1_fd, 0);
  91. if (fb1 == MAP_FAILED)
  92. {
  93. LOG("Error: cannot map %s\n", TS_DEV1);
  94. return false;
  95. }
  96. LOG("%s mapped OK.\n", TS_DEV1);
  97.  
  98. // Enable overlay
  99. ioctl(fb1_fd, OMAPFB_QUERY_PLANE, &planeinfo);
  100. fprintf(stderr, "x, y, w, h, chnout, enabled: %d %d %d %d %d %d\n", planeinfo.pos_x, planeinfo.pos_y, planeinfo.out_width, planeinfo.out_height, planeinfo.channel_out, planeinfo.enabled);
  101. planeinfo.enabled = 1;
  102. ioctl(fb1_fd, OMAPFB_SETUP_PLANE, &planeinfo);
  103.  
  104. // Enable overlaying, set white as chroma key color
  105. execute_shell_cmd("echo \"1\" > /sys/devices/platform/omapdss/manager0/alpha_blending_enabled");
  106. execute_shell_cmd("echo \"1\" > /sys/devices/platform/omapdss/manager0/trans_key_enabled");
  107. execute_shell_cmd("echo \"0xf81f\" > /sys/devices/platform/omapdss/manager0/trans_key_value");
  108.  
  109. // Rotate 180deg
  110. execute_shell_cmd("echo \"1\" > /sys/class/graphics/fb0/rotate"); // gui/input
  111. execute_shell_cmd("echo \"3\" > /sys/class/graphics/fb1/rotate"); // camera
  112.  
  113. // get current xres, yres
  114. __read_varinfo(FBDEV_0);
  115. xres = varinfo.xres;
  116. yres = varinfo.yres;
  117. bpp = varinfo.bits_per_pixel;
  118.  
  119. return true;
  120. }

Report this snippet  

You need to login to post a comment.