移植usb-camera(ZC0301PLH)

 linux3.6.6移植usb-camera(ZC0301PLH)

分类: linux linux-kernel移植 3.6.6 linux-kernel移植 kernel-3.6.6 camera   294人阅读  评论(0)  收藏 举报

//--------------------------------------------------------------------------------------------

// 作者:longtian635241([email protected]

// 论坛ID:idea6410

// 版权:idea6410

// 平台:友坚idea6410开发板

// 发布日期:2012-11-22

// 最后修改:2012-11-22

//

//----------------------------------------------------------------------------------------------

 

1、因为内核已经支持这款usbcamera所以只需配置即可!

  1. Device Drivers --->
  2. <*> Multimedia support --->
  3. [*]   Cameras/video grabbers support 
  4. [*]   Video capture adapters  --->
  5. [*] V4L USB devices --->
  6. <*> USB Video Class (UVC)
  7. [*] UVC input events device support
  8. [*] GSPCA based webcams --->
  9. <*>   ZC3XX USB Camera Driver

    插入USB摄像头(我使用的UVC摄像头),会提示:

     

    usb 1-1: new full-speed USB device number 7 using s3c2410-ohci
    usb 1-1: New USB device found, idVendor=0ac8, idProduct=303b
    usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    usb 1-1: Product: PC Camera
    usb 1-1: Manufacturer: Vimicro Corp.
    gspca_main: gspca_zc3xx-2.14.0 probing 0ac8:303b
    input: gspca_zc3xx as /devices/platform/s3c2410-ohci/usb1/1-1/input/input3

    查看设备:

    [root@urbetter /]# ls dev/video0 
    dev/video0

    2、测试:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>

    #include <getopt.h>           

    #include <fcntl.h>             
    #include <unistd.h>
    #include <errno.h>
    #include <malloc.h>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <sys/time.h>
    #include <sys/mman.h>
    #include <sys/ioctl.h>

    #include <asm/types.h>         
    #include <linux/videodev2.h>

    #define CLEAR(x) memset (&(x), 0, sizeof (x))

    struct buffer {
            void *                  start;
            size_t                  length;
    };

    static char *           dev_name        = "/dev/video0";//这个的根据你查看到的设备好修改为你的!
    static int              fd              = -1;
    struct buffer *         buffers         = NULL;

    FILE *file_fd;
    static unsigned long file_length;
    static unsigned char *file_name;

    int main (int argc,char ** argv)
    {
    struct v4l2_capability cap; 
    struct v4l2_format fmt;

    file_fd = fopen("test.jpg", "w");

    fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0);

    ioctl (fd, VIDIOC_QUERYCAP, &cap);

    CLEAR (fmt);
    fmt.type                = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    fmt.fmt.pix.width       = 640; 
    fmt.fmt.pix.height      = 480;
    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
    fmt.fmt.pix.field       = V4L2_FIELD_INTERLACED;
    ioctl (fd, VIDIOC_S_FMT, &fmt);

    file_length = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;

    buffers = calloc (1, sizeof (*buffers));

    buffers[0].length = file_length;
    buffers[0].start = malloc (file_length);

    for (;;) 
    {
       fd_set fds;
       struct timeval tv;
       int r;

       FD_ZERO (&fds);
       FD_SET (fd, &fds);

       /* Timeout. */
       tv.tv_sec = 3;
       tv.tv_usec = 0;

       r = select (fd + 1, &fds, NULL, NULL, &tv);

       if (-1 == r) {
        if (EINTR == errno)
         continue;
        printf ("select");
                            }

       if (0 == r) {
        fprintf (stderr, "select timeout\n");
        exit (EXIT_FAILURE);
                            }

       if (read (fd, buffers[0].start, buffers[0].length))
       break;
    }

    fwrite(buffers[0].start, buffers[0].length, 1, file_fd);

    free (buffers[0].start);
    close (fd);
    fclose (file_fd);
    exit (EXIT_SUCCESS);
    return 0;
    }

    编译:

    # arm-linux-gcc usb_camera.c -o usb_camera

    拷贝到文件系统中运行即可,在当前目录下就能看到test.jpg的图片!

你可能感兴趣的:(linux,Camera,3.6.6,linux-kernel移植,linux-kernel移植,kernel-3.6.6)