智也 大野 / Mbed 2 deprecated SDFilesystem

Dependencies:   mbed PowerControl SDFileSystem

Fork of SDFilesystem by 智也 大野

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HeptaCamera.h Source File

HeptaCamera.h

00001 #define BITMAPFILE
00002 #undef BAYERBITMAPFILE
00003 #undef HEXFILE
00004 #undef COLORBAR
00005 #include <algorithm>
00006 
00007 #ifndef MBED_HEPTACAMERA_H
00008 #define MBED_HEPTACAMERA_H
00009 #include "mbed.h"
00010 
00011 // size register
00012 #define REG_COM7                    0x12    /* Control 7 */
00013 #define REG_HSTART                  0x17    /* Horiz start high bits */
00014 #define REG_HSTOP                   0x18    /* Horiz stop high bits */
00015 #define REG_HREF                    0x32    /* HREF pieces */
00016 #define REG_VSTART                  0x19    /* Vert start high bits */
00017 #define REG_VSTOP                   0x1a    /* Vert stop high bits */
00018 #define REG_VREF                    0x03    /* Pieces of GAIN, VSTART, VSTOP */
00019 #define REG_COM3                    0x0c    /* Control 3 */
00020 #define REG_COM14                   0x3e    /* Control 14 */
00021 #define REG_SCALING_XSC             0x70
00022 #define REG_SCALING_YSC             0x71
00023 #define REG_SCALING_DCWCTR          0x72
00024 #define REG_SCALING_PCLK_DIV        0x73
00025 #define REG_SCALING_PCLK_DELAY      0xa2
00026 
00027 // VGA setting
00028 #define COM7_VGA                    0x00
00029 #define HSTART_VGA                  0x13
00030 #define HSTOP_VGA                   0x01
00031 #define HREF_VGA                    0x36 //0xb6 0x36
00032 #define VSTART_VGA                  0x02
00033 #define VSTOP_VGA                   0x7a
00034 #define VREF_VGA                    0x0a
00035 #define COM3_VGA                    0x00
00036 #define COM14_VGA                   0x00
00037 #define SCALING_XSC_VGA             0x3a
00038 #define SCALING_YSC_VGA             0x35
00039 #define SCALING_DCWCTR_VGA          0x11
00040 #define SCALING_PCLK_DIV_VGA        0xf0
00041 #define SCALING_PCLK_DELAY_VGA      0x02
00042 
00043 // QVGA setting
00044 #define COM7_QVGA                   0x00
00045 #define HSTART_QVGA                 0x16
00046 #define HSTOP_QVGA                  0x04
00047 #define HREF_QVGA                   0x00
00048 #define VSTART_QVGA                 0x02
00049 #define VSTOP_QVGA                  0x7a
00050 #define VREF_QVGA                   0x0a
00051 #define COM3_QVGA                   0x04
00052 #define COM14_QVGA                  0x19
00053 #define SCALING_XSC_QVGA            0x3a
00054 #define SCALING_YSC_QVGA            0x35
00055 #define SCALING_DCWCTR_QVGA         0x11
00056 #define SCALING_PCLK_DIV_QVGA       0xf1
00057 #define SCALING_PCLK_DELAY_QVGA     0x02
00058 
00059 // QQVGA setting
00060 #define COM7_QQVGA                  0x00
00061 #define HSTART_QQVGA                0x16
00062 #define HSTOP_QQVGA                 0x04
00063 #define HREF_QQVGA                  0xa4  //0x24? 0xa4? 
00064 #define VSTART_QQVGA                0x02
00065 #define VSTOP_QQVGA                 0x7a
00066 #define VREF_QQVGA                  0x0a
00067 #define COM3_QQVGA                  0x04
00068 #define COM14_QQVGA                 0x1a
00069 #define SCALING_XSC_QQVGA           0x3a
00070 #define SCALING_YSC_QQVGA           0x35
00071 #define SCALING_DCWCTR_QQVGA        0x22
00072 #define SCALING_PCLK_DIV_QQVGA      0xf2
00073 #define SCALING_PCLK_DELAY_QQVGA    0x02
00074 
00075 // CIF setting no tested linux src 2.6.29-rc5 ov7670_soc.c
00076 #define COM7_CIF                    0x00
00077 #define HSTART_CIF                  0x15
00078 #define HSTOP_CIF                   0x0b
00079 #define HREF_CIF                    0xb6
00080 #define VSTART_CIF                  0x03
00081 #define VSTOP_CIF                   0x7b
00082 #define VREF_CIF                    0x02
00083 #define COM3_CIF                    0x08
00084 #define COM14_CIF                   0x11
00085 #define SCALING_XSC_CIF             0x3a
00086 #define SCALING_YSC_CIF             0x35
00087 #define SCALING_DCWCTR_CIF          0x11
00088 #define SCALING_PCLK_DIV_CIF        0xf1
00089 #define SCALING_PCLK_DELAY_CIF      0x02
00090 
00091 // QCIF setting no tested no tested linux src 2.6.29-rc5 ov7670_soc.c
00092 #define COM7_QCIF                   0x00
00093 #define HSTART_QCIF                 0x39
00094 #define HSTOP_QCIF                  0x03
00095 #define HREF_QCIF                   0x80
00096 #define VSTART_QCIF                 0x03
00097 #define VSTOP_QCIF                  0x7b
00098 #define VREF_QCIF                   0x02
00099 #define COM3_QCIF                   0x0c
00100 #define COM14_QCIF                  0x11
00101 #define SCALING_XSC_QCIF            0x3a
00102 #define SCALING_YSC_QCIF            0x35
00103 #define SCALING_DCWCTR_QCIF         0x11
00104 #define SCALING_PCLK_DIV_QCIF       0xf1
00105 #define SCALING_PCLK_DELAY_QCIF     0x52
00106 
00107 // YUV
00108 #define REG_COM13                   0x3d    /* Control 13 */
00109 #define REG_TSLB                    0x3a    /* lots of stuff */
00110 
00111 #define COM7_YUV                    0x00    /* YUV */
00112 #define COM13_UV                    0x00    /* U before V - w/TSLB */
00113 #define COM13_UVSWAP                0x01    /* V before U - w/TSLB */
00114 #define TSLB_VLAST                  0x00    /* YUYV  - see com13 */
00115 #define TSLB_ULAST                  0x00    /* YVYU  - see com13 */
00116 #define TSLB_YLAST                  0x08    /* UYVY or VYUY - see com13 */
00117 
00118 // RGB
00119 #define COM7_RGB                    0x04    /* bits 0 and 2 - RGB format */
00120 
00121 // RGB444
00122 #define REG_RGB444                  0x8c    /* RGB 444 control */
00123 #define REG_COM15                   0x40    /* Control 15 */
00124 
00125 #define RGB444_ENABLE               0x02    /* Turn on RGB444, overrides 5x5 */
00126 #define RGB444_XBGR                 0x00
00127 #define RGB444_BGRX                 0x01    /* Empty nibble at end */
00128 #define COM15_RGB444                0x10    /* RGB444 output */
00129 
00130 // RGB555
00131 #define RGB444_DISABLE              0x00    /* Turn off RGB444, overrides 5x5 */
00132 #define COM15_RGB555                0x30    /* RGB555 output */
00133 
00134 // RGB565
00135 #define COM15_RGB565                0x10    /* RGB565 output */
00136 
00137 // Bayer RGB
00138 #define COM7_BAYER                  0x01    /* Bayer format */
00139 #define COM7_PBAYER                 0x05    /* "Processed bayer" */
00140 
00141 
00142 // data format
00143 #define COM15_R10F0                 0x00    /* Data range 10 to F0 */
00144 #define COM15_R01FE                 0x80    /*            01 to FE */
00145 #define COM15_R00FF                 0xc0    /*            00 to FF */
00146 
00147 // Night mode, flicker, banding / 
00148 #define REG_COM11                   0x3b    /* Control 11 */
00149 #define COM11_NIGHT                 0x80    /* NIght mode enable */
00150 #define COM11_NIGHT_MIN_RATE_1_1    0x00    /* Normal mode same */
00151 #define COM11_NIGHT_MIN_RATE_1_2    0x20    /* Normal mode 1/2 */
00152 #define COM11_NIGHT_MIN_RATE_1_4    0x40    /* Normal mode 1/4 */
00153 #define COM11_NIGHT_MIN_RATE_1_8    0x60    /* Normal mode 1/5 */
00154 #define COM11_HZAUTO_ON             0x10    /* Auto detect 50/60 Hz on */
00155 #define COM11_HZAUTO_OFF            0x00    /* Auto detect 50/60 Hz off */
00156 #define COM11_60HZ                  0x00    /* Manual 60Hz select */
00157 #define COM11_50HZ                  0x08    /* Manual 50Hz select */
00158 #define COM11_EXP                   0x02
00159 
00160 #define REG_MTX1                    0x4f
00161 #define REG_MTX2                    0x50
00162 #define REG_MTX3                    0x51
00163 #define REG_MTX4                    0x52
00164 #define REG_MTX5                    0x53
00165 #define REG_MTX6                    0x54
00166 #define REG_BRIGHT                  0x55    /* Brightness */
00167 #define REG_CONTRAS                 0x56    /* Contrast control */
00168 #define REG_CONTRAS_CENTER          0x57
00169 #define REG_MTXS                    0x58
00170 #define REG_MANU                    0x67
00171 #define REG_MANV                    0x68
00172 #define REG_GFIX                    0x69    /* Fix gain control */
00173 #define REG_GGAIN                   0x6a
00174 #define REG_DBLV                    0x6b
00175 
00176 #define REG_COM9        0x14        // Control 9  - gain ceiling
00177 #define COM9_AGC_2X     0x00
00178 #define COM9_AGC_4X     0x10
00179 #define COM9_AGC_8X     0x20
00180 #define COM9_AGC_16X    0x30
00181 #define COM9_AGC_32X    0x40
00182 #define COM9_AGC_64X    0x50
00183 #define COM9_AGC_128X   0x60
00184 #define COM9_AGC_MASK   0x70
00185 #define COM9_FREEZE     0x01
00186 #define COM13_GAMMA     0x80    /* Gamma enable */
00187 #define COM13_UVSAT     0x40    /* UV saturation auto adjustment */
00188 #define REG_GAIN        0x00    /* Gain lower 8 bits (rest in vref) */
00189 #define REG_BLUE        0x01    /* blue gain */
00190 #define REG_RED         0x02    /* red gain */
00191 #define REG_COM1        0x04    /* Control 1 */
00192 #define COM1_CCIR656    0x40    /* CCIR656 enable */
00193 #define REG_BAVE        0x05    /* U/B Average level */
00194 #define REG_GbAVE       0x06    /* Y/Gb Average level */
00195 #define REG_AECHH       0x07    /* AEC MS 5 bits */
00196 #define REG_RAVE        0x08    /* V/R Average level */
00197 #define REG_COM2        0x09    /* Control 2 */
00198 #define COM2_SSLEEP     0x10    /* Soft sleep mode */
00199 #define REG_PID         0x0a    /* Product ID MSB */
00200 #define REG_VER         0x0b    /* Product ID LSB */
00201 #define COM3_SWAP       0x40    /* Byte swap */
00202 #define COM3_SCALEEN    0x08    /* Enable scaling */
00203 #define COM3_DCWEN      0x04    /* Enable downsamp/crop/window */
00204 #define REG_COM4        0x0d    /* Control 4 */
00205 #define REG_COM5        0x0e    /* All "reserved" */
00206 #define REG_COM6        0x0f    /* Control 6 */
00207 #define REG_AECH        0x10    /* More bits of AEC value */
00208 #define REG_CLKRC       0x11    /* Clocl control */
00209 #define CLK_EXT         0x40    /* Use external clock directly */
00210 #define CLK_SCALE       0x3f    /* Mask for internal clock scale */
00211 #define COM7_RESET      0x80    /* Register reset */
00212 #define COM7_FMT_MASK   0x38
00213 #define COM7_FMT_VGA    0x00
00214 #define COM7_FMT_CIF    0x20    /* CIF format */
00215 #define COM7_FMT_QVGA   0x10    /* QVGA format */
00216 #define COM7_FMT_QCIF   0x08    /* QCIF format */
00217 #define REG_COM8        0x13    /* Control 8 */
00218 #define COM8_FASTAEC    0x80    /* Enable fast AGC/AEC */
00219 #define COM8_AECSTEP    0x40    /* Unlimited AEC step size */
00220 #define COM8_BFILT      0x20    /* Band filter enable */
00221 #define COM8_AGC        0x04    /* Auto gain enable */
00222 #define COM8_AWB        0x02    /* White balance enable */
00223 #define COM8_AEC        0x01    /* Auto exposure enable */
00224 #define REG_COM9        0x14    /* Control 9  - gain ceiling */
00225 #define REG_COM10       0x15    /* Control 10 */
00226 #define COM10_HSYNC     0x40    /* HSYNC instead of HREF */
00227 #define COM10_PCLK_HB   0x20    /* Suppress PCLK on horiz blank */
00228 #define COM10_HREF_REV  0x08    /* Reverse HREF */
00229 #define COM10_VS_LEAD   0x04    /* VSYNC on clock leading edge */
00230 #define COM10_VS_NEG    0x02    /* VSYNC negative */
00231 #define COM10_HS_NEG    0x01    /* HSYNC negative */
00232 #define REG_PSHFT       0x1b    /* Pixel delay after HREF */
00233 #define REG_MIDH        0x1c    /* Manuf. ID high */
00234 #define REG_MIDL        0x1d    /* Manuf. ID low */
00235 #define REG_MVFP        0x1e    /* Mirror / vflip */
00236 #define MVFP_MIRROR     0x20    /* Mirror image */
00237 #define MVFP_FLIP       0x10    /* Vertical flip */
00238 #define REG_AEW         0x24    /* AGC upper limit */
00239 #define REG_AEB         0x25    /* AGC lower limit */
00240 #define REG_VPT         0x26    /* AGC/AEC fast mode op region */
00241 #define REG_HSYST       0x30    /* HSYNC rising edge delay */
00242 #define REG_HSYEN       0x31    /* HSYNC falling edge delay */
00243 #define REG_COM12       0x3c    /* Control 12 */
00244 #define COM12_HREF      0x80    /* HREF always */
00245 #define COM14_DCWEN     0x10    /* DCW/PCLK-scale enable */
00246 #define REG_EDGE        0x3f    /* Edge enhancement factor */
00247 #define REG_COM16       0x41    /* Control 16 */
00248 #define COM16_AWBGAIN   0x08    /* AWB gain enable */
00249 #define REG_COM17       0x42    /* Control 17 */
00250 #define COM17_AECWIN    0xc0    /* AEC window - must match COM4 */
00251 #define COM17_CBAR      0x08    /* DSP Color bar */
00252 #define REG_CMATRIX_BASE 0x4f
00253 #define CMATRIX_LEN         6
00254 #define REG_REG76       0x76    /* OV's name */
00255 #define R76_BLKPCOR     0x80    /* Black pixel correction enable */
00256 #define R76_WHTPCOR     0x40    /* White pixel correction enable */
00257 #define REG_HAECC1      0x9f    /* Hist AEC/AGC control 1 */
00258 #define REG_HAECC2      0xa0    /* Hist AEC/AGC control 2 */
00259 #define REG_BD50MAX     0xa5    /* 50hz banding step limit */
00260 #define REG_HAECC3      0xa6    /* Hist AEC/AGC control 3 */
00261 #define REG_HAECC4      0xa7    /* Hist AEC/AGC control 4 */
00262 #define REG_HAECC5      0xa8    /* Hist AEC/AGC control 5 */
00263 #define REG_HAECC6      0xa9    /* Hist AEC/AGC control 6 */
00264 #define REG_HAECC7      0xaa    /* Hist AEC/AGC control 7 */
00265 #define REG_BD60MAX     0xab    /* 60hz banding step limit */
00266 
00267 #define OV7670_WRITE (0x42)
00268 #define OV7670_READ  (0x43)
00269 #define OV7670_WRITEWAIT (20)
00270 #define OV7670_NOACK (0)
00271 #define OV7670_REGMAX (201)
00272 #define OV7670_I2CFREQ (50000)
00273 
00274 //Camera OV7670
00275 
00276 class HeptaCamera{
00277 public:
00278     I2C camera;
00279     InterruptIn vsync,href;
00280     DigitalOut wen;
00281     BusIn data;
00282     DigitalOut rrst,oe,rclk;
00283     volatile int LineCounter;
00284     volatile int LastLines;
00285     volatile bool CaptureReq;
00286     volatile bool Busy;
00287     volatile bool Done;
00288 
00289     HeptaCamera(
00290         PinName sda,// Camera I2C port
00291         PinName scl,// Camera I2C port
00292         PinName vs, // VSYNC
00293         PinName hr, // HREF
00294         PinName we, // WEN
00295         PinName d7, // D7
00296         PinName d6, // D6
00297         PinName d5, // D5
00298         PinName d4, // D4
00299         PinName d3, // D3
00300         PinName d2, // D2
00301         PinName d1, // D1
00302         PinName d0, // D0
00303         PinName rt, // /RRST
00304         PinName o,  // /OE
00305         PinName rc  // RCLK      
00306         );
00307     void CaptureNext(void);
00308     bool CaptureDone(void);
00309     void WriteReg(int addr,int data);
00310     int ReadReg(int addr);
00311     void PrintRegister(void);
00312     void Reset(void);
00313     void InitForFIFOWriteReset(void);
00314     void InitSetColorbar(void);
00315     void InitDefaultReg(void);
00316     void InitRGB444(void);
00317     void InitRGB555(void);
00318     void InitRGB565(void);
00319     void InitYUV(void);
00320     void InitBayerRGB(void);
00321     void InitVGA(void);
00322     void InitFIFO_2bytes_color_nealy_limit_size(void);
00323     void InitVGA_3_4(void);
00324     void InitQVGA(void);
00325     void InitQQVGA();
00326     void VsyncHandler(void);
00327     void HrefHandler(void);
00328     int ReadOneByte(void);
00329     void ReadStart(void);
00330     void ReadStop(void);
00331     void shoot();
00332     void shoot2();
00333 private:
00334 };
00335 #endif