for OV5642

Dependencies:   EthernetInterface FATFileSystem GR-PEACH_video GraphicsFramework HttpServer_snapshot R_BSP mbed-rpc mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
RyoheiHagimoto
Date:
Fri May 13 10:15:34 2016 +0000
Parent:
14:212f66386982
Commit message:
for OV4652

Changed in this revision

camera_config.h Show annotated file Show diff for this revision Revisions of this file
i2c_setting.cpp Show annotated file Show diff for this revision Revisions of this file
i2c_setting.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera_config.h	Fri May 13 10:15:34 2016 +0000
@@ -0,0 +1,334 @@
+// Setting of Input Camera
+#ifndef NATIVE_CAMERA_CONFIG_H
+#define NATIVE_CAMERA_CONFIG_H
+
+#define NTSC    0
+#define CMOS    1
+#define INPUT_CAM    (CMOS)   /*0:NTSC  1:CMOS(OV5642) */
+
+#if (INPUT_CAM == NTSC)
+#else
+#define OV5642_INIT_TBL_NUM     318
+
+static const char * cam_init_tbl[OV5642_INIT_TBL_NUM] = {
+"Wr:78,03,31,03,93",
+"Wr:78,03,30,08,82",
+"Wr:78,03,30,17,7f",
+"Wr:78,03,30,18,fc",
+"Wr:78,03,38,10,c2",
+"Wr:78,03,36,15,f0",
+"Wr:78,03,30,00,00",
+"Wr:78,03,30,01,00",
+"Wr:78,03,30,02,00",
+"Wr:78,03,30,03,00",
+"Wr:78,03,30,00,f8",
+"Wr:78,03,30,01,48",
+"Wr:78,03,30,02,5c",
+"Wr:78,03,30,03,02",
+"Wr:78,03,30,04,07",
+"Wr:78,03,30,05,b7",
+"Wr:78,03,30,06,43",
+"Wr:78,03,30,07,37",
+"Wr:78,03,30,11,10",    // PLL 0x08->0x10  (24MHz clockで30fps)
+"Wr:78,03,30,10,10",
+"Wr:78,03,46,0c,22",
+"Wr:78,03,38,15,04"
+"Wr:78,03,37,0d,06",
+"Wr:78,03,37,0c,a0",
+"Wr:78,03,36,02,fc",
+"Wr:78,03,36,12,ff",
+"Wr:78,03,36,34,c0",
+"Wr:78,03,36,13,00",
+"Wr:78,03,36,05,7c",
+"Wr:78,03,36,21,09",
+"Wr:78,03,36,22,00",
+"Wr:78,03,36,04,40",
+"Wr:78,03,36,03,a7",
+"Wr:78,03,36,03,27",
+"Wr:78,03,40,00,21",
+"Wr:78,03,40,1d,02",
+"Wr:78,03,36,00,54",
+"Wr:78,03,36,05,04",
+"Wr:78,03,36,06,3f",
+"Wr:78,03,3c,01,00",
+"Wr:78,03,50,00,4f",
+"Wr:78,03,50,20,04",
+"Wr:78,03,51,81,79",
+"Wr:78,03,51,82,00",
+"Wr:78,03,51,85,22",
+"Wr:78,03,51,97,01",
+"Wr:78,03,50,01,ff",
+"Wr:78,03,55,00,0a",
+"Wr:78,03,55,04,00",
+"Wr:78,03,55,05,7f",
+"Wr:78,03,50,80,08",
+"Wr:78,03,30,0e,18",
+"Wr:78,03,46,10,00",
+"Wr:78,03,47,1d,05",
+"Wr:78,03,47,08,06",
+"Wr:78,03,37,10,10",
+"Wr:78,03,36,32,41",
+"Wr:78,03,37,02,40",
+"Wr:78,03,36,20,37",
+"Wr:78,03,36,31,01",
+"Wr:78,03,38,08,02",
+"Wr:78,03,38,09,90",    // 320->320+16
+"Wr:78,03,38,0a,01",
+"Wr:78,03,38,0b,f0",    // 480->480+16
+"Wr:78,03,38,0e,07",
+"Wr:78,03,38,0f,d0",
+"Wr:78,03,50,1f,00",
+"Wr:78,03,50,00,4f",
+"Wr:78,03,43,00,30",
+"Wr:78,03,35,03,07",
+"Wr:78,03,35,01,73",
+"Wr:78,03,35,02,80",
+"Wr:78,03,35,0b,00",
+"Wr:78,03,35,03,07",
+"Wr:78,03,38,24,11",
+"Wr:78,03,35,01,1e",
+"Wr:78,03,35,02,80",
+"Wr:78,03,35,0b,7f",
+"Wr:78,03,38,0c,0a",    //  H total pixels 3200->2630
+"Wr:78,03,38,0d,46",    //  H total pixels 3200->2630
+"Wr:78,03,38,0e,03",
+"Wr:78,03,38,0f,e8",
+"Wr:78,03,3a,0d,04",
+"Wr:78,03,3a,0e,03",
+"Wr:78,03,38,18,c1",
+"Wr:78,03,37,05,db",
+"Wr:78,03,37,0a,81",
+"Wr:78,03,38,01,80",
+"Wr:78,03,36,21,c7",
+"Wr:78,03,38,01,50",
+"Wr:78,03,38,03,08",
+"Wr:78,03,38,27,08",
+"Wr:78,03,38,10,c0",
+"Wr:78,03,38,04,05",
+"Wr:78,03,38,05,00",
+"Wr:78,03,56,82,05",
+"Wr:78,03,56,83,00",
+"Wr:78,03,38,06,03",
+"Wr:78,03,38,07,c0",
+"Wr:78,03,56,86,03",
+"Wr:78,03,56,87,c0",
+"Wr:78,03,3a,00,78",
+"Wr:78,03,3a,1a,04",
+"Wr:78,03,3a,13,30",
+"Wr:78,03,3a,18,00",
+"Wr:78,03,3a,19,7c",
+"Wr:78,03,3a,08,12",
+"Wr:78,03,3a,09,c0",
+"Wr:78,03,3a,0a,0f",
+"Wr:78,03,3a,0b,a0",
+"Wr:78,03,30,04,ff",
+"Wr:78,03,35,0c,07",
+"Wr:78,03,35,0d,d0",
+"Wr:78,03,35,00,00",
+"Wr:78,03,35,01,00",
+"Wr:78,03,35,02,00",
+"Wr:78,03,35,0a,00",
+"Wr:78,03,35,0b,00",
+"Wr:78,03,35,03,00",
+"Wr:78,03,52,8a,02",
+"Wr:78,03,52,8b,04",
+"Wr:78,03,52,8c,08",
+"Wr:78,03,52,8d,08",
+"Wr:78,03,52,8e,08",
+"Wr:78,03,52,8f,10",
+"Wr:78,03,52,90,10",
+"Wr:78,03,52,92,00",
+"Wr:78,03,52,93,02",
+"Wr:78,03,52,94,00",
+"Wr:78,03,52,95,02",
+"Wr:78,03,52,96,00",
+"Wr:78,03,52,97,02",
+"Wr:78,03,52,98,00",
+"Wr:78,03,52,99,02",
+"Wr:78,03,52,9a,00",
+"Wr:78,03,52,9b,02",
+"Wr:78,03,52,9c,00",
+"Wr:78,03,52,9d,02",
+"Wr:78,03,52,9e,00",
+"Wr:78,03,52,9f,02",
+"Wr:78,03,3a,0f,3c",
+"Wr:78,03,3a,10,30",
+"Wr:78,03,3a,1b,3c",
+"Wr:78,03,3a,1e,30",
+"Wr:78,03,3a,11,70",
+"Wr:78,03,3a,1f,10",
+"Wr:78,03,30,30,0b",
+"Wr:78,03,3a,02,00",
+"Wr:78,03,3a,03,7d",
+"Wr:78,03,3a,04,00",
+"Wr:78,03,3a,14,00",
+"Wr:78,03,3a,15,7d",
+"Wr:78,03,3a,16,00",
+"Wr:78,03,3a,08,09",
+"Wr:78,03,3a,09,60",
+"Wr:78,03,3a,0a,07",
+"Wr:78,03,3a,0b,d0",
+"Wr:78,03,3a,0d,08",
+"Wr:78,03,3a,0e,06",
+"Wr:78,03,51,93,70",
+"Wr:78,03,36,20,57",
+"Wr:78,03,37,03,98",
+"Wr:78,03,37,04,1c",
+"Wr:78,03,58,9b,04",
+"Wr:78,03,58,9a,c5",
+"Wr:78,03,52,8a,00",
+"Wr:78,03,52,8b,02",
+"Wr:78,03,52,8c,08",
+"Wr:78,03,52,8d,10",
+"Wr:78,03,52,8e,20",
+"Wr:78,03,52,8f,28",
+"Wr:78,03,52,90,30",
+"Wr:78,03,52,92,00",
+"Wr:78,03,52,93,00",
+"Wr:78,03,52,94,00",
+"Wr:78,03,52,95,02",
+"Wr:78,03,52,96,00",
+"Wr:78,03,52,97,08",
+"Wr:78,03,52,98,00",
+"Wr:78,03,52,99,10",
+"Wr:78,03,52,9a,00",
+"Wr:78,03,52,9b,20",
+"Wr:78,03,52,9c,00",
+"Wr:78,03,52,9d,28",
+"Wr:78,03,52,9e,00",
+"Wr:78,03,52,9f,30",
+"Wr:78,03,52,82,00",
+"Wr:78,03,53,00,00",
+"Wr:78,03,53,01,20",
+"Wr:78,03,53,02,00",
+"Wr:78,03,53,03,7c",
+"Wr:78,03,53,0c,00",
+"Wr:78,03,53,0d,0c",
+"Wr:78,03,53,0e,20",
+"Wr:78,03,53,0f,80",
+"Wr:78,03,53,10,20",
+"Wr:78,03,53,11,80",
+"Wr:78,03,53,08,20",
+"Wr:78,03,53,09,40",
+"Wr:78,03,53,04,00",
+"Wr:78,03,53,05,30",
+"Wr:78,03,53,06,00",
+"Wr:78,03,53,07,80",
+"Wr:78,03,53,14,08",
+"Wr:78,03,53,15,20",
+"Wr:78,03,53,19,30",
+"Wr:78,03,53,16,10",
+"Wr:78,03,53,17,08",
+"Wr:78,03,53,18,02",
+"Wr:78,03,53,80,01",
+"Wr:78,03,53,81,00",
+"Wr:78,03,53,82,00",
+"Wr:78,03,53,83,4e",
+"Wr:78,03,53,84,00",
+"Wr:78,03,53,85,0f",
+"Wr:78,03,53,86,00",
+"Wr:78,03,53,87,00",
+"Wr:78,03,53,88,01",
+"Wr:78,03,53,89,15",
+"Wr:78,03,53,8a,00",
+"Wr:78,03,53,8b,31",
+"Wr:78,03,53,8c,00",
+"Wr:78,03,53,8d,00",
+"Wr:78,03,53,8e,00",
+"Wr:78,03,53,8f,0f",
+"Wr:78,03,53,90,00",
+"Wr:78,03,53,91,ab",
+"Wr:78,03,53,92,00",
+"Wr:78,03,53,93,a2",
+"Wr:78,03,53,94,08",
+"Wr:78,03,54,80,14",
+"Wr:78,03,54,81,21",
+"Wr:78,03,54,82,36",
+"Wr:78,03,54,83,57",
+"Wr:78,03,54,84,65",
+"Wr:78,03,54,85,71",
+"Wr:78,03,54,86,7d",
+"Wr:78,03,54,87,87",
+"Wr:78,03,54,88,91",
+"Wr:78,03,54,89,9a",
+"Wr:78,03,54,8a,aa",
+"Wr:78,03,54,8b,b8",
+"Wr:78,03,54,8c,cd",
+"Wr:78,03,54,8d,dd",
+"Wr:78,03,54,8e,ea",
+"Wr:78,03,54,8f,10",
+"Wr:78,03,54,90,05",
+"Wr:78,03,54,91,00",
+"Wr:78,03,54,92,04",
+"Wr:78,03,54,93,20",
+"Wr:78,03,54,94,03",
+"Wr:78,03,54,95,60",
+"Wr:78,03,54,96,02",
+"Wr:78,03,54,97,b8",
+"Wr:78,03,54,98,02",
+"Wr:78,03,54,99,86",
+"Wr:78,03,54,9a,02",
+"Wr:78,03,54,9b,5b",
+"Wr:78,03,54,9c,02",
+"Wr:78,03,54,9d,3b",
+"Wr:78,03,54,9e,02",
+"Wr:78,03,54,9f,1c",
+"Wr:78,03,54,a0,02",
+"Wr:78,03,54,a1,04",
+"Wr:78,03,54,a2,01",
+"Wr:78,03,54,a3,ed",
+"Wr:78,03,54,a4,01",
+"Wr:78,03,54,a5,c5",
+"Wr:78,03,54,a6,01",
+"Wr:78,03,54,a7,a5",
+"Wr:78,03,54,a8,01",
+"Wr:78,03,54,a9,6c",
+"Wr:78,03,54,aa,01",
+"Wr:78,03,54,ab,41",
+"Wr:78,03,54,ac,01",
+"Wr:78,03,54,ad,20",
+"Wr:78,03,54,ae,00",
+"Wr:78,03,54,af,16",
+"Wr:78,03,34,06,00",
+"Wr:78,03,51,92,04",
+"Wr:78,03,51,91,f8",
+"Wr:78,03,51,93,70",
+"Wr:78,03,51,94,f0",
+"Wr:78,03,51,95,f0",
+"Wr:78,03,51,8d,3d",
+"Wr:78,03,51,8f,54",
+"Wr:78,03,51,8e,3d",
+"Wr:78,03,51,90,54",
+"Wr:78,03,51,8b,c0",
+"Wr:78,03,51,8c,bd",
+"Wr:78,03,51,87,18",
+"Wr:78,03,51,88,18",
+"Wr:78,03,51,89,6e",
+"Wr:78,03,51,8a,68",
+"Wr:78,03,51,86,1c",
+"Wr:78,03,51,81,50",
+"Wr:78,03,51,84,25",
+"Wr:78,03,51,82,11",
+"Wr:78,03,51,83,14",
+"Wr:78,03,51,84,25",
+"Wr:78,03,51,85,24",
+"Wr:78,03,50,25,82",
+"Wr:78,03,3a,0f,7e",
+"Wr:78,03,3a,10,72",
+"Wr:78,03,3a,1b,80",
+"Wr:78,03,3a,1e,70",
+"Wr:78,03,3a,11,d0",
+"Wr:78,03,3a,1f,40",
+"Wr:78,03,55,83,40",
+"Wr:78,03,55,84,40",
+"Wr:78,03,55,80,02",
+"Wr:78,03,36,33,07",
+"Wr:78,03,37,02,10",
+"Wr:78,03,37,03,b2",
+"Wr:78,03,37,04,18",
+"Wr:78,03,37,0b,40",
+"Wr:78,03,37,0d,02",
+"Wr:78,03,36,20,52",
+};
+#endif
+#endif  /* NATIVE_CAMERA_CONFIG_H */
--- a/i2c_setting.cpp	Tue Apr 19 02:22:08 2016 +0000
+++ b/i2c_setting.cpp	Fri May 13 10:15:34 2016 +0000
@@ -207,6 +207,7 @@
     return false;
 }
 
+
 #if(0) /* Please enable this line when performing the setting from the Terminal side. */
 Serial terminal(USBTX, USBRX);
 static char recv_term_buffer[I2C_SETTING_STR_BUF_SIZE];
--- a/i2c_setting.h	Tue Apr 19 02:22:08 2016 +0000
+++ b/i2c_setting.h	Fri May 13 10:15:34 2016 +0000
@@ -25,4 +25,5 @@
 
 extern bool i2c_setting_exe(char * buf);
 
+
 #endif
--- a/main.cpp	Tue Apr 19 02:22:08 2016 +0000
+++ b/main.cpp	Fri May 13 10:15:34 2016 +0000
@@ -8,6 +8,7 @@
 #include "RomRamFileSystem.h"
 #include "file_table.h"        //Binary data of web pages
 #include "i2c_setting.h"
+#include "camera_config.h"
 
 #define VIDEO_CVBS             (0)                 /* Analog  Video Signal */
 #define VIDEO_CMOS_CAMERA      (1)                 /* Digital Video Signal */
@@ -17,7 +18,7 @@
 
 /**** User Selection *********/
 /** Network setting **/
-#define USE_DHCP               (1)                 /* Select  0(static configuration) or 1(use DHCP) */
+#define USE_DHCP               (0)                 /* Select  0(static configuration) or 1(use DHCP) */
 #if (USE_DHCP == 0)
   #define IP_ADDRESS           ("192.168.0.2")     /* IP address      */
   #define SUBNET_MASK          ("255.255.255.0")   /* Subnet mask     */
@@ -46,12 +47,19 @@
 
 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
     in accordance with the frame buffer burst transfer mode. */
+#if (1) /* for OV4652 */
+#define PIXEL_HW               (640u)  /* VGA */
+#define PIXEL_VW               (480u)  /* VGA */
+#else
 #define PIXEL_HW               (320u)  /* QVGA */
 #define PIXEL_VW               (240u)  /* QVGA */
+#endif
 
 #define VIDEO_BUFFER_STRIDE    (((PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u)
 #define VIDEO_BUFFER_HEIGHT    (PIXEL_VW)
 
+#define OV5642_INIT_BUF_SIZE    17
+
 EthernetInterface network;
 RomRamFileSystem romramfs("romram");
 
@@ -64,6 +72,15 @@
 #endif
 static volatile int32_t vsync_count = 0;
 static volatile int32_t vfield_count = 1;
+#if (1) /* for OV5642 */
+#if defined(__ICCARM__)
+#pragma data_alignment=8
+static uint8_t JpegBuffer[2][1024 * 100]@ ".mirrorram";  //8 bytes aligned!;
+#pragma data_alignment=4
+#else
+static uint8_t JpegBuffer[2][1024 * 100]__attribute((section("NC_BSS"),aligned(8)));  //8 bytes aligned!;
+#endif
+#else /* for OV5642 */
 #if defined(__ICCARM__)
 #pragma data_alignment=8
 static uint8_t JpegBuffer[2][1024 * 50]@ ".mirrorram";  //8 bytes aligned!;
@@ -71,6 +88,7 @@
 #else
 static uint8_t JpegBuffer[2][1024 * 50]__attribute((section("NC_BSS"),aligned(8)));  //8 bytes aligned!;
 #endif
+#endif /* for OV5642 */
 static size_t jcu_encode_size[2];
 static int image_change = 0;
 JPEG_Converter Jcu;
@@ -80,6 +98,17 @@
 static int jcu_encoding = 0;
 static char i2c_setting_str_buf[I2C_SETTING_STR_BUF_SIZE];
 
+extern void analy_and_exe(char * buf);
+static void OV5642_Init(void) {
+    char camera_init_buffer[OV5642_INIT_BUF_SIZE];
+    int cnt;
+
+    for(cnt = 0; cnt < OV5642_INIT_TBL_NUM; cnt++) {
+        memcpy(&camera_init_buffer[0], cam_init_tbl[cnt], OV5642_INIT_BUF_SIZE);
+        i2c_setting_exe(&camera_init_buffer[0]);
+    }
+}
+
 static void JcuEncodeCallBackFunc(JPEG_Converter::jpeg_conv_error_t err_code) {
     jcu_buf_index_write_done = jcu_buf_index_write;
     image_change = 1;
@@ -150,6 +179,9 @@
     };
 #endif
 
+    /* Initialize OV5642 */
+    OV5642_Init();
+
     /* Create DisplayBase object */
     DisplayBase Display;
 
@@ -176,14 +208,27 @@
     ext_in_config.inp_endian_on  = DisplayBase::OFF;                      /* External input bit endian change on/off       */
     ext_in_config.inp_swap_on    = DisplayBase::OFF;                      /* External input B/R signal swap on/off         */
     ext_in_config.inp_vs_inv     = DisplayBase::SIG_POL_NOT_INVERTED;     /* External input DV_VSYNC inversion control     */
+#if (1) /* for OV4652 */
+    ext_in_config.inp_hs_inv     = DisplayBase::SIG_POL_NOT_INVERTED;     /* External input DV_HSYNC inversion control     */
+#else
     ext_in_config.inp_hs_inv     = DisplayBase::SIG_POL_INVERTED;         /* External input DV_HSYNC inversion control     */
-    ext_in_config.inp_f525_625   = DisplayBase::EXTIN_LINE_525;           /* Number of lines for BT.656 external input */
+#endif
+   ext_in_config.inp_f525_625   = DisplayBase::EXTIN_LINE_525;           /* Number of lines for BT.656 external input */
+#if (1) /* for OV4652 */
+    ext_in_config.inp_h_pos      = DisplayBase::EXTIN_H_POS_YCBYCR;       /* Y/Cb/Y/Cr data string start timing to Hsync reference */
+    ext_in_config.cap_vs_pos     = 5;                                     /* Capture start position from Vsync */
+    ext_in_config.cap_hs_pos     = 16;                                    /* Capture start position form Hsync */
+    ext_in_config.cap_width      = ((640u-16u));                          /* Capture width  */
+    ext_in_config.cap_height     = 468u;                                  /* Capture height Max 468[line]
+                                                                             Due to CMOS(MT9V111) output signal timing and VDC5 specification */
+#else
     ext_in_config.inp_h_pos      = DisplayBase::EXTIN_H_POS_CRYCBY;       /* Y/Cb/Y/Cr data string start timing to Hsync reference */
     ext_in_config.cap_vs_pos     = 6;                                     /* Capture start position from Vsync */
     ext_in_config.cap_hs_pos     = 150;                                   /* Capture start position form Hsync */
     ext_in_config.cap_width      = 640;                                   /* Capture width  */
     ext_in_config.cap_height     = 468u;                                  /* Capture height Max 468[line]
                                                                              Due to CMOS(MT9V111) output signal timing and VDC5 specification */
+#endif
     error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_EXT, &ext_in_config);
     if( error != DisplayBase::GRAPHICS_OK ) {
         printf("Line %d, error %d\n", __LINE__, error);