First release

Dependencies:   EthernetInterface HTTPServer TextLCD mbed-rpc mbed-rtos mbed

Sample code of section 5 in Oct 2014 issue of the Interface Magazine, published by CQ publishing in Japan. CQ出版社インターフェース誌 2014年10月号5章に掲載のサンプルコードです.

LPC1768にトラ技OV7670モジュールとサーボを接続したうえで,リモート操作可能なネットワーク・カメラにしています.このコードのうちカメラ制御部には,Sadaei Osakabe氏のコードを流用させていただいています.

また,次のHTMLファイルをダウンロードして,LPC1768のフラッシュメモリに置いてください.ネットワーク経由で,このHTMLにアクセスをします(ブラウザで開く). /media/uploads/smorioka/netcam.htm

Committer:
smorioka
Date:
Tue Aug 26 16:49:26 2014 +0000
Revision:
0:993f719c9352
Sample code of section 5 in Oct 2014 issue of the Interface Magazine, published by CQ publishing in Japan.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
smorioka 0:993f719c9352 1 // This code was written by Mr.Sadaei Osakabe.
smorioka 0:993f719c9352 2 // Original code is located at
smorioka 0:993f719c9352 3 // https://mbed.org/users/diasea/code/OV7670_with_AL422B_Color_Size_test/
smorioka 0:993f719c9352 4
smorioka 0:993f719c9352 5 // size register
smorioka 0:993f719c9352 6 #define REG_COM7 0x12 /* Control 7 */
smorioka 0:993f719c9352 7 #define REG_HSTART 0x17 /* Horiz start high bits */
smorioka 0:993f719c9352 8 #define REG_HSTOP 0x18 /* Horiz stop high bits */
smorioka 0:993f719c9352 9 #define REG_HREF 0x32 /* HREF pieces */
smorioka 0:993f719c9352 10 #define REG_VSTART 0x19 /* Vert start high bits */
smorioka 0:993f719c9352 11 #define REG_VSTOP 0x1a /* Vert stop high bits */
smorioka 0:993f719c9352 12 #define REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
smorioka 0:993f719c9352 13 #define REG_COM3 0x0c /* Control 3 */
smorioka 0:993f719c9352 14 #define REG_COM14 0x3e /* Control 14 */
smorioka 0:993f719c9352 15 #define REG_SCALING_XSC 0x70
smorioka 0:993f719c9352 16 #define REG_SCALING_YSC 0x71
smorioka 0:993f719c9352 17 #define REG_SCALING_DCWCTR 0x72
smorioka 0:993f719c9352 18 #define REG_SCALING_PCLK_DIV 0x73
smorioka 0:993f719c9352 19 #define REG_SCALING_PCLK_DELAY 0xa2
smorioka 0:993f719c9352 20
smorioka 0:993f719c9352 21 // VGA setting
smorioka 0:993f719c9352 22 #define COM7_VGA 0x00
smorioka 0:993f719c9352 23 #define HSTART_VGA 0x13
smorioka 0:993f719c9352 24 #define HSTOP_VGA 0x01
smorioka 0:993f719c9352 25 #define HREF_VGA 0x36 //0xb6 0x36
smorioka 0:993f719c9352 26 #define VSTART_VGA 0x02
smorioka 0:993f719c9352 27 #define VSTOP_VGA 0x7a
smorioka 0:993f719c9352 28 #define VREF_VGA 0x0a
smorioka 0:993f719c9352 29 #define COM3_VGA 0x00
smorioka 0:993f719c9352 30 #define COM14_VGA 0x00
smorioka 0:993f719c9352 31 #define SCALING_XSC_VGA 0x3a
smorioka 0:993f719c9352 32 #define SCALING_YSC_VGA 0x35
smorioka 0:993f719c9352 33 #define SCALING_DCWCTR_VGA 0x11
smorioka 0:993f719c9352 34 #define SCALING_PCLK_DIV_VGA 0xf0
smorioka 0:993f719c9352 35 #define SCALING_PCLK_DELAY_VGA 0x02
smorioka 0:993f719c9352 36
smorioka 0:993f719c9352 37 // QVGA setting
smorioka 0:993f719c9352 38 #define COM7_QVGA 0x00
smorioka 0:993f719c9352 39 #define HSTART_QVGA 0x16
smorioka 0:993f719c9352 40 #define HSTOP_QVGA 0x04
smorioka 0:993f719c9352 41 #define HREF_QVGA 0x00
smorioka 0:993f719c9352 42 #define VSTART_QVGA 0x02
smorioka 0:993f719c9352 43 #define VSTOP_QVGA 0x7a
smorioka 0:993f719c9352 44 #define VREF_QVGA 0x0a
smorioka 0:993f719c9352 45 #define COM3_QVGA 0x04
smorioka 0:993f719c9352 46 #define COM14_QVGA 0x19
smorioka 0:993f719c9352 47 #define SCALING_XSC_QVGA 0x3a
smorioka 0:993f719c9352 48 #define SCALING_YSC_QVGA 0x35
smorioka 0:993f719c9352 49 #define SCALING_DCWCTR_QVGA 0x11
smorioka 0:993f719c9352 50 #define SCALING_PCLK_DIV_QVGA 0xf1
smorioka 0:993f719c9352 51 #define SCALING_PCLK_DELAY_QVGA 0x02
smorioka 0:993f719c9352 52
smorioka 0:993f719c9352 53 // QQVGA setting
smorioka 0:993f719c9352 54 #define COM7_QQVGA 0x00
smorioka 0:993f719c9352 55 #define HSTART_QQVGA 0x16
smorioka 0:993f719c9352 56 #define HSTOP_QQVGA 0x04
smorioka 0:993f719c9352 57 #define HREF_QQVGA 0xa4 //0x24? 0xa4?
smorioka 0:993f719c9352 58 #define VSTART_QQVGA 0x02
smorioka 0:993f719c9352 59 #define VSTOP_QQVGA 0x7a
smorioka 0:993f719c9352 60 #define VREF_QQVGA 0x0a
smorioka 0:993f719c9352 61 #define COM3_QQVGA 0x04
smorioka 0:993f719c9352 62 #define COM14_QQVGA 0x1a
smorioka 0:993f719c9352 63 #define SCALING_XSC_QQVGA 0x3a
smorioka 0:993f719c9352 64 #define SCALING_YSC_QQVGA 0x35
smorioka 0:993f719c9352 65 #define SCALING_DCWCTR_QQVGA 0x22
smorioka 0:993f719c9352 66 #define SCALING_PCLK_DIV_QQVGA 0xf2
smorioka 0:993f719c9352 67 #define SCALING_PCLK_DELAY_QQVGA 0x02
smorioka 0:993f719c9352 68
smorioka 0:993f719c9352 69 // CIF setting no tested linux src 2.6.29-rc5 ov7670_soc.c
smorioka 0:993f719c9352 70 #define COM7_CIF 0x00
smorioka 0:993f719c9352 71 #define HSTART_CIF 0x15
smorioka 0:993f719c9352 72 #define HSTOP_CIF 0x0b
smorioka 0:993f719c9352 73 #define HREF_CIF 0xb6
smorioka 0:993f719c9352 74 #define VSTART_CIF 0x03
smorioka 0:993f719c9352 75 #define VSTOP_CIF 0x7b
smorioka 0:993f719c9352 76 #define VREF_CIF 0x02
smorioka 0:993f719c9352 77 #define COM3_CIF 0x08
smorioka 0:993f719c9352 78 #define COM14_CIF 0x11
smorioka 0:993f719c9352 79 #define SCALING_XSC_CIF 0x3a
smorioka 0:993f719c9352 80 #define SCALING_YSC_CIF 0x35
smorioka 0:993f719c9352 81 #define SCALING_DCWCTR_CIF 0x11
smorioka 0:993f719c9352 82 #define SCALING_PCLK_DIV_CIF 0xf1
smorioka 0:993f719c9352 83 #define SCALING_PCLK_DELAY_CIF 0x02
smorioka 0:993f719c9352 84
smorioka 0:993f719c9352 85 // QCIF setting no tested no tested linux src 2.6.29-rc5 ov7670_soc.c
smorioka 0:993f719c9352 86 #define COM7_QCIF 0x00
smorioka 0:993f719c9352 87 #define HSTART_QCIF 0x39
smorioka 0:993f719c9352 88 #define HSTOP_QCIF 0x03
smorioka 0:993f719c9352 89 #define HREF_QCIF 0x80
smorioka 0:993f719c9352 90 #define VSTART_QCIF 0x03
smorioka 0:993f719c9352 91 #define VSTOP_QCIF 0x7b
smorioka 0:993f719c9352 92 #define VREF_QCIF 0x02
smorioka 0:993f719c9352 93 #define COM3_QCIF 0x0c
smorioka 0:993f719c9352 94 #define COM14_QCIF 0x11
smorioka 0:993f719c9352 95 #define SCALING_XSC_QCIF 0x3a
smorioka 0:993f719c9352 96 #define SCALING_YSC_QCIF 0x35
smorioka 0:993f719c9352 97 #define SCALING_DCWCTR_QCIF 0x11
smorioka 0:993f719c9352 98 #define SCALING_PCLK_DIV_QCIF 0xf1
smorioka 0:993f719c9352 99 #define SCALING_PCLK_DELAY_QCIF 0x52
smorioka 0:993f719c9352 100
smorioka 0:993f719c9352 101 // YUV
smorioka 0:993f719c9352 102 #define REG_COM13 0x3d /* Control 13 */
smorioka 0:993f719c9352 103 #define REG_TSLB 0x3a /* lots of stuff */
smorioka 0:993f719c9352 104
smorioka 0:993f719c9352 105 #define COM7_YUV 0x00 /* YUV */
smorioka 0:993f719c9352 106 #define COM13_UV 0x00 /* U before V - w/TSLB */
smorioka 0:993f719c9352 107 #define COM13_UVSWAP 0x01 /* V before U - w/TSLB */
smorioka 0:993f719c9352 108 #define TSLB_VLAST 0x00 /* YUYV - see com13 */
smorioka 0:993f719c9352 109 #define TSLB_ULAST 0x00 /* YVYU - see com13 */
smorioka 0:993f719c9352 110 #define TSLB_YLAST 0x08 /* UYVY or VYUY - see com13 */
smorioka 0:993f719c9352 111
smorioka 0:993f719c9352 112 // RGB
smorioka 0:993f719c9352 113 #define COM7_RGB 0x04 /* bits 0 and 2 - RGB format */
smorioka 0:993f719c9352 114
smorioka 0:993f719c9352 115 // RGB444
smorioka 0:993f719c9352 116 #define REG_RGB444 0x8c /* RGB 444 control */
smorioka 0:993f719c9352 117 #define REG_COM15 0x40 /* Control 15 */
smorioka 0:993f719c9352 118
smorioka 0:993f719c9352 119 #define RGB444_ENABLE 0x02 /* Turn on RGB444, overrides 5x5 */
smorioka 0:993f719c9352 120 #define RGB444_XBGR 0x00
smorioka 0:993f719c9352 121 #define RGB444_BGRX 0x01 /* Empty nibble at end */
smorioka 0:993f719c9352 122 #define COM15_RGB444 0x10 /* RGB444 output */
smorioka 0:993f719c9352 123
smorioka 0:993f719c9352 124 // RGB555
smorioka 0:993f719c9352 125 #define RGB444_DISABLE 0x00 /* Turn off RGB444, overrides 5x5 */
smorioka 0:993f719c9352 126 #define COM15_RGB555 0x30 /* RGB555 output */
smorioka 0:993f719c9352 127
smorioka 0:993f719c9352 128 // RGB565
smorioka 0:993f719c9352 129 #define COM15_RGB565 0x10 /* RGB565 output */
smorioka 0:993f719c9352 130
smorioka 0:993f719c9352 131 // Bayer RGB
smorioka 0:993f719c9352 132 #define COM7_BAYER 0x01 /* Bayer format */
smorioka 0:993f719c9352 133 #define COM7_PBAYER 0x05 /* "Processed bayer" */
smorioka 0:993f719c9352 134
smorioka 0:993f719c9352 135
smorioka 0:993f719c9352 136 // data format
smorioka 0:993f719c9352 137 #define COM15_R10F0 0x00 /* Data range 10 to F0 */
smorioka 0:993f719c9352 138 #define COM15_R01FE 0x80 /* 01 to FE */
smorioka 0:993f719c9352 139 #define COM15_R00FF 0xc0 /* 00 to FF */
smorioka 0:993f719c9352 140
smorioka 0:993f719c9352 141 // Night mode, flicker, banding /
smorioka 0:993f719c9352 142 #define REG_COM11 0x3b /* Control 11 */
smorioka 0:993f719c9352 143 #define COM11_NIGHT 0x80 /* NIght mode enable */
smorioka 0:993f719c9352 144 #define COM11_NIGHT_MIN_RATE_1_1 0x00 /* Normal mode same */
smorioka 0:993f719c9352 145 #define COM11_NIGHT_MIN_RATE_1_2 0x20 /* Normal mode 1/2 */
smorioka 0:993f719c9352 146 #define COM11_NIGHT_MIN_RATE_1_4 0x40 /* Normal mode 1/4 */
smorioka 0:993f719c9352 147 #define COM11_NIGHT_MIN_RATE_1_8 0x60 /* Normal mode 1/5 */
smorioka 0:993f719c9352 148 #define COM11_HZAUTO_ON 0x10 /* Auto detect 50/60 Hz on */
smorioka 0:993f719c9352 149 #define COM11_HZAUTO_OFF 0x00 /* Auto detect 50/60 Hz off */
smorioka 0:993f719c9352 150 #define COM11_60HZ 0x00 /* Manual 60Hz select */
smorioka 0:993f719c9352 151 #define COM11_50HZ 0x08 /* Manual 50Hz select */
smorioka 0:993f719c9352 152 #define COM11_EXP 0x02
smorioka 0:993f719c9352 153
smorioka 0:993f719c9352 154 #define REG_MTX1 0x4f
smorioka 0:993f719c9352 155 #define REG_MTX2 0x50
smorioka 0:993f719c9352 156 #define REG_MTX3 0x51
smorioka 0:993f719c9352 157 #define REG_MTX4 0x52
smorioka 0:993f719c9352 158 #define REG_MTX5 0x53
smorioka 0:993f719c9352 159 #define REG_MTX6 0x54
smorioka 0:993f719c9352 160 #define REG_BRIGHT 0x55 /* Brightness */
smorioka 0:993f719c9352 161 #define REG_CONTRAS 0x56 /* Contrast control */
smorioka 0:993f719c9352 162 #define REG_CONTRAS_CENTER 0x57
smorioka 0:993f719c9352 163 #define REG_MTXS 0x58
smorioka 0:993f719c9352 164 #define REG_MANU 0x67
smorioka 0:993f719c9352 165 #define REG_MANV 0x68
smorioka 0:993f719c9352 166 #define REG_GFIX 0x69 /* Fix gain control */
smorioka 0:993f719c9352 167 #define REG_GGAIN 0x6a
smorioka 0:993f719c9352 168 #define REG_DBLV 0x6b
smorioka 0:993f719c9352 169
smorioka 0:993f719c9352 170 #define REG_COM9 0x14 // Control 9 - gain ceiling
smorioka 0:993f719c9352 171 #define COM9_AGC_2X 0x00
smorioka 0:993f719c9352 172 #define COM9_AGC_4X 0x10
smorioka 0:993f719c9352 173 #define COM9_AGC_8X 0x20
smorioka 0:993f719c9352 174 #define COM9_AGC_16X 0x30
smorioka 0:993f719c9352 175 #define COM9_AGC_32X 0x40
smorioka 0:993f719c9352 176 #define COM9_AGC_64X 0x50
smorioka 0:993f719c9352 177 #define COM9_AGC_128X 0x60
smorioka 0:993f719c9352 178 #define COM9_AGC_MASK 0x70
smorioka 0:993f719c9352 179 #define COM9_FREEZE 0x01
smorioka 0:993f719c9352 180 #define COM13_GAMMA 0x80 /* Gamma enable */
smorioka 0:993f719c9352 181 #define COM13_UVSAT 0x40 /* UV saturation auto adjustment */
smorioka 0:993f719c9352 182 #define REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
smorioka 0:993f719c9352 183 #define REG_BLUE 0x01 /* blue gain */
smorioka 0:993f719c9352 184 #define REG_RED 0x02 /* red gain */
smorioka 0:993f719c9352 185 #define REG_COM1 0x04 /* Control 1 */
smorioka 0:993f719c9352 186 #define COM1_CCIR656 0x40 /* CCIR656 enable */
smorioka 0:993f719c9352 187 #define REG_BAVE 0x05 /* U/B Average level */
smorioka 0:993f719c9352 188 #define REG_GbAVE 0x06 /* Y/Gb Average level */
smorioka 0:993f719c9352 189 #define REG_AECHH 0x07 /* AEC MS 5 bits */
smorioka 0:993f719c9352 190 #define REG_RAVE 0x08 /* V/R Average level */
smorioka 0:993f719c9352 191 #define REG_COM2 0x09 /* Control 2 */
smorioka 0:993f719c9352 192 #define COM2_SSLEEP 0x10 /* Soft sleep mode */
smorioka 0:993f719c9352 193 #define REG_PID 0x0a /* Product ID MSB */
smorioka 0:993f719c9352 194 #define REG_VER 0x0b /* Product ID LSB */
smorioka 0:993f719c9352 195 #define COM3_SWAP 0x40 /* Byte swap */
smorioka 0:993f719c9352 196 #define COM3_SCALEEN 0x08 /* Enable scaling */
smorioka 0:993f719c9352 197 #define COM3_DCWEN 0x04 /* Enable downsamp/crop/window */
smorioka 0:993f719c9352 198 #define REG_COM4 0x0d /* Control 4 */
smorioka 0:993f719c9352 199 #define REG_COM5 0x0e /* All "reserved" */
smorioka 0:993f719c9352 200 #define REG_COM6 0x0f /* Control 6 */
smorioka 0:993f719c9352 201 #define REG_AECH 0x10 /* More bits of AEC value */
smorioka 0:993f719c9352 202 #define REG_CLKRC 0x11 /* Clocl control */
smorioka 0:993f719c9352 203 #define CLK_EXT 0x40 /* Use external clock directly */
smorioka 0:993f719c9352 204 #define CLK_SCALE 0x3f /* Mask for internal clock scale */
smorioka 0:993f719c9352 205 #define COM7_RESET 0x80 /* Register reset */
smorioka 0:993f719c9352 206 #define COM7_FMT_MASK 0x38
smorioka 0:993f719c9352 207 #define COM7_FMT_VGA 0x00
smorioka 0:993f719c9352 208 #define COM7_FMT_CIF 0x20 /* CIF format */
smorioka 0:993f719c9352 209 #define COM7_FMT_QVGA 0x10 /* QVGA format */
smorioka 0:993f719c9352 210 #define COM7_FMT_QCIF 0x08 /* QCIF format */
smorioka 0:993f719c9352 211 #define REG_COM8 0x13 /* Control 8 */
smorioka 0:993f719c9352 212 #define COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
smorioka 0:993f719c9352 213 #define COM8_AECSTEP 0x40 /* Unlimited AEC step size */
smorioka 0:993f719c9352 214 #define COM8_BFILT 0x20 /* Band filter enable */
smorioka 0:993f719c9352 215 #define COM8_AGC 0x04 /* Auto gain enable */
smorioka 0:993f719c9352 216 #define COM8_AWB 0x02 /* White balance enable */
smorioka 0:993f719c9352 217 #define COM8_AEC 0x01 /* Auto exposure enable */
smorioka 0:993f719c9352 218 #define REG_COM9 0x14 /* Control 9 - gain ceiling */
smorioka 0:993f719c9352 219 #define REG_COM10 0x15 /* Control 10 */
smorioka 0:993f719c9352 220 #define COM10_HSYNC 0x40 /* HSYNC instead of HREF */
smorioka 0:993f719c9352 221 #define COM10_PCLK_HB 0x20 /* Suppress PCLK on horiz blank */
smorioka 0:993f719c9352 222 #define COM10_HREF_REV 0x08 /* Reverse HREF */
smorioka 0:993f719c9352 223 #define COM10_VS_LEAD 0x04 /* VSYNC on clock leading edge */
smorioka 0:993f719c9352 224 #define COM10_VS_NEG 0x02 /* VSYNC negative */
smorioka 0:993f719c9352 225 #define COM10_HS_NEG 0x01 /* HSYNC negative */
smorioka 0:993f719c9352 226 #define REG_PSHFT 0x1b /* Pixel delay after HREF */
smorioka 0:993f719c9352 227 #define REG_MIDH 0x1c /* Manuf. ID high */
smorioka 0:993f719c9352 228 #define REG_MIDL 0x1d /* Manuf. ID low */
smorioka 0:993f719c9352 229 #define REG_MVFP 0x1e /* Mirror / vflip */
smorioka 0:993f719c9352 230 #define MVFP_MIRROR 0x20 /* Mirror image */
smorioka 0:993f719c9352 231 #define MVFP_FLIP 0x10 /* Vertical flip */
smorioka 0:993f719c9352 232 #define REG_AEW 0x24 /* AGC upper limit */
smorioka 0:993f719c9352 233 #define REG_AEB 0x25 /* AGC lower limit */
smorioka 0:993f719c9352 234 #define REG_VPT 0x26 /* AGC/AEC fast mode op region */
smorioka 0:993f719c9352 235 #define REG_HSYST 0x30 /* HSYNC rising edge delay */
smorioka 0:993f719c9352 236 #define REG_HSYEN 0x31 /* HSYNC falling edge delay */
smorioka 0:993f719c9352 237 #define REG_COM12 0x3c /* Control 12 */
smorioka 0:993f719c9352 238 #define COM12_HREF 0x80 /* HREF always */
smorioka 0:993f719c9352 239 #define COM14_DCWEN 0x10 /* DCW/PCLK-scale enable */
smorioka 0:993f719c9352 240 #define REG_EDGE 0x3f /* Edge enhancement factor */
smorioka 0:993f719c9352 241 #define REG_COM16 0x41 /* Control 16 */
smorioka 0:993f719c9352 242 #define COM16_AWBGAIN 0x08 /* AWB gain enable */
smorioka 0:993f719c9352 243 #define REG_COM17 0x42 /* Control 17 */
smorioka 0:993f719c9352 244 #define COM17_AECWIN 0xc0 /* AEC window - must match COM4 */
smorioka 0:993f719c9352 245 #define COM17_CBAR 0x08 /* DSP Color bar */
smorioka 0:993f719c9352 246 #define REG_CMATRIX_BASE 0x4f
smorioka 0:993f719c9352 247 #define CMATRIX_LEN 6
smorioka 0:993f719c9352 248 #define REG_REG76 0x76 /* OV's name */
smorioka 0:993f719c9352 249 #define R76_BLKPCOR 0x80 /* Black pixel correction enable */
smorioka 0:993f719c9352 250 #define R76_WHTPCOR 0x40 /* White pixel correction enable */
smorioka 0:993f719c9352 251 #define REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
smorioka 0:993f719c9352 252 #define REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
smorioka 0:993f719c9352 253 #define REG_BD50MAX 0xa5 /* 50hz banding step limit */
smorioka 0:993f719c9352 254 #define REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
smorioka 0:993f719c9352 255 #define REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
smorioka 0:993f719c9352 256 #define REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
smorioka 0:993f719c9352 257 #define REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
smorioka 0:993f719c9352 258 #define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
smorioka 0:993f719c9352 259 #define REG_BD60MAX 0xab /* 60hz banding step limit */