天嵌 ARM开发社区

 找回密码
 注册
查看: 2628|回复: 4

tq2440附带的ov9650驱动ov9650.c和测试程序camera.c是按v4l2标准写的吗?

[复制链接]
xmkk 发表于 2013-12-30 10:38:29 | 显示全部楼层 |阅读模式
论坛上版主说是的,但是我看过测试程序和驱动源码后,觉得并不是那样,求大神详细解释一下,初学驱动编程,求指导!谢谢!!!
camera.c
  1. /*
  2. *   TQ2440 camera test program
  3. *
  4. *   preview : 320x240 overlay on 320x240 16bpp LCD
  5. *
  6. *   TFT LCD size : 320x240
  7. */
  8. #include <sys/time.h>
  9. #include <sys/types.h>
  10. #include <asm/types.h>
  11. #include <sys/stat.h>
  12. #include <fcntl.h>
  13. #include <sys/ioctl.h>
  14. #include <unistd.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <sys/mman.h>
  19. #include <errno.h>

  20. #include <linux/fs.h>
  21. #include <linux/kernel.h>
  22. #include "videodev.h"
  23. #include "videodev2.h"
  24. #include <linux/fb.h>

  25. #define PIXFMT_NUM                        5
  26. #define INPUT_NUM                         5
  27. #define CTRL_NUM                         100

  28. #define V4L2_DEV_NODE                        "/dev/camera"
  29. #define FB_DEV_NODE                        "/dev/fb/0"

  30. //typedef struct v4l2_input    V_INPUT;
  31. //typedef struct v4l2_format   V_FORMAT;
  32. //typedef struct v4l2_fmtdesc  V_FMTDESC;
  33. //typedef struct v4l2_queryctrl V_QRYCTRL;

  34. typedef struct fb_var_screeninfo F_VINFO;

  35. unsigned int x_lcd_size, y_lcd_size;

  36. static void v4l2_show_on_fb(int fd, char *fbmem, int frames)
  37. {
  38.         int i;
  39.         int ret;
  40.         char preview_buf[240*320*2];                // 2 byte per pixe
  41.        
  42.         while(1) {
  43.                         if ((ret = read (fd, &preview_buf, 240*320*2)) < 0) {
  44.                                 perror("read");
  45.                                 return;
  46.                         }
  47.         #if 1                        //for 320*240,640*480,800*480
  48.                         {
  49.                         int y;
  50.                         for (y = 0; y < 240; y++)
  51.                                 memcpy(fbmem + x_lcd_size*2*y, preview_buf + 320*2*y, 320*2);                //memcpy(dest,src,n)
  52.                         }
  53.         #else                        //for 240*320
  54.                         memcpy(fbmem, &preview_buf, 240*320*2);
  55.         #endif
  56.                         fflush(stdout);
  57.         }
  58.        
  59.         printf("\n");
  60. }

  61. static unsigned int fb_grab(int fd, char **fbmem)
  62. {
  63.         F_VINFO modeinfo;
  64.         unsigned int length;

  65. /*get the variable screen information*/
  66.         if (ioctl(fd, FBIOGET_VSCREENINFO, &modeinfo) < 0) {
  67.                 perror("FBIOGET_VSCREENINFO");
  68.                 exit (EXIT_FAILURE);
  69.         }
  70.         length = modeinfo.xres * modeinfo.yres * (modeinfo.bits_per_pixel >> 3);

  71.         x_lcd_size=modeinfo.xres;             //width of tft lcd
  72.         y_lcd_size=modeinfo.yres;             //height of tft lcd

  73.         printf("fb memory info=xres (%d) x yres (%d), %d bpp\n",
  74.                         modeinfo.xres, modeinfo.yres, modeinfo.bits_per_pixel);

  75.         *fbmem = mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  76.         if (*fbmem < 0) {
  77.                 perror("mmap()");
  78.                 length = 0;
  79.         }

  80.         return length;
  81. }

  82. static void fb_ungrab(char **fbmem, unsigned int length)
  83. {
  84.         if (*fbmem)
  85.                 munmap(*fbmem, length);
  86. }


  87. int main(int argc, char *argv[])
  88. {
  89.         int v4l2_fd = -1;
  90.         int fb_fd = -1;
  91.         char *fbmem = NULL;
  92.         unsigned int fb_length = 0;

  93.         int preview_frames = 180;
  94.         int tmp;

  95.         printf("TQ2440 Camera Test Program, Start !\n");
  96.         if (argc > 1) {
  97.                 if (sscanf(argv[1], "%d", &tmp) == 1)
  98.                         preview_frames = tmp;
  99.         }

  100.         v4l2_fd = open(V4L2_DEV_NODE, O_RDWR);
  101.         if (v4l2_fd < 0) {
  102.                 perror(V4L2_DEV_NODE);
  103.                 goto out;
  104.         }

  105.         fb_fd = open(FB_DEV_NODE, O_RDWR);
  106.         if (fb_fd < 0) {
  107.                 perror(FB_DEV_NODE);
  108.                 goto out;
  109.         }
  110.        
  111.         fflush(stdout);                //refresh the screen
  112.         if ((fb_length = fb_grab(fb_fd, &fbmem)) == 0)
  113.                 goto out;
  114.         memset(fbmem, 0, fb_length);

  115.         printf("Press Ctrl+C to stop !\n");
  116.         fflush(stdout);

  117.         v4l2_show_on_fb(v4l2_fd, fbmem, preview_frames);
  118.        
  119.         printf("\n");

  120. out:

  121.         if (v4l2_fd > 0)
  122.                 close(v4l2_fd);

  123.         fb_ungrab(&fbmem, fb_length);

  124.         return 0;
  125. }
复制代码



TQ-ZQL 发表于 2013-12-30 10:43:23 | 显示全部楼层
驱动不是v4l2的
 楼主| xmkk 发表于 2013-12-30 11:01:28 | 显示全部楼层

好吧,那为什么在ov9650.c  camera_test.c 里都有v4l相关的头文件呢?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
lzj8251 发表于 2015-8-26 18:25:44 | 显示全部楼层
请问你的摄像头能正常运行么
virgil2015 发表于 2016-1-20 21:21:28 | 显示全部楼层
按照天嵌给的这个OV9650的测试程序,是可以运行,但是天嵌给的驱动本身不支持V4L2,所以自己写OV9650的应用程序的时候是用不了V4L2的,你可以去查看一下天嵌OV9650的驱动,代码里面没有支持V4L2
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-29 18:05 , Processed in 1.046875 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表