Arducam_OV5642_Library

Dependents:   DigitalCamera_OV5642_WIZwiki-W7500 RFID-RC522_buffer Prelude_OV5642_dev

Committer:
justinkim
Date:
Thu Oct 29 23:31:28 2015 +0000
Revision:
3:ee782b77485e
Parent:
1:f2126346d524
TEST version 0.2 - adding FTP...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
justinkim 0:fc90ec271280 1 #ifndef MBED_ARDUCAM_H
justinkim 0:fc90ec271280 2 #define MBED_ARDUCAM_H
justinkim 0:fc90ec271280 3
justinkim 0:fc90ec271280 4 #include "mbed.h"
justinkim 0:fc90ec271280 5
justinkim 0:fc90ec271280 6 //******************************************************************************
justinkim 0:fc90ec271280 7 // Macros
justinkim 0:fc90ec271280 8 //******************************************************************************
justinkim 0:fc90ec271280 9 #define I2C_SEND_STOP 0x01
justinkim 0:fc90ec271280 10 #define I2C_SEND_START 0x02
justinkim 0:fc90ec271280 11 #define sensor_addr 0x78
justinkim 0:fc90ec271280 12 #define SPAWN_TASK_PRIORITY 9//9
justinkim 0:fc90ec271280 13 #define HTTP_SERVER_APP_TASK_PRIORITY 3//1
justinkim 0:fc90ec271280 14 #define CAMERA_SERVICE_PRIORITY 3
justinkim 0:fc90ec271280 15 #define OSI_STACK_SIZE 8 * 1024
justinkim 0:fc90ec271280 16
justinkim 0:fc90ec271280 17 #define cport(port, data) port &= data
justinkim 0:fc90ec271280 18 #define sport(port, data) port |= data
justinkim 0:fc90ec271280 19
justinkim 0:fc90ec271280 20 #define swap(type, i, j) {type t = i; i = j; j = t;}
justinkim 0:fc90ec271280 21
justinkim 0:fc90ec271280 22 #define fontbyte(x) cfont.font[x]
justinkim 0:fc90ec271280 23
justinkim 0:fc90ec271280 24 #define regtype volatile uint32_t
justinkim 0:fc90ec271280 25 #define regsize uint32_t
justinkim 0:fc90ec271280 26 #define PROGMEM
justinkim 0:fc90ec271280 27
justinkim 0:fc90ec271280 28
justinkim 0:fc90ec271280 29 #define pgm_read_byte(x) (*((char *)x))
justinkim 0:fc90ec271280 30 // #define pgm_read_word(x) (*((short *)(x & 0xfffffffe)))
justinkim 0:fc90ec271280 31 #define pgm_read_word(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
justinkim 0:fc90ec271280 32 #define pgm_read_byte_near(x) (*((char *)x))
justinkim 0:fc90ec271280 33 #define pgm_read_byte_far(x) (*((char *)x))
justinkim 0:fc90ec271280 34 // #define pgm_read_word_near(x) (*((short *)(x & 0xfffffffe))
justinkim 0:fc90ec271280 35 // #define pgm_read_word_far(x) (*((short *)(x & 0xfffffffe)))
justinkim 0:fc90ec271280 36 #define pgm_read_word_near(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x)))
justinkim 0:fc90ec271280 37 #define pgm_read_word_far(x) ( ((*((unsigned char *)x + 1)) << 8) + (*((unsigned char *)x))))
justinkim 0:fc90ec271280 38 #define PSTR(x) x
justinkim 0:fc90ec271280 39 #define F(X) (X)
justinkim 0:fc90ec271280 40
justinkim 0:fc90ec271280 41 #define BMP 0
justinkim 0:fc90ec271280 42 #define JPEG 1
justinkim 0:fc90ec271280 43
justinkim 0:fc90ec271280 44 #define OV5642 3
justinkim 0:fc90ec271280 45
justinkim 0:fc90ec271280 46 #define OV5642_320x240 1 //320x240
justinkim 0:fc90ec271280 47 #define OV5642_640x480 2 //640x480
justinkim 0:fc90ec271280 48 #define OV5642_1280x720 3 //1280x720
justinkim 0:fc90ec271280 49 #define OV5642_1920x1080 4 //1920x1080
justinkim 0:fc90ec271280 50 #define OV5642_2048x1563 5 //2048x1563
justinkim 0:fc90ec271280 51 #define OV5642_2592x1944 6 //2592x1944
justinkim 0:fc90ec271280 52
justinkim 0:fc90ec271280 53 /****************************************************/
justinkim 0:fc90ec271280 54 /* I2C Control Definition */
justinkim 0:fc90ec271280 55 /****************************************************/
justinkim 0:fc90ec271280 56 #define I2C_ADDR_8BIT 0
justinkim 0:fc90ec271280 57 #define I2C_ADDR_16BIT 1
justinkim 0:fc90ec271280 58 #define I2C_REG_8BIT 0
justinkim 0:fc90ec271280 59 #define I2C_REG_16BIT 1
justinkim 0:fc90ec271280 60 #define I2C_DAT_8BIT 0
justinkim 0:fc90ec271280 61 #define I2C_DAT_16BIT 1
justinkim 0:fc90ec271280 62
justinkim 0:fc90ec271280 63 /* Register initialization tables for SENSORs */
justinkim 0:fc90ec271280 64 /* Terminating list entry for reg */
justinkim 0:fc90ec271280 65 #define SENSOR_REG_TERM_8BIT 0xFF
justinkim 0:fc90ec271280 66 #define SENSOR_REG_TERM_16BIT 0xFFFF
justinkim 0:fc90ec271280 67 /* Terminating list entry for val */
justinkim 0:fc90ec271280 68 #define SENSOR_VAL_TERM_8BIT 0xFF
justinkim 0:fc90ec271280 69 #define SENSOR_VAL_TERM_16BIT 0xFFFF
justinkim 0:fc90ec271280 70
justinkim 0:fc90ec271280 71 /****************************************************/
justinkim 0:fc90ec271280 72 /* ArduChip related definition */
justinkim 0:fc90ec271280 73 /****************************************************/
justinkim 0:fc90ec271280 74 #define RWBIT 0x80 //READ AND WRITE BIT IS BIT[7]
justinkim 0:fc90ec271280 75
justinkim 0:fc90ec271280 76 #define ARDUCHIP_TEST1 0x00 //TEST register
justinkim 0:fc90ec271280 77 #define ARDUCHIP_TEST2 0x01 //TEST register
justinkim 0:fc90ec271280 78
justinkim 0:fc90ec271280 79 #define ARDUCHIP_FRAMES 0x01 //Bit[2:0]Number of frames to be captured
justinkim 0:fc90ec271280 80
justinkim 0:fc90ec271280 81 #define ARDUCHIP_MODE 0x02 //Mode register
justinkim 0:fc90ec271280 82 #define MCU2LCD_MODE 0x00
justinkim 0:fc90ec271280 83 #define CAM2LCD_MODE 0x01
justinkim 0:fc90ec271280 84 #define LCD2MCU_MODE 0x02
justinkim 0:fc90ec271280 85
justinkim 0:fc90ec271280 86 #define ARDUCHIP_TIM 0x03 //Timming control
justinkim 0:fc90ec271280 87 #define HREF_LEVEL_MASK 0x01 //0 = High active , 1 = Low active
justinkim 0:fc90ec271280 88 #define VSYNC_LEVEL_MASK 0x02 //0 = High active , 1 = Low active
justinkim 0:fc90ec271280 89 #define LCD_BKEN_MASK 0x04 //0 = Enable, 1 = Disable
justinkim 0:fc90ec271280 90 #define DELAY_MASK 0x08 //0 = no delay, 1 = delay one clock
justinkim 0:fc90ec271280 91 #define MODE_MASK 0x10 //0 = LCD mode, 1 = FIFO mode
justinkim 0:fc90ec271280 92 #define FIFO_PWRDN_MASK 0x20 //0 = Normal operation, 1 = FIFO power down
justinkim 0:fc90ec271280 93 #define LOW_POWER_MODE 0x40 //0 = Normal mode, 1 = Low power mode
justinkim 0:fc90ec271280 94
justinkim 0:fc90ec271280 95 #define ARDUCHIP_FIFO 0x04 //FIFO and I2C control
justinkim 0:fc90ec271280 96 #define FIFO_CLEAR_MASK 0x01
justinkim 0:fc90ec271280 97 #define FIFO_START_MASK 0x02
justinkim 0:fc90ec271280 98 #define FIFO_RDPTR_RST_MASK 0x10
justinkim 0:fc90ec271280 99 #define FIFO_WRPTR_RST_MASK 0x20
justinkim 0:fc90ec271280 100
justinkim 0:fc90ec271280 101 #define ARDUCHIP_GPIO 0x06 //GPIO Write Register
justinkim 0:fc90ec271280 102 #define GPIO_RESET_MASK 0x01 //0 = default state, 1 = Sensor reset IO value
justinkim 0:fc90ec271280 103 #define GPIO_PWDN_MASK 0x02 //0 = Sensor power down IO value, 1 = Sensor power enable IO value
justinkim 0:fc90ec271280 104
justinkim 0:fc90ec271280 105 #define BURST_FIFO_READ 0x3C //Burst FIFO read operation
justinkim 0:fc90ec271280 106 #define SINGLE_FIFO_READ 0x3D //Single FIFO read operation
justinkim 0:fc90ec271280 107
justinkim 0:fc90ec271280 108 #define ARDUCHIP_REV 0x40 //ArduCHIP revision
justinkim 0:fc90ec271280 109 #define VER_LOW_MASK 0x3F
justinkim 0:fc90ec271280 110 #define VER_HIGH_MASK 0xC0
justinkim 0:fc90ec271280 111
justinkim 0:fc90ec271280 112 #define ARDUCHIP_TRIG 0x41 //Trigger source
justinkim 0:fc90ec271280 113 #define VSYNC_MASK 0x01
justinkim 0:fc90ec271280 114 #define SHUTTER_MASK 0x02
justinkim 0:fc90ec271280 115 #define CAP_DONE_MASK 0x08
justinkim 0:fc90ec271280 116
justinkim 0:fc90ec271280 117 #define FIFO_SIZE1 0x42 //Camera write FIFO size[7:0] for burst to read
justinkim 0:fc90ec271280 118 #define FIFO_SIZE2 0x43 //Camera write FIFO size[15:8]
justinkim 0:fc90ec271280 119 #define FIFO_SIZE3 0x44 //Camera write FIFO size[18:16
justinkim 0:fc90ec271280 120
justinkim 0:fc90ec271280 121 class ArduCAM
justinkim 0:fc90ec271280 122 {
justinkim 0:fc90ec271280 123 public:
justinkim 0:fc90ec271280 124 ArduCAM(PinName mosi, PinName miso, PinName sck, PinName cs, PinName sda, PinName scl);
justinkim 0:fc90ec271280 125 void InitCAM(void);
justinkim 0:fc90ec271280 126
justinkim 0:fc90ec271280 127 void CS_HIGH(void);
justinkim 0:fc90ec271280 128 void CS_LOW(void);
justinkim 0:fc90ec271280 129
justinkim 0:fc90ec271280 130 void flush_fifo(void);
justinkim 0:fc90ec271280 131 void start_capture(void);
justinkim 0:fc90ec271280 132 void clear_fifo_flag(void);
justinkim 0:fc90ec271280 133 uint8_t read_fifo(void);
justinkim 0:fc90ec271280 134
justinkim 0:fc90ec271280 135 uint8_t read_reg(uint8_t addr);
justinkim 0:fc90ec271280 136 void write_reg(uint8_t addr, uint8_t data);
justinkim 0:fc90ec271280 137
justinkim 0:fc90ec271280 138 uint32_t read_fifo_length(void);
justinkim 0:fc90ec271280 139 void set_fifo_burst(void);
justinkim 0:fc90ec271280 140 void set_bit(uint8_t addr, uint8_t bit);
justinkim 0:fc90ec271280 141 void clear_bit(uint8_t addr, uint8_t bit);
justinkim 0:fc90ec271280 142 uint8_t get_bit(uint8_t addr, uint8_t bit);
justinkim 0:fc90ec271280 143 void set_mode(uint8_t mode);
justinkim 0:fc90ec271280 144
justinkim 0:fc90ec271280 145 int wrSensorRegs(const struct sensor_reg*);
justinkim 0:fc90ec271280 146 int wrSensorRegs8_8(const struct sensor_reg*);
justinkim 0:fc90ec271280 147 int wrSensorRegs8_16(const struct sensor_reg*);
justinkim 0:fc90ec271280 148 int wrSensorRegs16_8(const struct sensor_reg*);
justinkim 0:fc90ec271280 149 int wrSensorRegs16_16(const struct sensor_reg*);
justinkim 0:fc90ec271280 150
justinkim 0:fc90ec271280 151 uint8_t wrSensorReg(int regID, int regDat);
justinkim 0:fc90ec271280 152 uint8_t wrSensorReg8_8(int regID, int regDat);
justinkim 0:fc90ec271280 153 uint8_t wrSensorReg8_16(int regID, int regDat);
justinkim 0:fc90ec271280 154 uint8_t wrSensorReg16_8(int regID, int regDat);
justinkim 0:fc90ec271280 155 uint8_t wrSensorReg16_16(int regID, int regDat);
justinkim 0:fc90ec271280 156
justinkim 0:fc90ec271280 157 uint8_t rdSensorReg8_8(uint8_t regID, uint8_t* regDat);
justinkim 0:fc90ec271280 158 uint8_t rdSensorReg16_8(uint16_t regID, uint8_t* regDat);
justinkim 0:fc90ec271280 159 uint8_t rdSensorReg8_16(uint8_t regID, uint16_t* regDat);
justinkim 0:fc90ec271280 160 uint8_t rdSensorReg16_16(uint16_t regID, uint16_t* regDat);
justinkim 0:fc90ec271280 161
justinkim 3:ee782b77485e 162 void OV5642_set_JPEG_size(uint8_t size);
justinkim 0:fc90ec271280 163 void set_format(uint8_t fmt);
justinkim 0:fc90ec271280 164
justinkim 0:fc90ec271280 165 int bus_write(int address, int value);
justinkim 0:fc90ec271280 166 uint8_t bus_read(int address);
justinkim 0:fc90ec271280 167
justinkim 0:fc90ec271280 168 protected:
justinkim 0:fc90ec271280 169 SPI spi; // does SPI MOSI, MISO and SCK
justinkim 0:fc90ec271280 170 DigitalOut _cs; // does SPI CE
justinkim 0:fc90ec271280 171 I2C i2c; // does I2C SDA, SCL
justinkim 0:fc90ec271280 172 regtype *P_CS;
justinkim 0:fc90ec271280 173 regsize B_CS;
justinkim 0:fc90ec271280 174 uint8_t m_fmt;
justinkim 0:fc90ec271280 175 uint8_t sensor_model;
justinkim 0:fc90ec271280 176
justinkim 0:fc90ec271280 177 uint32_t I2CInit(void);
justinkim 0:fc90ec271280 178 int32_t I2CBufferRead(int32_t ucDevAddr, uint8_t *ucBuffer, int32_t ulSize,unsigned char ucFlags);
justinkim 0:fc90ec271280 179 int32_t I2CBufferWrite(int32_t ucDevAddr, uint8_t *ucBuffer, int32_t ulSize,unsigned char ucFlags);
justinkim 0:fc90ec271280 180 };
justinkim 0:fc90ec271280 181
justinkim 0:fc90ec271280 182 #endif