mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update OV7725 registers.
* Fix the ov7725 driver for better camera image quality. * Add in banding filter setting for each camera.
This commit is contained in:
parent
10ec2324ff
commit
6c939b4c37
@ -30,6 +30,9 @@
|
|||||||
// Sensor PLL register value.
|
// Sensor PLL register value.
|
||||||
#define OMV_OV7725_PLL_CONFIG (0x41) // x4
|
#define OMV_OV7725_PLL_CONFIG (0x41) // x4
|
||||||
|
|
||||||
|
// Sensor Banding Filter Value
|
||||||
|
#define OMV_OV7725_BANDING (0x3F)
|
||||||
|
|
||||||
// Bootloader LED GPIO port/pin
|
// Bootloader LED GPIO port/pin
|
||||||
#define OMV_BOOTLDR_LED_PIN (GPIO_PIN_2)
|
#define OMV_BOOTLDR_LED_PIN (GPIO_PIN_2)
|
||||||
#define OMV_BOOTLDR_LED_PORT (GPIOC)
|
#define OMV_BOOTLDR_LED_PORT (GPIOC)
|
||||||
|
|||||||
@ -30,6 +30,9 @@
|
|||||||
// Sensor PLL register value.
|
// Sensor PLL register value.
|
||||||
#define OMV_OV7725_PLL_CONFIG (0x81) // x6
|
#define OMV_OV7725_PLL_CONFIG (0x81) // x6
|
||||||
|
|
||||||
|
// Sensor Banding Filter Value
|
||||||
|
#define OMV_OV7725_BANDING (0x8F)
|
||||||
|
|
||||||
// Bootloader LED GPIO port/pin
|
// Bootloader LED GPIO port/pin
|
||||||
#define OMV_BOOTLDR_LED_PIN (GPIO_PIN_1)
|
#define OMV_BOOTLDR_LED_PIN (GPIO_PIN_1)
|
||||||
#define OMV_BOOTLDR_LED_PORT (GPIOC)
|
#define OMV_BOOTLDR_LED_PORT (GPIOC)
|
||||||
|
|||||||
@ -30,6 +30,9 @@
|
|||||||
// Sensor PLL register value.
|
// Sensor PLL register value.
|
||||||
#define OMV_OV7725_PLL_CONFIG (0x41) // x4
|
#define OMV_OV7725_PLL_CONFIG (0x41) // x4
|
||||||
|
|
||||||
|
// Sensor Banding Filter Value
|
||||||
|
#define OMV_OV7725_BANDING (0x7F)
|
||||||
|
|
||||||
// Bootloader LED GPIO port/pin
|
// Bootloader LED GPIO port/pin
|
||||||
#define OMV_BOOTLDR_LED_PIN (GPIO_PIN_1)
|
#define OMV_BOOTLDR_LED_PIN (GPIO_PIN_1)
|
||||||
#define OMV_BOOTLDR_LED_PORT (GPIOC)
|
#define OMV_BOOTLDR_LED_PORT (GPIOC)
|
||||||
|
|||||||
164
src/omv/ov7725.c
164
src/omv/ov7725.c
@ -17,97 +17,91 @@
|
|||||||
#include "omv_boardconfig.h"
|
#include "omv_boardconfig.h"
|
||||||
|
|
||||||
static const uint8_t default_regs[][2] = {
|
static const uint8_t default_regs[][2] = {
|
||||||
{COM3, COM3_SWAP_YUV},
|
|
||||||
{COM7, COM7_RES_VGA | COM7_FMT_RGB565 | COM7_FMT_RGB},
|
|
||||||
|
|
||||||
{COM4, OMV_OV7725_PLL_CONFIG},
|
// From App Note.
|
||||||
{CLKRC, 0xC0}, /* Res/Bypass pre-scalar */
|
|
||||||
|
|
||||||
// VGA Window Size
|
|
||||||
{HSTART, 0x23},
|
|
||||||
{HSIZE, 0xA0},
|
|
||||||
{VSTART, 0x07},
|
|
||||||
{VSIZE, 0xF0},
|
|
||||||
{HREF, 0x00},
|
|
||||||
|
|
||||||
// Scale down to QVGA Resoultion
|
|
||||||
{HOUTSIZE, 0x50},
|
|
||||||
{VOUTSIZE, 0x78},
|
|
||||||
|
|
||||||
{COM12, 0x03},
|
{COM12, 0x03},
|
||||||
|
{HSTART, 0x22},
|
||||||
|
{HSIZE, 0xa4},
|
||||||
|
{VSTART, 0x07},
|
||||||
|
{VSIZE, 0xf0},
|
||||||
|
{HREF, 0x00},
|
||||||
|
{HOUTSIZE, 0xa0},
|
||||||
|
{VOUTSIZE, 0xf0},
|
||||||
{EXHCH, 0x00},
|
{EXHCH, 0x00},
|
||||||
{TGT_B, 0x7F},
|
{CLKRC, 0xC0}, // {CLKRC, 0x01},
|
||||||
|
|
||||||
|
{TGT_B, 0x7f},
|
||||||
{FIXGAIN, 0x09},
|
{FIXGAIN, 0x09},
|
||||||
{AWB_CTRL0, 0xE0},
|
{AWB_CTRL0, 0xe0},
|
||||||
{DSP_CTRL1, 0xFF},
|
{DSP_CTRL1, 0xff},
|
||||||
|
{DSP_CTRL2, 0x20 | DSP_CTRL2_VDCW_EN | DSP_CTRL2_HDCW_EN | DSP_CTRL2_VZOOM_EN | DSP_CTRL2_HZOOM_EN}, // {DSP_CTRL2, 0x20},
|
||||||
{DSP_CTRL2, DSP_CTRL2_VDCW_EN | DSP_CTRL2_HDCW_EN | DSP_CTRL2_HZOOM_EN | DSP_CTRL2_VZOOM_EN},
|
|
||||||
|
|
||||||
{DSP_CTRL3, 0x00},
|
{DSP_CTRL3, 0x00},
|
||||||
{DSP_CTRL4, 0x00},
|
{DSP_CTRL4, 0x48},
|
||||||
{DSPAUTO, 0xFF},
|
|
||||||
|
|
||||||
{COM8, 0xF0},
|
{COM8, 0xf0},
|
||||||
{COM6, 0xC5},
|
{COM4, OMV_OV7725_PLL_CONFIG}, // {COM4, 0x41},
|
||||||
{COM9, 0x21},
|
{COM6, 0xc5},
|
||||||
{BDBASE, 0x7F},
|
{COM9, 0x11},
|
||||||
|
{BDBASE, 0x7f},
|
||||||
{BDSTEP, 0x03},
|
{BDSTEP, 0x03},
|
||||||
{AEW, 0x96},
|
{AEW, 0x40},
|
||||||
{AEB, 0x64},
|
{AEB, 0x30},
|
||||||
{VPT, 0xA1},
|
{VPT, 0xa1},
|
||||||
{EXHCL, 0x00},
|
{EXHCL, 0x00},
|
||||||
{AWB_CTRL3, 0xAA},
|
{AWB_CTRL3, 0xaa},
|
||||||
{COM8, 0xFF},
|
{COM8, 0xff},
|
||||||
|
|
||||||
//Gamma
|
|
||||||
{GAM1, 0x0C},
|
|
||||||
{GAM2, 0x16},
|
|
||||||
{GAM3, 0x2A},
|
|
||||||
{GAM4, 0x4E},
|
|
||||||
{GAM5, 0x61},
|
|
||||||
{GAM6, 0x6F},
|
|
||||||
{GAM7, 0x7B},
|
|
||||||
{GAM8, 0x86},
|
|
||||||
{GAM9, 0x8E},
|
|
||||||
{GAM10, 0x97},
|
|
||||||
{GAM11, 0xA4},
|
|
||||||
{GAM12, 0xAF},
|
|
||||||
{GAM13, 0xC5},
|
|
||||||
{GAM14, 0xD7},
|
|
||||||
{GAM15, 0xE8},
|
|
||||||
|
|
||||||
{SLOP, 0x20},
|
|
||||||
{EDGE1, 0x05},
|
{EDGE1, 0x05},
|
||||||
|
{DNSOFF, 0x01},
|
||||||
{EDGE2, 0x03},
|
{EDGE2, 0x03},
|
||||||
{EDGE3, 0x00},
|
{EDGE3, 0x00},
|
||||||
{DNSOFF, 0x01},
|
{MTX1, 0xb0},
|
||||||
|
{MTX2, 0x9d},
|
||||||
{MTX1, 0xB0},
|
|
||||||
{MTX2, 0x9D},
|
|
||||||
{MTX3, 0x13},
|
{MTX3, 0x13},
|
||||||
{MTX4, 0x16},
|
{MTX4, 0x16},
|
||||||
{MTX5, 0x7B},
|
{MTX5, 0x7b},
|
||||||
{MTX6, 0x91},
|
{MTX6, 0x91},
|
||||||
{MTX_CTRL, 0x1E},
|
{MTX_CTRL, 0x1e},
|
||||||
|
|
||||||
{BRIGHTNESS, 0x08},
|
{BRIGHTNESS, 0x08},
|
||||||
{CONTRAST, 0x20},
|
{CONTRAST, 0x20},
|
||||||
{UVADJ0, 0x81},
|
{UVADJ0, 0x81},
|
||||||
{SDE, (SDE_CONT_BRIGHT_EN | SDE_SATURATION_EN)},
|
{SDE, SDE_CONT_BRIGHT_EN | SDE_SATURATION_EN},
|
||||||
|
|
||||||
|
{GAM1, 0x0c},
|
||||||
|
{GAM2, 0x16},
|
||||||
|
{GAM3, 0x2a},
|
||||||
|
{GAM4, 0x4e},
|
||||||
|
{GAM5, 0x61},
|
||||||
|
{GAM6, 0x6f},
|
||||||
|
{GAM7, 0x7b},
|
||||||
|
{GAM8, 0x86},
|
||||||
|
{GAM9, 0x8e},
|
||||||
|
{GAM10, 0x97},
|
||||||
|
{GAM11, 0xa4},
|
||||||
|
{GAM12, 0xaf},
|
||||||
|
{GAM13, 0xc5},
|
||||||
|
{GAM14, 0xd7},
|
||||||
|
{GAM15, 0xe8},
|
||||||
|
{SLOP, 0x20},
|
||||||
|
|
||||||
// For 30 fps/60Hz
|
|
||||||
{DM_LNL, 0x00},
|
{DM_LNL, 0x00},
|
||||||
{DM_LNH, 0x00},
|
{BDBASE, OMV_OV7725_BANDING}, // {BDBASE, 0x7f}
|
||||||
{BDBASE, 0x7F},
|
|
||||||
{BDSTEP, 0x03},
|
{BDSTEP, 0x03},
|
||||||
|
|
||||||
// Lens Correction, should be tuned with real camera module
|
{LC_RADI, 0x10},
|
||||||
{LC_CTR, 0x01}, // Enable LC and use 1 coefficient for all 3 channels
|
{LC_COEF, 0x10},
|
||||||
{LC_RADI, 0x30}, // The radius of the circle where no compensation applies
|
{LC_COEFB, 0x14},
|
||||||
{LC_COEF, 0x30}, // RGB Lens correction coefficient
|
{LC_COEFR, 0x17},
|
||||||
|
{LC_CTR, 0x01}, // {LC_CTR, 0x05},
|
||||||
|
|
||||||
// Frame reduction in night mode.
|
{COM5, 0xf5}, // {COM5, 0x65},
|
||||||
{COM5, 0xD5},
|
|
||||||
|
// OpenMV Custom.
|
||||||
|
|
||||||
|
{COM7, COM7_FMT_RGB565},
|
||||||
|
|
||||||
|
// End.
|
||||||
|
|
||||||
{0x00, 0x00},
|
{0x00, 0x00},
|
||||||
};
|
};
|
||||||
@ -153,24 +147,21 @@ static const uint8_t saturation_regs[NUM_SATURATION_LEVELS][2] = {
|
|||||||
|
|
||||||
static int reset(sensor_t *sensor)
|
static int reset(sensor_t *sensor)
|
||||||
{
|
{
|
||||||
int i=0;
|
|
||||||
const uint8_t (*regs)[2];
|
|
||||||
|
|
||||||
// Reset all registers
|
// Reset all registers
|
||||||
cambus_writeb(sensor->slv_addr, COM7, COM7_RESET);
|
int ret = cambus_writeb(sensor->slv_addr, COM7, COM7_RESET);
|
||||||
|
|
||||||
// Delay 10 ms
|
// Delay 2 ms
|
||||||
systick_sleep(10);
|
systick_sleep(2);
|
||||||
|
|
||||||
// Write default regsiters
|
// Write default regsiters
|
||||||
for (i=0, regs = default_regs; regs[i][0]; i++) {
|
for (int i = 0; default_regs[i][0]; i++) {
|
||||||
cambus_writeb(sensor->slv_addr, regs[i][0], regs[i][1]);
|
ret |= cambus_writeb(sensor->slv_addr, default_regs[i][0], default_regs[i][1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delay
|
// Delay 300 ms
|
||||||
systick_sleep(30);
|
systick_sleep(300);
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sleep(sensor_t *sensor, int enable)
|
static int sleep(sensor_t *sensor, int enable)
|
||||||
@ -210,18 +201,17 @@ static int set_pixformat(sensor_t *sensor, pixformat_t pixformat)
|
|||||||
switch (pixformat) {
|
switch (pixformat) {
|
||||||
case PIXFORMAT_RGB565:
|
case PIXFORMAT_RGB565:
|
||||||
reg = COM7_SET_FMT(reg, COM7_FMT_RGB);
|
reg = COM7_SET_FMT(reg, COM7_FMT_RGB);
|
||||||
ret = cambus_writeb(sensor->slv_addr, DSP_CTRL4, 0);
|
ret |= cambus_writeb(sensor->slv_addr, DSP_CTRL4, DSP_CTRL4_YUV_RGB);
|
||||||
break;
|
break;
|
||||||
case PIXFORMAT_YUV422:
|
case PIXFORMAT_YUV422:
|
||||||
case PIXFORMAT_GRAYSCALE:
|
case PIXFORMAT_GRAYSCALE:
|
||||||
reg = COM7_SET_FMT(reg, COM7_FMT_YUV);
|
reg = COM7_SET_FMT(reg, COM7_FMT_YUV);
|
||||||
ret = cambus_writeb(sensor->slv_addr, DSP_CTRL4, 0);
|
ret |= cambus_writeb(sensor->slv_addr, DSP_CTRL4, DSP_CTRL4_YUV_RGB);
|
||||||
break;
|
break;
|
||||||
case PIXFORMAT_BAYER:
|
case PIXFORMAT_BAYER:
|
||||||
reg = COM7_SET_FMT(reg, COM7_FMT_P_BAYER);
|
reg = COM7_SET_FMT(reg, COM7_FMT_P_BAYER);
|
||||||
ret = cambus_writeb(sensor->slv_addr, DSP_CTRL4, DSP_CTRL4_RAW8);
|
ret |= cambus_writeb(sensor->slv_addr, DSP_CTRL4, DSP_CTRL4_RAW8);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -255,7 +245,6 @@ static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
|||||||
ret |= cambus_writeb(sensor->slv_addr, HSIZE, 0x50);
|
ret |= cambus_writeb(sensor->slv_addr, HSIZE, 0x50);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, VSTART, 0x03);
|
ret |= cambus_writeb(sensor->slv_addr, VSTART, 0x03);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, VSIZE, 0x78);
|
ret |= cambus_writeb(sensor->slv_addr, VSIZE, 0x78);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, HREF, 0x00);
|
|
||||||
|
|
||||||
// Enable auto-scaling/zooming factors
|
// Enable auto-scaling/zooming factors
|
||||||
ret |= cambus_writeb(sensor->slv_addr, DSPAUTO, 0xFF);
|
ret |= cambus_writeb(sensor->slv_addr, DSPAUTO, 0xFF);
|
||||||
@ -271,15 +260,14 @@ static int set_framesize(sensor_t *sensor, framesize_t framesize)
|
|||||||
ret |= cambus_writeb(sensor->slv_addr, HSIZE, 0xA0);
|
ret |= cambus_writeb(sensor->slv_addr, HSIZE, 0xA0);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, VSTART, 0x07);
|
ret |= cambus_writeb(sensor->slv_addr, VSTART, 0x07);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, VSIZE, 0xF0);
|
ret |= cambus_writeb(sensor->slv_addr, VSIZE, 0xF0);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, HREF, 0x00);
|
|
||||||
|
|
||||||
// Disable auto-scaling/zooming factors
|
// Disable auto-scaling/zooming factors
|
||||||
ret |= cambus_writeb(sensor->slv_addr, DSPAUTO, 0xF3);
|
ret |= cambus_writeb(sensor->slv_addr, DSPAUTO, 0xF3);
|
||||||
|
|
||||||
// Clear auto-scaling/zooming factors
|
// Clear auto-scaling/zooming factors
|
||||||
ret |= cambus_writeb(sensor->slv_addr, SCAL0, 0x00);
|
ret |= cambus_writeb(sensor->slv_addr, SCAL0, 0x00);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, SCAL1, 0x00);
|
ret |= cambus_writeb(sensor->slv_addr, SCAL1, 0x40);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, SCAL2, 0x00);
|
ret |= cambus_writeb(sensor->slv_addr, SCAL2, 0x40);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -316,7 +304,6 @@ static int set_brightness(sensor_t *sensor, int level)
|
|||||||
static int set_saturation(sensor_t *sensor, int level)
|
static int set_saturation(sensor_t *sensor, int level)
|
||||||
{
|
{
|
||||||
int ret=0;
|
int ret=0;
|
||||||
|
|
||||||
level += (NUM_SATURATION_LEVELS / 2 );
|
level += (NUM_SATURATION_LEVELS / 2 );
|
||||||
if (level < 0 || level >= NUM_SATURATION_LEVELS) {
|
if (level < 0 || level >= NUM_SATURATION_LEVELS) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -570,7 +557,7 @@ static int set_special_effect(sensor_t *sensor, sde_t sde)
|
|||||||
case SDE_NORMAL:
|
case SDE_NORMAL:
|
||||||
ret |= cambus_writeb(sensor->slv_addr, SDE, 0x06);
|
ret |= cambus_writeb(sensor->slv_addr, SDE, 0x06);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, UFIX, 0x80);
|
ret |= cambus_writeb(sensor->slv_addr, UFIX, 0x80);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, UFIX, 0x80);
|
ret |= cambus_writeb(sensor->slv_addr, VFIX, 0x80);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
@ -586,6 +573,7 @@ static int set_lens_correction(sensor_t *sensor, int enable, int radi, int coef)
|
|||||||
ret |= cambus_writeb(sensor->slv_addr, LC_CTR, (enable&0x01));
|
ret |= cambus_writeb(sensor->slv_addr, LC_CTR, (enable&0x01));
|
||||||
ret |= cambus_writeb(sensor->slv_addr, LC_RADI, radi);
|
ret |= cambus_writeb(sensor->slv_addr, LC_RADI, radi);
|
||||||
ret |= cambus_writeb(sensor->slv_addr, LC_COEF, coef);
|
ret |= cambus_writeb(sensor->slv_addr, LC_COEF, coef);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -106,7 +106,7 @@
|
|||||||
#define COM8_AEC_EN 0x01 /* AEC Enable */
|
#define COM8_AEC_EN 0x01 /* AEC Enable */
|
||||||
#define COM8_SET_AGC(r, x) ((r&0xFB)|((x&0x1)<<2))
|
#define COM8_SET_AGC(r, x) ((r&0xFB)|((x&0x1)<<2))
|
||||||
#define COM8_SET_AWB(r, x) ((r&0xFD)|((x&0x1)<<1))
|
#define COM8_SET_AWB(r, x) ((r&0xFD)|((x&0x1)<<1))
|
||||||
#define COM8_SET_AEC(r, x) ((r&0xFE)|((x&0x1)<<0))
|
#define COM8_SET_AEC(r, x) ((r&0x7E)|((x&0x1)<<7)|((x&0x1)<<0))
|
||||||
|
|
||||||
#define COM9 0x14 /* Common Control 9 */
|
#define COM9 0x14 /* Common Control 9 */
|
||||||
#define COM9_HISTO_AVG 0x80 /* Histogram or average based AEC/AGC selection */
|
#define COM9_HISTO_AVG 0x80 /* Histogram or average based AEC/AGC selection */
|
||||||
@ -285,7 +285,7 @@
|
|||||||
#define GAM6 0x83 /* Gamma Curve 6th Segment Input End Point 0x30 Output Value */
|
#define GAM6 0x83 /* Gamma Curve 6th Segment Input End Point 0x30 Output Value */
|
||||||
#define GAM7 0x84 /* Gamma Curve 7th Segment Input End Point 0x38 Output Value */
|
#define GAM7 0x84 /* Gamma Curve 7th Segment Input End Point 0x38 Output Value */
|
||||||
#define GAM8 0x85 /* Gamma Curve 8th Segment Input End Point 0x40 Output Value */
|
#define GAM8 0x85 /* Gamma Curve 8th Segment Input End Point 0x40 Output Value */
|
||||||
#define GAM9 0x86 /* Gamma Curve 9th Segment Input End Point 0x48 Output Value */
|
#define GAM9 0x86 /* Gamma Curve 9th Segment Input Enpd Point 0x48 Output Value */
|
||||||
#define GAM10 0x87 /* Gamma Curve 10th Segment Input End Point 0x50 Output Value */
|
#define GAM10 0x87 /* Gamma Curve 10th Segment Input End Point 0x50 Output Value */
|
||||||
#define GAM11 0x88 /* Gamma Curve 11th Segment Input End Point 0x60 Output Value */
|
#define GAM11 0x88 /* Gamma Curve 11th Segment Input End Point 0x60 Output Value */
|
||||||
#define GAM12 0x89 /* Gamma Curve 12th Segment Input End Point 0x70 Output Value */
|
#define GAM12 0x89 /* Gamma Curve 12th Segment Input End Point 0x70 Output Value */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user