1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunThe cpia2 driver 4*4882a593Smuzhiyun================ 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunAuthors: Peter Pregler <Peter_Pregler@email.com>, 7*4882a593SmuzhiyunScott J. Bertin <scottbertin@yahoo.com>, and 8*4882a593SmuzhiyunJarl Totland <Jarl.Totland@bdc.no> for the original cpia driver, which 9*4882a593Smuzhiyunthis one was modelled from. 10*4882a593Smuzhiyun 11*4882a593SmuzhiyunIntroduction 12*4882a593Smuzhiyun------------ 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunThis is a driver for STMicroelectronics's CPiA2 (second generation 15*4882a593SmuzhiyunColour Processor Interface ASIC) based cameras. This camera outputs an MJPEG 16*4882a593Smuzhiyunstream at up to vga size. It implements the Video4Linux interface as much as 17*4882a593Smuzhiyunpossible. Since the V4L interface does not support compressed formats, only 18*4882a593Smuzhiyunan mjpeg enabled application can be used with the camera. We have modified the 19*4882a593Smuzhiyungqcam application to view this stream. 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunThe driver is implemented as two kernel modules. The cpia2 module 22*4882a593Smuzhiyuncontains the camera functions and the V4L interface. The cpia2_usb module 23*4882a593Smuzhiyuncontains usb specific functions. The main reason for this was the size of the 24*4882a593Smuzhiyunmodule was getting out of hand, so I separated them. It is not likely that 25*4882a593Smuzhiyunthere will be a parallel port version. 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunFeatures 28*4882a593Smuzhiyun-------- 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun- Supports cameras with the Vision stv6410 (CIF) and stv6500 (VGA) cmos 31*4882a593Smuzhiyun sensors. I only have the vga sensor, so can't test the other. 32*4882a593Smuzhiyun- Image formats: VGA, QVGA, CIF, QCIF, and a number of sizes in between. 33*4882a593Smuzhiyun VGA and QVGA are the native image sizes for the VGA camera. CIF is done 34*4882a593Smuzhiyun in the coprocessor by scaling QVGA. All other sizes are done by clipping. 35*4882a593Smuzhiyun- Palette: YCrCb, compressed with MJPEG. 36*4882a593Smuzhiyun- Some compression parameters are settable. 37*4882a593Smuzhiyun- Sensor framerate is adjustable (up to 30 fps CIF, 15 fps VGA). 38*4882a593Smuzhiyun- Adjust brightness, color, contrast while streaming. 39*4882a593Smuzhiyun- Flicker control settable for 50 or 60 Hz mains frequency. 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunMaking and installing the stv672 driver modules 42*4882a593Smuzhiyun----------------------------------------------- 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunRequirements 45*4882a593Smuzhiyun~~~~~~~~~~~~ 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunVideo4Linux must be either compiled into the kernel or 48*4882a593Smuzhiyunavailable as a module. Video4Linux2 is automatically detected and made 49*4882a593Smuzhiyunavailable at compile time. 50*4882a593Smuzhiyun 51*4882a593SmuzhiyunSetup 52*4882a593Smuzhiyun~~~~~ 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunUse ``modprobe cpia2`` to load and ``modprobe -r cpia2`` to unload. This 55*4882a593Smuzhiyunmay be done automatically by your distribution. 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunDriver options 58*4882a593Smuzhiyun~~~~~~~~~~~~~~ 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun.. tabularcolumns:: |p{13ex}|L| 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun============== ======================================================== 64*4882a593SmuzhiyunOption Description 65*4882a593Smuzhiyun============== ======================================================== 66*4882a593Smuzhiyunvideo_nr video device to register (0=/dev/video0, etc) 67*4882a593Smuzhiyun range -1 to 64. default is -1 (first available) 68*4882a593Smuzhiyun If you have more than 1 camera, this MUST be -1. 69*4882a593Smuzhiyunbuffer_size Size for each frame buffer in bytes (default 68k) 70*4882a593Smuzhiyunnum_buffers Number of frame buffers (1-32, default 3) 71*4882a593Smuzhiyunalternate USB Alternate (2-7, default 7) 72*4882a593Smuzhiyunflicker_freq Frequency for flicker reduction(50 or 60, default 60) 73*4882a593Smuzhiyunflicker_mode 0 to disable, or 1 to enable flicker reduction. 74*4882a593Smuzhiyun (default 0). This is only effective if the camera 75*4882a593Smuzhiyun uses a stv0672 coprocessor. 76*4882a593Smuzhiyun============== ======================================================== 77*4882a593Smuzhiyun 78*4882a593SmuzhiyunSetting the options 79*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~ 80*4882a593Smuzhiyun 81*4882a593SmuzhiyunIf you are using modules, edit /etc/modules.conf and add an options 82*4882a593Smuzhiyunline like this:: 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun options cpia2 num_buffers=3 buffer_size=65535 85*4882a593Smuzhiyun 86*4882a593SmuzhiyunIf the driver is compiled into the kernel, at boot time specify them 87*4882a593Smuzhiyunlike this:: 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun cpia2.num_buffers=3 cpia2.buffer_size=65535 90*4882a593Smuzhiyun 91*4882a593SmuzhiyunWhat buffer size should I use? 92*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunThe maximum image size depends on the alternate you choose, and the 95*4882a593Smuzhiyunframe rate achieved by the camera. If the compression engine is able to 96*4882a593Smuzhiyunkeep up with the frame rate, the maximum image size is given by the table 97*4882a593Smuzhiyunbelow. 98*4882a593Smuzhiyun 99*4882a593SmuzhiyunThe compression engine starts out at maximum compression, and will 100*4882a593Smuzhiyunincrease image quality until it is close to the size in the table. As long 101*4882a593Smuzhiyunas the compression engine can keep up with the frame rate, after a short time 102*4882a593Smuzhiyunthe images will all be about the size in the table, regardless of resolution. 103*4882a593Smuzhiyun 104*4882a593SmuzhiyunAt low alternate settings, the compression engine may not be able to 105*4882a593Smuzhiyuncompress the image enough and will reduce the frame rate by producing larger 106*4882a593Smuzhiyunimages. 107*4882a593Smuzhiyun 108*4882a593SmuzhiyunThe default of 68k should be good for most users. This will handle 109*4882a593Smuzhiyunany alternate at frame rates down to 15fps. For lower frame rates, it may 110*4882a593Smuzhiyunbe necessary to increase the buffer size to avoid having frames dropped due 111*4882a593Smuzhiyunto insufficient space. 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun========== ========== ======== ===== 114*4882a593SmuzhiyunAlternate bytes/ms 15fps 30fps 115*4882a593Smuzhiyun========== ========== ======== ===== 116*4882a593Smuzhiyun 2 128 8533 4267 117*4882a593Smuzhiyun 3 384 25600 12800 118*4882a593Smuzhiyun 4 640 42667 21333 119*4882a593Smuzhiyun 5 768 51200 25600 120*4882a593Smuzhiyun 6 896 59733 29867 121*4882a593Smuzhiyun 7 1023 68200 34100 122*4882a593Smuzhiyun========== ========== ======== ===== 123*4882a593Smuzhiyun 124*4882a593SmuzhiyunTable: Image size(bytes) 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunHow many buffers should I use? 128*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 129*4882a593Smuzhiyun 130*4882a593SmuzhiyunFor normal streaming, 3 should give the best results. With only 2, 131*4882a593Smuzhiyunit is possible for the camera to finish sending one image just after a 132*4882a593Smuzhiyunprogram has started reading the other. If this happens, the driver must drop 133*4882a593Smuzhiyuna frame. The exception to this is if you have a heavily loaded machine. In 134*4882a593Smuzhiyunthis case use 2 buffers. You are probably not reading at the full frame rate. 135*4882a593SmuzhiyunIf the camera can send multiple images before a read finishes, it could 136*4882a593Smuzhiyunoverwrite the third buffer before the read finishes, leading to a corrupt 137*4882a593Smuzhiyunimage. Single and double buffering have extra checks to avoid overwriting. 138*4882a593Smuzhiyun 139*4882a593SmuzhiyunUsing the camera 140*4882a593Smuzhiyun~~~~~~~~~~~~~~~~ 141*4882a593Smuzhiyun 142*4882a593SmuzhiyunWe are providing a modified gqcam application to view the output. In 143*4882a593Smuzhiyunorder to avoid confusion, here it is called mview. There is also the qx5view 144*4882a593Smuzhiyunprogram which can also control the lights on the qx5 microscope. MJPEG Tools 145*4882a593Smuzhiyun(http://mjpeg.sourceforge.net) can also be used to record from the camera. 146