mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
sensors/ov7725: Add ioctl to control nightmode.
This commit is contained in:
parent
33db84ebdc
commit
abfd430854
@ -141,6 +141,8 @@ typedef enum {
|
||||
IOCTL_PAUSE_AUTO_FOCUS,
|
||||
IOCTL_RESET_AUTO_FOCUS,
|
||||
IOCTL_WAIT_ON_AUTO_FOCUS,
|
||||
IOCTL_SET_NIGHT_MODE,
|
||||
IOCTL_GET_NIGHT_MODE,
|
||||
IOCTL_LEPTON_GET_WIDTH,
|
||||
IOCTL_LEPTON_GET_HEIGHT,
|
||||
IOCTL_LEPTON_GET_RADIOMETRY,
|
||||
|
||||
@ -707,6 +707,24 @@ static mp_obj_t py_sensor_ioctl(uint n_args, const mp_obj_t *args) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (OMV_ENABLE_OV7725 == 1)
|
||||
case IOCTL_SET_NIGHT_MODE: {
|
||||
if (n_args >= 2) {
|
||||
error = sensor_ioctl(request, mp_obj_get_int(args[1]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case IOCTL_GET_NIGHT_MODE: {
|
||||
int enabled;
|
||||
error = sensor_ioctl(request, &enabled);
|
||||
if (error == 0) {
|
||||
ret_obj = mp_obj_new_bool(enabled);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case IOCTL_LEPTON_GET_WIDTH: {
|
||||
int width;
|
||||
error = sensor_ioctl(request, &width);
|
||||
@ -1082,6 +1100,10 @@ STATIC const mp_map_elem_t globals_dict_table[] = {
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_RESET_AUTO_FOCUS), MP_OBJ_NEW_SMALL_INT(IOCTL_RESET_AUTO_FOCUS)},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_WAIT_ON_AUTO_FOCUS), MP_OBJ_NEW_SMALL_INT(IOCTL_WAIT_ON_AUTO_FOCUS)},
|
||||
#endif
|
||||
#if (OMV_ENABLE_OV7725 == 1)
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_SET_NIGHT_MODE), MP_OBJ_NEW_SMALL_INT(IOCTL_SET_NIGHT_MODE)},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_GET_NIGHT_MODE), MP_OBJ_NEW_SMALL_INT(IOCTL_GET_NIGHT_MODE)},
|
||||
#endif
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_LEPTON_GET_WIDTH), MP_OBJ_NEW_SMALL_INT(IOCTL_LEPTON_GET_WIDTH)},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_LEPTON_GET_HEIGHT), MP_OBJ_NEW_SMALL_INT(IOCTL_LEPTON_GET_HEIGHT)},
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_IOCTL_LEPTON_GET_RADIOMETRY), MP_OBJ_NEW_SMALL_INT(IOCTL_LEPTON_GET_RADIOMETRY)},
|
||||
|
||||
@ -618,6 +618,38 @@ static int set_lens_correction(sensor_t *sensor, int enable, int radi, int coef)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ioctl(sensor_t *sensor, int request, va_list ap) {
|
||||
int ret = 0;
|
||||
uint8_t reg;
|
||||
|
||||
switch (request) {
|
||||
case IOCTL_SET_NIGHT_MODE: {
|
||||
int enable = va_arg(ap, int);
|
||||
ret = omv_i2c_readb(&sensor->i2c_bus, sensor->slv_addr, COM5, ®);
|
||||
ret |= omv_i2c_writeb(&sensor->i2c_bus, sensor->slv_addr, COM5, COM5_SET_AFR(reg, (enable != 0)));
|
||||
if (enable == 0) {
|
||||
ret |= omv_i2c_writeb(&sensor->i2c_bus, sensor->slv_addr, ADVFL, 0);
|
||||
ret |= omv_i2c_writeb(&sensor->i2c_bus, sensor->slv_addr, ADVFH, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IOCTL_GET_NIGHT_MODE: {
|
||||
int *enable = va_arg(ap, int *);
|
||||
ret = omv_i2c_readb(&sensor->i2c_bus, sensor->slv_addr, COM5, ®);
|
||||
if (ret >= 0) {
|
||||
*enable = reg & COM5_AFR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ov7725_init(sensor_t *sensor) {
|
||||
// Initialize sensor structure.
|
||||
sensor->reset = reset;
|
||||
@ -643,6 +675,7 @@ int ov7725_init(sensor_t *sensor) {
|
||||
sensor->set_vflip = set_vflip;
|
||||
sensor->set_special_effect = set_special_effect;
|
||||
sensor->set_lens_correction = set_lens_correction;
|
||||
sensor->ioctl = ioctl;
|
||||
|
||||
// Set sensor flags
|
||||
sensor->hw_flags.vsync = 1;
|
||||
|
||||
@ -68,6 +68,7 @@
|
||||
#define COM5_AFR_8x 0x08 /* Add frame when AGC reaches 8x gain */
|
||||
#define COM5_AFR_16x 0x0c /* Add frame when AGC reaches 16x gain */
|
||||
#define COM5_AEC_NO_LIMIT 0x01 /* No limit to AEC increase step */
|
||||
#define COM5_SET_AFR(r, x) ((r & 0x7F) | ((x & 0x1) << 7))
|
||||
|
||||
#define COM6 0x0F /* Common Control 6 */
|
||||
#define COM6_AUTO_WINDOW 0x01 /* Auto window setting ON/OFF selection when format changes */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user