为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

摄像头驱动testcamera

2017-10-08 9页 doc 34KB 106阅读

用户头像

is_358746

暂无简介

举报
摄像头驱动testcamera摄像头驱动testcamera / created by ucdragon 2009-3-23 8:55 / include ltstdio.hgt include ltstdlib.hgt include ltstring.hgt include ltfcntl.hgt include lterrno.hgt include ltunistd.hgt include lttermios.hgt include ltlinux/fb.hgt include ltsys/mman.hgt include ltsys/ioctl...
摄像头驱动testcamera
摄像头驱动testcamera / created by ucdragon 2009-3-23 8:55 / include ltstdio.hgt include ltstdlib.hgt include ltstring.hgt include ltfcntl.hgt include lterrno.hgt include ltunistd.hgt include lttermios.hgt include ltlinux/fb.hgt include ltsys/mman.hgt include ltsys/ioctl.hgt include ltjpeglib.hgt define __user include quotvideodev.hquot include quotpxa_camera.hquot // define S3C2440A //define PXA27X //define SCCB_INIT define USER_I2C_INIT //use i2c initialize //define YCbCr_TO_RGB_TEST define FIXED_SOURCE_WIDTH 640 define FIXED_SOURCE_HEIGHT 480 define CAM_OV9655 //define CAM_OV9650 // static struct int palette char name optional_image_format VIDEO_PALETTE_YUV422P quotYCbCr422 planarquot VIDEO_PALETTE_RGB565 quotRGB565quot / VIDEO_PALETTE_RGB24 quotRGB24quot / define MAX_IMAGE_FORMAT sizeofoptional_image_format/sizeofoptional_image_format0 ifndef GLOBAL define GLOBAL //defined in jmorecfg.h endif static unsigned short image_width static unsigned short image_height static unsigned char image_buffer static unsigned short optimization 75 static unsigned short image_format static char image_file quotjpgfilequot static unsigned short file_index static unsigned short mmap_camera static unsigned short capture_video static unsigned short cpu_type __u32 Conv_YCbCr_Rgb__u8 y0 __u8 y1 __u8 cb0 __u8 cr0 // GLOBALvoid write_JPEG_file char filename int quality struct jpeg_compress_struct cinfo struct jpeg_error_mgr jerr / More stuff / FILE outfile / target file / JSAMPROW row_pointer1 / pointer to JSAMPLE rows / int row_stride / physical row width in image buffer / cinfo.err jpeg_std_errorampjerr / Now we can initialize the JPEG compression object. / jpeg_create_compressampcinfo if outfile fopenfilename quotwbquot NULL fprintfstderr quotcant open snquot filename exit1 jpeg_stdio_destampcinfo outfile cinfo.image_width image_width / image width and height in pixels / cinfo.image_height image_height cinfo.input_components 3 / of color components per pixel / cinfo.in_color_space JCS_RGB / colorspace of input image / jpeg_set_defaultsampcinfo jpeg_set_qualityampcinfo quality TRUE / limit to baseline-JPEG values / jpeg_start_compressampcinfo TRUE row_stride image_width 3 / JSAMPLEs per row in image_buffer / while cinfo.next_scanline lt cinfo.image_height row_pointer0 amp image_buffercinfo.next_scanline row_stride void jpeg_write_scanlinesampcinfo row_pointer 1 / Step 6: Finish compression / jpeg_finish_compressampcinfo / After finish_compress we can close the output file. / fcloseoutfile jpeg_destroy_compressampcinfo / And were done / // support RGB16 or YCbCr422 static void save_pictureunsigned char src int y x char name64 unsigned long rgb_data unsigned short w image_width unsigned short h image_height unsigned char src_y src unsigned char src_cb src_yimage_widthimage_height unsigned char src_cr src_cbimage_widthimage_height/2 int palette optional_image_formatimage_format.palette image_buffer mallocwh3 //RGB24 ifimage_bufferNULL printfquotallocate memory fail in saving picturenquot return ifpaletteVIDEO_PALETTE_RGB565 fory0 ylth y forx0 xltw x image_bufferywx3 __u16 srcywxamp0xf800gtgt8 image_bufferywx31 __u16 srcywxamp0x07e0gtgt3 image_bufferywx32 __u16 srcywxamp0x001fltlt3 else ifpaletteVIDEO_PALETTE_YUV422P fory0 ylth y forx0 xltw x rgb_data Conv_YCbCr_Rgbsrc_yywx src_yywx1 src_cbywxgtgt1 src_crywxgtgt1 image_bufferywx3 rgb_dataamp0xf800gtgt8 image_bufferywx31 rgb_dataamp0x07e0gtgt3 image_bufferywx32 rgb_dataamp0x001fltlt3 x image_bufferywx3 rgb_dataamp0xf8000000gtgt24 image_bufferywx31 rgb_dataamp0x07e00000gtgt19 image_bufferywx32 rgb_dataamp0x001f0000gtgt13 else printfquotunsupported input image format for saving jpeg filenquot freeimage_buffer return memsetname 0 sizeofname sprintfname quots04d.jpgquot image_file file_index write_JPEG_filename optimization freeimage_buffer // struct reg_set_s int val1 int val2 static int fb_xres static int fb_yres static int fb_bpp define YCbCrtoRYCbCr 1000Y 1371Cr-128/1000 define YCbCrtoGYCbCr 1000Y - 336Cb-128 - 698Cr-128/1000 define YCbCrtoBYCbCr 1000Y 1732Cb-128/1000 define minx1 x2 x1ltx2x1:x2 __u32 Conv_YCbCr_Rgb__u8 y0 __u8 y1 __u8 cb0 __u8 cr0 // bit order is // YCbCr Cr0 Y1 Cb0 Y0 RGBR1G1B1R0G0B0. int r0 g0 b0 r1 g1 b1 __u16 rgb0 rgb1 __u32 rgb if 1 // 4 frames/s 192MHz 12MHz 6 frames/s 450MHz 12MHz r0 YCbCrtoRy0 cb0 cr0 g0 YCbCrtoGy0 cb0 cr0 b0 YCbCrtoBy0 cb0 cr0 r1 YCbCrtoRy1 cb0 cr0 g1 YCbCrtoGy1 cb0 cr0 b1 YCbCrtoBy1 cb0 cr0 endif if r0gt255 r0 255 if r0lt0 r0 0 if g0gt255 g0 255 if g0lt0 g0 0 if b0gt255 b0 255 if b0lt0 b0 0 if r1gt255 r1 255 if r1lt0 r1 0 if g1gt255 g1 255 if g1lt0 g1 0 if b1gt255 b1 255 if b1lt0 b1 0 // 5:6:5 16bit format rgb0 __u16r0gtgt3ltlt11 __u16g0gtgt2ltlt5 __u16b0gtgt3ltlt0 //RGB565. rgb1 __u16r1gtgt3ltlt11 __u16g1gtgt2ltlt5 __u16b1gtgt3ltlt0 //RGB565. rgb rgb1ltlt16 rgb0 returnrgb static char yuv_interval 0 2 4 8 16 static void show_cam_imgvoid scr __u8 y_buf __u8 cb_buf __u8 cr_buf __u16 x y w h i f __u16 fb_buf __u16 scr __u32 rgb_data int palette optional_image_formatimage_format.palette fori0 ilt4 i //0123 ifimage_widthgtgtiltfb_xres f 0 w minimage_widthgtgti fb_xres h minimage_heightgtgti fb_yres break ifimage_heightgtgtiltfb_yres f 1 w minimage_widthgtgti fb_yres h minimage_heightgtgti fb_xres break ifigt4 return //printfquotdd ddnquot i f w h ifpaletteVIDEO_PALETTE_RGB565 iff fory0 ylth y forx0 xltw x2 fb_bufx __u16 y_bufxltlti fb_bufx1 __u16 y_bufx1ltlti fb_buf fb_xres __u16 y_buf image_widthltlti else fory0 ylth y forx0 xltw x2 fb_buffb_yres-x-1fb_xresy __u16 y_bufxltlti fb_buffb_yres-x-2fb_xresy __u16 y_bufx1ltlti __u16 y_buf image_widthltlti else ifpaletteVIDEO_PALETTE_YUV422P iff fory0 ylth y forx0 xltw x2 //calculate 2 times ifi fb_bufx Conv_YCbCr_Rgby_bufxltlti y_bufxltlti1 cb_bufxltltigtgt1 cr_bufxltltigtgt1 fb_bufx1 Conv_YCbCr_Rgby_bufxltltiyuv_intervali y_bufxltlti1yuv_intervali cb_bufxltltiyuv_intervaligtgt1 cr_bufxltltiyuv_intervaligtgt1 else rgb_data Conv_YCbCr_Rgby_bufxltlti y_bufxltlti1 cb_bufxltltigtgt1 cr_bufxltltigtgt1 fb_bufx rgb_data fb_bufx1 rgb_datagtgt16 fb_buf fb_xres y_buf image_widthltlti cb_buf image_widthltltigtgt1 cr_buf image_widthltltigtgt1 else fory0 ylth y forx0 xltw x2 ifi fb_buffb_yres-x-1fb_xresy Conv_YCbCr_Rgby_bufxltlti y_bufxltlti1 cb_bufxltltigtgt1 cr_bufxltltigtgt1 fb_buffb_yres-x-2fb_xresy Conv_YCbCr_Rgby_bufxltltiyuv_intervali y_bufxltlti1yuv_intervali cb_bufxltltiyuv_intervaligtgt1 cr_bufxltltiyuv_intervaligtgt1 else rgb_data Conv_YCbCr_Rgby_bufxltlti y_bufxltlti1 cb_bufxltltigtgt1 cr_bufxltltigtgt1 fb_buffb_yres-x-1fb_xresy rgb_data fb_buffb_yres-x-2fb_xresy fb_bufx1 rgb_datagtgt16 y_buf image_widthltlti cb_buf image_widthltltigtgt1 cr_buf image_widthltltigtgt1 ifdef YCbCr_TO_RGB_TEST include quot422jpeg.hquot static void test_ycbcr_to_rgbvoid scr __u8 buffer_y buffer_cb buffer_cr buffer_y __u8 c422jpeg buffer_cb buffer_y 240 320 buffer_cr buffer_cb 240 320 / 2 image_width 320//--czx image_height 240 printfquotTest YCbCr422 to RGB...nquot show_cam_imgscr buffer_y buffer_cb buffer_cr printfquotPress enter key to continue...nquot getchar image_width 0 image_height 0 else static void test_ycbcr_to_rgbvoid scr endif if definedUSER_I2C_INIT definedSCCB_INIT define CAMERA_I2C_ADDR 0x30 define CAMERA_MIDH 0x1c define CAMERA_MIDL 0x1d define CAMERA_PIDH 0x0a define CAMERA_PIDL 0x0b define CHIP_DELAY 0xFF struct i2c_reg_t int subaddr int value static struct i2c_reg_t camera_regs 0x12 0x80 // Camera Soft reset. Self cleared after reset. CHIP_DELAY 20 //change 0x110x81-gt0x80 0x150x02-gt0x20 0x3a0x01-gt0x0dhzh //0x120x80 0x110x810x6a0x3e0x3b0x090x130xe00x010x800x020x800x000x000x100x00 0x130xe50x390x430x380x120x370x000x350x910x0e0xa00x1e0x040xA80x80 0x120x400x040x000x0c0x040x0d0x800x180xc60x170x260x320xad0x030x00 0x1a0x3d0x190x010x3f0xa60x140x2e0x150x200x410x020x420x080x1b0x00 0x160x060x330xe20x340xbf0x960x040x3a0x000x8e0x000x3c0x770x8B0x06 0x940x880x950x880x400xc10x290x3f0x0f0x420x3d0x920x690x400x5C0xb9 0x5D0x960x5E0x100x590xc00x5A0xaf0x5B0x550x430xf00x440x100x450x68 0x460x960x470x600x480x800x5F0xe00x600x8c0x610x200xa50xd90xa40x74 0x8d0x020x130xe70x4f0x3a0x500x3d0x510x030x520x120x530x260x540x38 0x550x400x560x400x570x400x580x0d0x8C0x230x3E0x020xa90xb80xaa0x92 0xab0x0a0x8f0xdf0x900x000x910x000x9f0x000xa00x000x3A0x0d0x240x70 0x250x640x260xc30x2a0x000x2b0x000x6c0x400x6d0x300x6e0x4b0x6f0x60 0x700x700x710x700x720x700x730x700x740x600x750x600x760x500x770x48 0x780x3a0x790x2e0x7a0x280x7b0x220x7c0x040x7d0x070x7e0x100x7f0x28 0x800x360x810x440x820x520x830x600x840x6c0x850x780x860x8c0x870x9e 0x880xbb0x890xd20x8a0xe6 // 0x3a 0x0d // //0x3a 0x1d //for test //0x67 U //fixed value for U //0x68 V //fixed value for V //0x15 0x12 //PCLK reverse VSYNC negative //0x12 0x10 //QVGA //0x04 0x20 //QQVGA //0x15 0x20 //no PCLK when HREF is low static struct i2c_reg_t ov9655_vga_reg 0x120x80 0xFF 10 0xb50x0 0x350x0 0xa80xc1 0x3a0x0d//80 0x3d0x99 0x770x2 0x260x72 0x270x8 0x280x8 0x290x15 0x2c0x8 0xab0x4 0x6e0x0 0x6d0x55 0x00x32 0x100x7b 0xbb0xae 0x720x0 0x3e0x0c 0x740x3a 0x760x1 0x750x35 0x730x0 0xc70x80 0xc30x4e 0x330x0 0xa40x50 0xaa0x92 0xc20x1 0xc10xc8 0x1e0x4 0xa90xfa 0x0e0x61 0x390x57 0x0f0x42 0x240x3c 0x250x36 0x120x62 0x30x12 0x320xff 0x170x16 0x180x2 0x190x1 0x1a0x3d 0x360xfa 0x690x0a 0x8c0x8d 0xc00xaa 0x400xc0 0xc60x85 0xcb0xf0 0xcc0xd8 0x710xa0 0xa50x90 0x6f0x9e 0x420xc0 0x3f0x82 0x8a0x23 0x140x1a 0x3b0x0c 0x2d0x0 0x2e0x00 0x340x3d 0x410x40 0xc90xe0 0xca0xe8 0xcd0x93 0x7a0x20 0x7b0x1c 0x7c0x28 0x7d0x3c 0x7e0x5a 0x7f0x68 0x800x76 0x810x80 0x820x88 0x830x8f 0x840x96 0x850xa3 0x860xaf 0x870xc4 0x880xd7 0x890xe8 0x4f0x98 0x500x98 0x510x0 0x520x28 0x530x70 0x540x98 0x580x1a 0x900x86 0x910x84 0x9f0x75 0xa00x73 0x160x14 0x2a0x0 0x2b0x0 0xac0x80 0xad0x80 0xae0x80 0xaf0x80 0xb20xf2 0xb30x20 0xb40x20 0xb60xaf 0xb60xaf 0x40x3 0x50x2b 0x60x35 0x70x36 0x80x3b 0x2f0x35 0x4a0xea 0x4b0xe6 0x4c0xe6 0x4d0xe6 0x4e0xe6 0x700x0b 0xa60x40 0xbc0x4 0xbd0x1 0xbe0x3 0xbf0x1 0xbf0x1 0x430x14 0x440xf0 0x450x46 0x460x62 0x470x2a 0x480x3c 0x590x85 0x5a0xa9 0x5b0x64 0x5c0x84 0x5d0x53 0x5e0x0e 0x6c0x0c 0x6d0x55 0x6e0x0 0x6f0x9e 0x620x0 0x630x0 0x640x2 0x650x20 0x660x1 0x9d0x2 0x9e0x3 0x290x15 0xa90xef 0x110x0 0x6b0x1a 0x920x18 0x930x0 0xa20x4b 0xa30x4b 0x6a0x4b 0x130xe7 define CAMERA_OV9655_REGS sizeofov9655_vga_reg/sizeofov9655_vga_reg0 define CAMERA_REGS sizeofcamera_regs/sizeofcamera_regs0 include ltsys/time.hgt static void delay_mslong ms / struct timeval tvs tve struct timezone tzs tze ifms return gettimeofdayamptvs amptzs while1 long ds dus gettimeofdayamptve amptze dus tve.tv_usec - tvs.tv_usec ifduslt0 dus 1000000 tve.tv_sec-- ds tve.tv_sec - tvs.tv_sec ifds1000000dus/1000gtms break / fd_set rfds struct timeval tv FD_ZEROamprfds FD_SET0 amprfds tv.tv_sec 0 tv.tv_usec ms1000 select1 amprfds NULL NULL amptv endif ifdef USER_I2C_INIT static int i2c_writeint fd __u8 reg __u8 val int retries __u8 data2 data0 reg data1 val forretries5 retries retries-- ifwritefd data 22 return 0 delay_ms2 //printfquotwrite fail x xnquot data0 data1 return -1 static int i2c_readint fd __u8 reg __u8 val int retries forretries5 retries retries-- ifwritefd ampreg 11 ifreadfd val 11 return 0 delay_ms2 //printfquotread failnquot return -1 define I2C_SLAVE 0x0703 / Change slave address / static int camera_i2c_initvoid int i fd __u8 id4 //delay_ms100 printfquotopen i2c device...nquot fd openquot/dev/i2c/0quot O_RDWR iffdlt0 fd openquot/dev/misc/i2cquot O_RDWR iffdlt0 printfquotfail to open i2c adapter devicenquot return -1 ifioctlfd I2C_SLAVE CAMERA_I2C_ADDRlt0 printfquotfail to set i2c device slave addressnquot closefd return -1 printfquotset slave address to 0xx successnquot CAMERA_I2C_ADDR ifi2c_readfd CAMERA_MIDH idi2c_readfd CAMERA_MIDL id1 printfquotfail to get camera MIDnquot closefd return -1 printfquotapp::manufactory ID is 0x04xnquot id0ltlt8id1 i2c_readfd CAMERA_PIDH id2 i2c_readfd CAMERA_PIDL id3 printfquotapp::product ID is 0x04xnquot id2ltlt8id3 ifdef CAM_OV9655 fori0 iltCAMERA_OV9655_REGS i ifov9655_vga_regi.subaddrCHIP_DELAY delay_msov9655_vga_regi.value else ifi2c_writefd ov9655_vga_regi.subaddr ov9655_vga_regi.value printfquotwrite subaddr 0xx failnquot ov9655_vga_regi.subaddr //delay_ms2 //printfquotdnquot i endif ifdef CAM_OV9650 fori0 iltCAMER.
/
本文档为【摄像头驱动testcamera】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索