fixed flickering on automatic exposure and added support for set_auto_exposure API
#include "omv_boardconfig.h"
#define HIMAX_BOOT_RETRY (10)
+#define HIMAX_LINE_LEN_PCK 0x172
+#define HIMAX_FRAME_LENGTH 0x232
#if (OMV_ENABLE_HM01B0 == 1)
static const uint16_t default_regs[][2] = {
{BLC_TGT, 0x08}, // BLC target :8 at 8 bit mode
@@ -43,7 +45,7 @@ static const uint16_t default_regs[][2] = {
{0x1001, 0x43}, // BLC dithering en
{0x1002, 0x43}, // blc_darkpixel_thd
- {0x0350, 0x00}, // Dgain Control
+ {0x0350, 0x7F}, // Dgain Control
{BLI_EN, 0x01}, // BLI enable
{0x1003, 0x00}, // BLI Target [Def: 0x20]
@@ -93,10 +95,10 @@ static const uint16_t default_regs[][2] = {
{FS_50HZ_L, 0x32},
{MD_CTRL, 0x30},
- {0x0340, 0x02},
- {0x0341, 0x16},
- {0x0342, 0x01},
- {0x0343, 0x78},
+ {FRAME_LEN_LINES_H, HIMAX_FRAME_LENGTH>>8},
+ {FRAME_LEN_LINES_L, HIMAX_FRAME_LENGTH&0xFF},
+ {LINE_LEN_PCK_H, HIMAX_LINE_LEN_PCK>>8},
+ {LINE_LEN_PCK_L, HIMAX_LINE_LEN_PCK&0xFF},
{0x3010, 0x00}, // no full frame
{0x0383, 0x01},
{0x0387, 0x01},
@@ -260,7 +262,20 @@ static int get_gain_db(sensor_t *sensor, float *gain_db)
static int set_auto_exposure(sensor_t *sensor, int enable, int exposure_us)
{
- return 0;
+ int ret=0;
+
+ if (enable) {
+ ret |= cambus_writeb2(&sensor->i2c, sensor->slv_addr, AE_CTRL, 1);
+ } else {
+ int coarse_int = exposure_us*(OMV_XCLK_FREQUENCY/1000000)/LINE_LEN_PCK_H;
+ if (coarse_int<2) coarse_int = 2;
+ if (coarse_int>HIMAX_FRAME_LENGTH-2) coarse_int = HIMAX_FRAME_LENGTH-2;
+ ret |= cambus_writeb2(&sensor->i2c, sensor->slv_addr, AE_CTRL, 0);
+ ret |= cambus_writeb2(&sensor->i2c, sensor->slv_addr, INTEGRATION_H, coarse_int>>8);
+ ret |= cambus_writeb2(&sensor->i2c, sensor->slv_addr, INTEGRATION_L, coarse_int&0xff);
+ }
+
+ return ret;
}
static int get_exposure_us(sensor_t *sensor, int *exposure_us)
