Export OV7725's lens shading correction function.

This commit is contained in:
iabdalkader 2016-12-25 02:45:05 +02:00
parent ac026d0b91
commit fd384bf1b0
5 changed files with 44 additions and 6 deletions

View File

@ -101,11 +101,11 @@ static const uint8_t default_regs[][2] = {
{BDSTEP, 0x03},
// Lens Correction, should be tuned with real camera module
{LC_RADI, 0x10},
{LC_COEF, 0x10},
{LC_COEFB, 0x14},
{LC_COEFR, 0x17},
{LC_CTR, 0x05},
{LC_CTR, 0x01}, // Enable LC and use 1 coefficient for all 3 channels
{LC_RADI, 0x30}, // The radius of the circle where no compensation applies
{LC_COEF, 0x30}, // RGB Lens correction coefficient
// Frame reduction in night mode.
{COM5, 0xD5},
{0x00, 0x00},
@ -388,9 +388,20 @@ static int set_special_effect(sensor_t *sensor, sde_t sde)
return -1;
}
return 0;
return ret;
}
static int set_lens_correction(sensor_t *sensor, int enable, int radi, int coef)
{
int ret=0;
ret |= SCCB_Write(sensor->slv_addr, LC_CTR, (enable&0x01));
ret |= SCCB_Write(sensor->slv_addr, LC_RADI, radi);
ret |= SCCB_Write(sensor->slv_addr, LC_COEF, coef);
return ret;
}
int ov7725_init(sensor_t *sensor)
{
// Set function pointers
@ -409,6 +420,7 @@ int ov7725_init(sensor_t *sensor)
sensor->set_hmirror = set_hmirror;
sensor->set_vflip = set_vflip;
sensor->set_special_effect = set_special_effect;
sensor->set_lens_correction = set_lens_correction;
// Set sensor flags
SENSOR_HW_FLAGS_SET(sensor, SENSOR_HW_FLAGS_VSYNC, 1);

View File

@ -279,6 +279,13 @@ static mp_obj_t py_sensor_set_special_effect(mp_obj_t sde) {
return mp_const_true;
}
static mp_obj_t py_sensor_set_lens_correction(mp_obj_t enable, mp_obj_t radi, mp_obj_t coef) {
if (sensor_set_lens_correction(mp_obj_is_true(enable),
mp_obj_get_int(radi), mp_obj_get_int(coef)) != 0) {
return mp_const_false;
}
return mp_const_true;
}
static mp_obj_t py_sensor_write_reg(mp_obj_t addr, mp_obj_t val) {
sensor_write_reg(mp_obj_get_int(addr), mp_obj_get_int(val));
return mp_const_none;
@ -314,6 +321,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_exposure_ctrl_obj, py_sensor_se
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_hmirror_obj, py_sensor_set_hmirror);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_vflip_obj, py_sensor_set_vflip);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_set_special_effect_obj, py_sensor_set_special_effect);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(py_sensor_set_lens_correction_obj, py_sensor_set_lens_correction);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(py_sensor_write_reg_obj, py_sensor_write_reg);
STATIC MP_DEFINE_CONST_FUN_OBJ_1(py_sensor_read_reg_obj, py_sensor_read_reg);
@ -370,6 +378,7 @@ STATIC const mp_map_elem_t globals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_hmirror), (mp_obj_t)&py_sensor_set_hmirror_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_vflip), (mp_obj_t)&py_sensor_set_vflip_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_special_effect), (mp_obj_t)&py_sensor_set_special_effect_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_lens_correction), (mp_obj_t)&py_sensor_set_lens_correction_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR___write_reg), (mp_obj_t)&py_sensor_write_reg_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR___read_reg), (mp_obj_t)&py_sensor_read_reg_obj },
};

View File

@ -203,6 +203,7 @@ Q(set_exposure_ctrl)
Q(set_hmirror)
Q(set_vflip)
Q(set_special_effect)
Q(set_lens_correction)
Q(__write_reg)
Q(__read_reg)

View File

@ -563,6 +563,18 @@ int sensor_set_special_effect(sde_t sde)
return 0;
}
int sensor_set_lens_correction(int enable, int radi, int coef)
{
/* call the sensor specific function */
if (sensor.set_lens_correction == NULL
|| sensor.set_lens_correction(&sensor, enable, radi, coef) != 0) {
/* operation not supported */
return -1;
}
return 0;
}
int sensor_set_line_filter(line_filter_t line_filter_func, void *line_filter_args)
{
// Set line pre-processing function and args

View File

@ -128,6 +128,7 @@ typedef struct _sensor {
int (*set_hmirror) (sensor_t *sensor, int enable);
int (*set_vflip) (sensor_t *sensor, int enable);
int (*set_special_effect) (sensor_t *sensor, sde_t sde);
int (*set_lens_correction) (sensor_t *sensor, int enable, int radi, int coef);
} sensor_t;
// Resolution table
@ -200,6 +201,9 @@ int sensor_set_vflip(int enable);
// Set special digital effects (SDE).
int sensor_set_special_effect(sde_t sde);
// Set lens shading correction
int sensor_set_lens_correction(int enable, int radi, int coef);
// Set filter function.
int sensor_set_line_filter(line_filter_t line_filter_func, void *line_filter_args);