36#include <linux/i2c-dev.h>
37#include <linux/videodev2.h>
38#include <linux/v4l2-mediabus.h>
47#ifndef MS9v117_CROP_WIDTH
48#define MS9v117_CROP_WIDTH 240
51#ifndef MS9v117_CROP_HEIGHT
52#define MS9v117_CROP_HEIGHT 240
55#if MS9v117_CROP_WIDTH > 320 || MS9v117_CROP_HEIGHT > 240
56#error "MT9V117 crop size too large: set up the sensor for higher resolution"
76 .dev_name =
"/dev/video0",
77 .subdev_name =
"/dev/v4l-subdev0",
84 .camera_intrinsics = {
99#define MT9V117_PATCH_LINE_NUM 13
101 0xf0, 0x00, 0x72, 0xcf, 0xff, 0x00, 0x3e, 0xd0, 0x92, 0x00,
102 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0xb1, 0x10, 0x92, 0x05,
103 0xb1, 0x11, 0x92, 0x04, 0xb1, 0x12, 0x70, 0xcf, 0xff, 0x00,
104 0x30, 0xc0, 0x90, 0x00, 0x7f, 0xe0, 0xb1, 0x13, 0x70, 0xcf,
105 0xff, 0xff, 0xe7, 0x1c, 0x88, 0x36, 0x09, 0x0f, 0x00, 0xb3
109 0xf0, 0x30, 0x69, 0x13, 0xe1, 0x80, 0xd8, 0x08, 0x20, 0xca,
110 0x03, 0x22, 0x71, 0xcf, 0xff, 0xff, 0xe5, 0x68, 0x91, 0x35,
111 0x22, 0x0a, 0x1f, 0x80, 0xff, 0xff, 0xf2, 0x18, 0x29, 0x05,
112 0x00, 0x3e, 0x12, 0x22, 0x11, 0x01, 0x21, 0x04, 0x0f, 0x81,
113 0x00, 0x00, 0xff, 0xf0, 0x21, 0x8c, 0xf0, 0x10, 0x1a, 0x22
117 0xf0, 0x60, 0x10, 0x44, 0x12, 0x20, 0x11, 0x02, 0xf7, 0x87,
118 0x22, 0x4f, 0x03, 0x83, 0x1a, 0x20, 0x10, 0xc4, 0xf0, 0x09,
119 0xba, 0xae, 0x7b, 0x50, 0x1a, 0x20, 0x10, 0x84, 0x21, 0x45,
120 0x01, 0xc1, 0x1a, 0x22, 0x10, 0x44, 0x70, 0xcf, 0xff, 0x00,
121 0x3e, 0xd0, 0xb0, 0x60, 0xb0, 0x25, 0x7e, 0xe0, 0x78, 0xe0
125 0xf0, 0x90, 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x12,
126 0x72, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x8a, 0x57, 0x20, 0x04,
127 0x0f, 0x80, 0x00, 0x00, 0xff, 0xf0, 0xe2, 0x80, 0x20, 0xc5,
128 0x01, 0x61, 0x20, 0xc5, 0x03, 0x22, 0xb1, 0x12, 0x71, 0xcf,
129 0xff, 0x00, 0x3e, 0xd0, 0xb1, 0x04, 0x7e, 0xe0, 0x78, 0xe0
133 0xf0, 0xc0, 0x70, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x88, 0x57,
134 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x13, 0xea, 0x84,
135 0xb8, 0xa9, 0x78, 0x10, 0xf0, 0x03, 0xb8, 0x89, 0xb8, 0x8c,
136 0xb1, 0x13, 0x71, 0xcf, 0xff, 0x00, 0x30, 0xc0, 0xb1, 0x00,
137 0x7e, 0xe0, 0xc0, 0xf1, 0x09, 0x1e, 0x03, 0xc0, 0xc1, 0xa1
141 0xf0, 0xf0, 0x75, 0x08, 0x76, 0x28, 0x77, 0x48, 0xc2, 0x40,
142 0xd8, 0x20, 0x71, 0xcf, 0x00, 0x03, 0x20, 0x67, 0xda, 0x02,
143 0x08, 0xae, 0x03, 0xa0, 0x73, 0xc9, 0x0e, 0x25, 0x13, 0xc0,
144 0x0b, 0x5e, 0x01, 0x60, 0xd8, 0x06, 0xff, 0xbc, 0x0c, 0xce,
145 0x01, 0x00, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0x5a, 0x03, 0x20
149 0xf1, 0x20, 0xd9, 0x01, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0xb6,
150 0x03, 0x20, 0xd9, 0x01, 0x8d, 0x14, 0x08, 0x17, 0x01, 0x91,
151 0x8d, 0x16, 0xe8, 0x07, 0x0b, 0x36, 0x01, 0x60, 0xd8, 0x07,
152 0x0b, 0x52, 0x01, 0x60, 0xd8, 0x11, 0x8d, 0x14, 0xe0, 0x87,
153 0xd8, 0x00, 0x20, 0xca, 0x02, 0x62, 0x00, 0xc9, 0x03, 0xe0
157 0xf1, 0x50, 0xc0, 0xa1, 0x78, 0xe0, 0xc0, 0xf1, 0x08, 0xb2,
158 0x03, 0xc0, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x40, 0x75, 0xcf,
159 0xff, 0xff, 0xe5, 0x68, 0x95, 0x17, 0x96, 0x40, 0x77, 0xcf,
160 0xff, 0xff, 0xe5, 0x42, 0x95, 0x38, 0x0a, 0x0d, 0x00, 0x01,
161 0x97, 0x40, 0x0a, 0x11, 0x00, 0x40, 0x0b, 0x0a, 0x01, 0x00
165 0xf1, 0x80, 0x95, 0x17, 0xb6, 0x00, 0x95, 0x18, 0xb7, 0x00,
166 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x44, 0x96, 0x20, 0x95, 0x15,
167 0x08, 0x13, 0x00, 0x40, 0x0e, 0x1e, 0x01, 0x20, 0xd9, 0x00,
168 0x95, 0x15, 0xb6, 0x00, 0xff, 0xa1, 0x75, 0xcf, 0xff, 0xff,
169 0xe7, 0x1c, 0x77, 0xcf, 0xff, 0xff, 0xe5, 0x46, 0x97, 0x40
173 0xf1, 0xb0, 0x8d, 0x16, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x48,
174 0x8d, 0x37, 0x08, 0x0d, 0x00, 0x81, 0x96, 0x40, 0x09, 0x15,
175 0x00, 0x80, 0x0f, 0xd6, 0x01, 0x00, 0x8d, 0x16, 0xb7, 0x00,
176 0x8d, 0x17, 0xb6, 0x00, 0xff, 0xb0, 0xff, 0xbc, 0x00, 0x41,
177 0x03, 0xc0, 0xc0, 0xf1, 0x0d, 0x9e, 0x01, 0x00, 0xe8, 0x04
181 0xf1, 0xe0, 0xff, 0x88, 0xf0, 0x0a, 0x0d, 0x6a, 0x01, 0x00,
182 0x0d, 0x8e, 0x01, 0x00, 0xe8, 0x7e, 0xff, 0x85, 0x0d, 0x72,
183 0x01, 0x00, 0xff, 0x8c, 0xff, 0xa7, 0xff, 0xb2, 0xd8, 0x00,
184 0x73, 0xcf, 0xff, 0xff, 0xf2, 0x40, 0x23, 0x15, 0x00, 0x01,
185 0x81, 0x41, 0xe0, 0x02, 0x81, 0x20, 0x08, 0xf7, 0x81, 0x34
189 0xf2, 0x10, 0xa1, 0x40, 0xd8, 0x00, 0xc0, 0xd1, 0x7e, 0xe0,
190 0x53, 0x51, 0x30, 0x34, 0x20, 0x6f, 0x6e, 0x5f, 0x73, 0x74,
191 0x61, 0x72, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d,
192 0x69, 0x6e, 0x67, 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, 0x0a,
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
197 0xf2, 0x40, 0xff, 0xff, 0xe8, 0x28, 0xff, 0xff, 0xf0, 0xe8,
198 0xff, 0xff, 0xe8, 0x08, 0xff, 0xff, 0xf1, 0x54
228 mt->i2c_trans.buf[0] = addr >> 8;
229 mt->i2c_trans.buf[1] = addr & 0xFF;
233 mt->i2c_trans.buf[2] =
val & 0xFF;
234 }
else if (
len == 2) {
235 mt->i2c_trans.buf[2] = (
val >> 8) & 0xFF;
236 mt->i2c_trans.buf[3] =
val & 0xFF;
237 }
else if (
len == 4) {
238 mt->i2c_trans.buf[2] = (
val >> 24) & 0xFF;
239 mt->i2c_trans.buf[3] = (
val >> 16) & 0xFF;
240 mt->i2c_trans.buf[4] = (
val >> 8) & 0xFF;
241 mt->i2c_trans.buf[5] =
val & 0xFF;
243 printf(
"[MT9V117] write_reg with incorrect length %d\r\n",
len);
256 mt->i2c_trans.buf[0] = addr >> 8;
257 mt->i2c_trans.buf[1] = addr & 0xFF;
264 ret |=
mt->i2c_trans.buf[
len - i - 1] << (8 * i);
336 printf(
"[MT9V117] Applying patch failed (No OK)\r\n");
342 printf(
"[MT9V117] Applying patch failed after 10 retries\r\n");
404 printf(
"[MT9V117] Couldn't write to GPIO 129\n");
416 printf(
"[MT9V117] Couldn't write to PWM\n");
476 printf(
"[MT9V117] Switching config failed (No OK)\r\n");
485 printf(
"[MT9V117] Could not switch to new config\r\n");
static const float offset[]
enum I2CTransactionStatus i2c_blocking_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len, float timeout)
Submit a write only transaction and wait for it to complete.
enum I2CTransactionStatus i2c_blocking_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r, float timeout)
Submit a write/read transaction and wait for it to complete.
@ I2CTransDone
transaction set to done by user level
static uint8_t patch_line3[]
static uint8_t patch_line8[]
static uint8_t patch_line9[]
static const struct mt9v117_patch_t mt9v117_patch_lines[MT9V117_PATCH_LINE_NUM]
static uint8_t patch_line10[]
static uint8_t patch_line2[]
static uint8_t patch_line6[]
static uint8_t patch_line7[]
static uint8_t patch_line4[]
static uint8_t patch_line13[]
static void write_reg(struct mt9v117_t *mt, uint16_t addr, uint32_t val, uint16_t len)
Write multiple bytes to a single register.
#define MS9v117_CROP_WIDTH
static uint32_t read_reg(struct mt9v117_t *mt, uint16_t addr, uint16_t len)
Read multiple bytes from a register.
#define MS9v117_CROP_HEIGHT
static uint8_t patch_line12[]
void mt9v117_init(struct mt9v117_t *mt)
Initialisation of the Aptina MT9V117 CMOS sensor (1/6 inch VGA, bottom camera)
static void mt9v117_config(struct mt9v117_t *mt)
static uint8_t patch_line5[]
static uint8_t patch_line11[]
static void write_var(struct mt9v117_t *mt, uint16_t var, uint16_t offset, uint32_t val, uint16_t len)
static uint8_t patch_line1[]
struct video_config_t bottom_camera
static void mt9v117_write_patch(struct mt9v117_t *mt)
#define MT9V117_PATCH_LINE_NUM
static uint32_t read_var(struct mt9v117_t *mt, uint16_t var, uint16_t offset, uint16_t len)
Initialization and configuration of the MT9V117 CMOS Chip.
#define MT9V117_TARGET_FPS
#define MT9V117_TARGET_LUMA
struct i2c_periph * i2c_periph
I2C peripheral used to communicate over.
#define MT9V117_LOW_LIGHT_VAR
#define MT9V117_CAM_SENSOR_CONTROL_READ_MODE_OFFSET
#define MT9V117_COMMAND_APPLY_PATCH
#define MT9V117_CAM_SENSOR_CFG_X_ADDR_END_OFFSET
#define MT9V117_PATCHLDR_PATCH_ID_OFFSET
#define MT9V117_AE_TRACK_JUMP_DIVISOR
#define MT9V117_CAM_OUTPUT_HEIGHT_OFFSET
#define MT9V117_AE_TRACK_VAR
#define MT9V117_PATCHLDR_LOADER_ADDRESS_OFFSET
#define MT9V117_CAM_STAT_AE_INITIAL_WINDOW_XEND_OFFSET
#define MT9V117_CAM_SENSOR_CFG_TARGET_FDZONE_60_OFFSET
#define MT9V117_CAM_OUTPUT_FORMAT_OFFSET
#define MT9V117_CAM_SENSOR_CFG_Y_ADDR_END_OFFSET
#define MT9V117_CAM_STAT_AE_INITIAL_WINDOW_YEND_OFFSET
#define MT9V117_LOGICAL_ADDRESS_ACCESS
#define MT9V117_COMMAND_SET_STATE
#define MT9V117_PATCHLDR_FIRMWARE_ID_OFFSET
#define MT9V117_CAM_STAT_AE_INITIAL_WINDOW_XSTART_OFFSET
#define MT9V117_CAM_LL_STOP_GAIN_METRIC_OFFSET
#define MT9V117_RESET_SOC_I2C
#define MT9V117_CAM_SENSOR_CFG_Y_ADDR_START_OFFSET
#define MT9V117_PATCHLDR_VAR
#define MT9V117_CHIP_ID
Request the chip ID.
#define MT9V117_CAM_AET_SKIP_FRAMES
#define MT9V117_CAM_SENSOR_CFG_X_ADDR_START_OFFSET
#define MT9V117_CAM_STAT_AE_INITIAL_WINDOW_YSTART_OFFSET
#define MT9V117_CAM_STAT_AWB_HG_WINDOW_YSTART_OFFSET
#define MT9V117_CHIP_ID_RESP
Should be the response to CHIP_ID.
#define MT9V117_ADDRESS
The i2c address of the chip.
#define MT9V117_CAM_CROP_WINDOW_YOFFSET_OFFSET
#define MT9V117_CAM_CROP_MODE_OFFSET
#define MT9V117_CAM_SENSOR_CFG_FRAME_LENGTH_LINES_OFFSET
#define MT9V117_AE_RULE_ALGO_AVERAGE
#define MT9V117_CAM_SENSOR_CFG_MAX_FDZONE_60_OFFSET
#define MT9V117_COMMAND_OK
#define MT9V117_CAM_STAT_AWB_HG_WINDOW_XEND_OFFSET
#define MT9V117_CAM_SENSOR_CONTROL_Y_SKIP_EN
#define MT9V117_AE_RULE_VAR
#define MT9V117_CAM_OUTPUT_FORMAT_BT656_ENABLE
#define MT9V117_PHYSICAL_ADDRESS_ACCESS
#define MT9V117_CAM_STAT_AWB_HG_WINDOW_YEND_OFFSET
#define MT9V117_CAM_LL_START_GAIN_METRIC_OFFSET
#define MT9V117_AWB_PIXEL_THRESHOLD_COUNT_OFFSET
#define MT9V117_SYSMGR_VAR
#define MT9V117_CAM_CROP_WINDOW_WIDTH_OFFSET
#define MT9V117_CAM_CROP_WINDOW_XOFFSET_OFFSET
#define MT9V117_AE_RULE_ALGO_OFFSET
#define MT9V117_RESET_MISC_CTRL
#define MT9V117_CAM_CTRL_VAR
#define MT9V117_ACCESS_CTL_STAT
#define MT9V117_CAM_OUTPUT_WIDTH_OFFSET
#define MT9V117_SYS_STATE_ENTER_CONFIG_CHANGE
#define MT9V117_SYSMGR_NEXT_STATE_OFFSET
#define MT9V117_CAM_STAT_AWB_HG_WINDOW_XSTART_OFFSET
#define MT9V117_CAM_SENSOR_CFG_CPIPE_LAST_ROW_OFFSET
#define MT9V117_CAM_CROP_WINDOW_HEIGHT_OFFSET
struct img_size_t output_size
Output image size.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.