Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
mt9v117.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Freek van Tienen <freek.v.tienen@gmail.com>
3 *
4 * This file is part of Paparazzi.
5 *
6 * Paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * Paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 *
20 */
21
30
31#include "std.h"
32#include "mt9v117.h"
33#include "mt9v117_regs.h"
35
36#include <stdio.h>
37#include <unistd.h>
38
39#ifndef MT9V117_I2C_TRIES
40#define MT9V117_I2C_TRIES 3
41#endif
42
49static bool i2c_checked(struct i2c_periph *p, struct i2c_transaction *t, uint8_t slave, uint16_t reg,
50 uint8_t len_w, uint16_t len_r, float timeout, const char *tag)
51{
52#if SITL // no sensor in the simulator: no I2C, registers read as 0
53 for (uint16_t i = 0; i < len_r; i++) {
54 t->buf[i] = 0;
55 }
56 return true;
57#endif
58 for (int tries = 1; tries <= MT9V117_I2C_TRIES; tries++) {
59 for (int w = 0; w < 500 && (t->status == I2CTransPending || t->status == I2CTransRunning); w++) {
60 usleep(1000);
61 }
63 if (len_r > 0) {
64 t->buf[0] = reg >> 8;
65 t->buf[1] = reg & 0xFF;
66 s = i2c_blocking_transceive(p, t, slave, len_w, len_r, timeout);
67 } else {
68 s = i2c_blocking_transmit(p, t, slave, len_w, timeout);
69 }
70 if (s == I2CTransSuccess) {
71 return true;
72 }
73 fprintf(stderr, "[%s] I2C %s of 0x%04x failed (status %d, try %d of %d)\n", tag,
74 len_r > 0 ? "read" : "write", reg, s, tries, MT9V117_I2C_TRIES);
75 usleep(10000);
76 }
77 return false;
78}
79#include <fcntl.h>
80#include <sys/ioctl.h>
81#include <linux/i2c-dev.h>
82#include <linux/videodev2.h>
83#include <linux/v4l2-mediabus.h>
84
85#ifdef BOARD_DISCO
86#include "boards/disco.h"
87#else
88#include "boards/bebop.h"
89#endif
90
91
92#ifndef MS9v117_CROP_WIDTH
93#define MS9v117_CROP_WIDTH 240
94#endif
95
96#ifndef MS9v117_CROP_HEIGHT
97#define MS9v117_CROP_HEIGHT 240
98#endif
99
100#if MS9v117_CROP_WIDTH > 320 || MS9v117_CROP_HEIGHT > 240
101#error "MT9V117 crop size too large: set up the sensor for higher resolution"
102#endif
103
104
105/* Camera structure */
107 .output_size = {
110 },
111 .sensor_size = {
112 .w = 320,
113 .h = 240,
114 },
115 .crop = {
116 .x = ((320 - MS9v117_CROP_WIDTH) / 2),
117 .y = 0,
120 },
121 .dev_name = "/dev/video0",
122 .subdev_name = "/dev/v4l-subdev0",
123 .format = V4L2_PIX_FMT_UYVY,
124 .subdev_format = V4L2_MBUS_FMT_UYVY8_2X8,
125 .buf_cnt = 5,
126 .filters = 0,
127 .cv_listener = NULL,
128 .fps = MT9V117_TARGET_FPS,
129 .camera_intrinsics = {
130 .focal_x = MT9V117_FOCAL_X,
131 .focal_y = MT9V117_FOCAL_Y,
132 .center_x = MT9V117_CENTER_X,
133 .center_y = MT9V117_CENTER_Y,
134 .Dhane_k = MT9V117_DHANE_K
135 }
136};
137
139 .i2c_periph = &i2c0
140};
141
142/* Patch lines */
143//I2C_BUF_LEN must be higher then size of these patch lines
144#define MT9V117_PATCH_LINE_NUM 13
146 0xf0, 0x00, 0x72, 0xcf, 0xff, 0x00, 0x3e, 0xd0, 0x92, 0x00,
147 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0xb1, 0x10, 0x92, 0x05,
148 0xb1, 0x11, 0x92, 0x04, 0xb1, 0x12, 0x70, 0xcf, 0xff, 0x00,
149 0x30, 0xc0, 0x90, 0x00, 0x7f, 0xe0, 0xb1, 0x13, 0x70, 0xcf,
150 0xff, 0xff, 0xe7, 0x1c, 0x88, 0x36, 0x09, 0x0f, 0x00, 0xb3
151};
152
154 0xf0, 0x30, 0x69, 0x13, 0xe1, 0x80, 0xd8, 0x08, 0x20, 0xca,
155 0x03, 0x22, 0x71, 0xcf, 0xff, 0xff, 0xe5, 0x68, 0x91, 0x35,
156 0x22, 0x0a, 0x1f, 0x80, 0xff, 0xff, 0xf2, 0x18, 0x29, 0x05,
157 0x00, 0x3e, 0x12, 0x22, 0x11, 0x01, 0x21, 0x04, 0x0f, 0x81,
158 0x00, 0x00, 0xff, 0xf0, 0x21, 0x8c, 0xf0, 0x10, 0x1a, 0x22
159};
160
162 0xf0, 0x60, 0x10, 0x44, 0x12, 0x20, 0x11, 0x02, 0xf7, 0x87,
163 0x22, 0x4f, 0x03, 0x83, 0x1a, 0x20, 0x10, 0xc4, 0xf0, 0x09,
164 0xba, 0xae, 0x7b, 0x50, 0x1a, 0x20, 0x10, 0x84, 0x21, 0x45,
165 0x01, 0xc1, 0x1a, 0x22, 0x10, 0x44, 0x70, 0xcf, 0xff, 0x00,
166 0x3e, 0xd0, 0xb0, 0x60, 0xb0, 0x25, 0x7e, 0xe0, 0x78, 0xe0
167};
168
170 0xf0, 0x90, 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x12,
171 0x72, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x8a, 0x57, 0x20, 0x04,
172 0x0f, 0x80, 0x00, 0x00, 0xff, 0xf0, 0xe2, 0x80, 0x20, 0xc5,
173 0x01, 0x61, 0x20, 0xc5, 0x03, 0x22, 0xb1, 0x12, 0x71, 0xcf,
174 0xff, 0x00, 0x3e, 0xd0, 0xb1, 0x04, 0x7e, 0xe0, 0x78, 0xe0
175};
176
178 0xf0, 0xc0, 0x70, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x88, 0x57,
179 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x13, 0xea, 0x84,
180 0xb8, 0xa9, 0x78, 0x10, 0xf0, 0x03, 0xb8, 0x89, 0xb8, 0x8c,
181 0xb1, 0x13, 0x71, 0xcf, 0xff, 0x00, 0x30, 0xc0, 0xb1, 0x00,
182 0x7e, 0xe0, 0xc0, 0xf1, 0x09, 0x1e, 0x03, 0xc0, 0xc1, 0xa1
183};
184
186 0xf0, 0xf0, 0x75, 0x08, 0x76, 0x28, 0x77, 0x48, 0xc2, 0x40,
187 0xd8, 0x20, 0x71, 0xcf, 0x00, 0x03, 0x20, 0x67, 0xda, 0x02,
188 0x08, 0xae, 0x03, 0xa0, 0x73, 0xc9, 0x0e, 0x25, 0x13, 0xc0,
189 0x0b, 0x5e, 0x01, 0x60, 0xd8, 0x06, 0xff, 0xbc, 0x0c, 0xce,
190 0x01, 0x00, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0x5a, 0x03, 0x20
191};
192
194 0xf1, 0x20, 0xd9, 0x01, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0xb6,
195 0x03, 0x20, 0xd9, 0x01, 0x8d, 0x14, 0x08, 0x17, 0x01, 0x91,
196 0x8d, 0x16, 0xe8, 0x07, 0x0b, 0x36, 0x01, 0x60, 0xd8, 0x07,
197 0x0b, 0x52, 0x01, 0x60, 0xd8, 0x11, 0x8d, 0x14, 0xe0, 0x87,
198 0xd8, 0x00, 0x20, 0xca, 0x02, 0x62, 0x00, 0xc9, 0x03, 0xe0
199};
200
202 0xf1, 0x50, 0xc0, 0xa1, 0x78, 0xe0, 0xc0, 0xf1, 0x08, 0xb2,
203 0x03, 0xc0, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x40, 0x75, 0xcf,
204 0xff, 0xff, 0xe5, 0x68, 0x95, 0x17, 0x96, 0x40, 0x77, 0xcf,
205 0xff, 0xff, 0xe5, 0x42, 0x95, 0x38, 0x0a, 0x0d, 0x00, 0x01,
206 0x97, 0x40, 0x0a, 0x11, 0x00, 0x40, 0x0b, 0x0a, 0x01, 0x00
207};
208
210 0xf1, 0x80, 0x95, 0x17, 0xb6, 0x00, 0x95, 0x18, 0xb7, 0x00,
211 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x44, 0x96, 0x20, 0x95, 0x15,
212 0x08, 0x13, 0x00, 0x40, 0x0e, 0x1e, 0x01, 0x20, 0xd9, 0x00,
213 0x95, 0x15, 0xb6, 0x00, 0xff, 0xa1, 0x75, 0xcf, 0xff, 0xff,
214 0xe7, 0x1c, 0x77, 0xcf, 0xff, 0xff, 0xe5, 0x46, 0x97, 0x40
215};
216
218 0xf1, 0xb0, 0x8d, 0x16, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x48,
219 0x8d, 0x37, 0x08, 0x0d, 0x00, 0x81, 0x96, 0x40, 0x09, 0x15,
220 0x00, 0x80, 0x0f, 0xd6, 0x01, 0x00, 0x8d, 0x16, 0xb7, 0x00,
221 0x8d, 0x17, 0xb6, 0x00, 0xff, 0xb0, 0xff, 0xbc, 0x00, 0x41,
222 0x03, 0xc0, 0xc0, 0xf1, 0x0d, 0x9e, 0x01, 0x00, 0xe8, 0x04
223};
224
226 0xf1, 0xe0, 0xff, 0x88, 0xf0, 0x0a, 0x0d, 0x6a, 0x01, 0x00,
227 0x0d, 0x8e, 0x01, 0x00, 0xe8, 0x7e, 0xff, 0x85, 0x0d, 0x72,
228 0x01, 0x00, 0xff, 0x8c, 0xff, 0xa7, 0xff, 0xb2, 0xd8, 0x00,
229 0x73, 0xcf, 0xff, 0xff, 0xf2, 0x40, 0x23, 0x15, 0x00, 0x01,
230 0x81, 0x41, 0xe0, 0x02, 0x81, 0x20, 0x08, 0xf7, 0x81, 0x34
231};
232
234 0xf2, 0x10, 0xa1, 0x40, 0xd8, 0x00, 0xc0, 0xd1, 0x7e, 0xe0,
235 0x53, 0x51, 0x30, 0x34, 0x20, 0x6f, 0x6e, 0x5f, 0x73, 0x74,
236 0x61, 0x72, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d,
237 0x69, 0x6e, 0x67, 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, 0x0a,
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
239};
240
242 0xf2, 0x40, 0xff, 0xff, 0xe8, 0x28, 0xff, 0xff, 0xf0, 0xe8,
243 0xff, 0xff, 0xe8, 0x08, 0xff, 0xff, 0xf1, 0x54
244};
245
246/* Patch lines structure */
251
253 {patch_line1, sizeof(patch_line1)},
254 {patch_line2, sizeof(patch_line2)},
255 {patch_line3, sizeof(patch_line3)},
256 {patch_line4, sizeof(patch_line4)},
257 {patch_line5, sizeof(patch_line5)},
258 {patch_line6, sizeof(patch_line6)},
259 {patch_line7, sizeof(patch_line7)},
260 {patch_line8, sizeof(patch_line8)},
261 {patch_line9, sizeof(patch_line9)},
262 {patch_line10, sizeof(patch_line10)},
263 {patch_line11, sizeof(patch_line11)},
264 {patch_line12, sizeof(patch_line12)},
265 {patch_line13, sizeof(patch_line13)}
266};
267
271static void write_reg(struct mt9v117_t *mt, uint16_t addr, uint32_t val, uint16_t len)
272{
273 mt->i2c_trans.buf[0] = addr >> 8;
274 mt->i2c_trans.buf[1] = addr & 0xFF;
275
276 // Fix sigdness based on length
277 if (len == 1) {
278 mt->i2c_trans.buf[2] = val & 0xFF;
279 } else if (len == 2) {
280 mt->i2c_trans.buf[2] = (val >> 8) & 0xFF;
281 mt->i2c_trans.buf[3] = val & 0xFF;
282 } else if (len == 4) {
283 mt->i2c_trans.buf[2] = (val >> 24) & 0xFF;
284 mt->i2c_trans.buf[3] = (val >> 16) & 0xFF;
285 mt->i2c_trans.buf[4] = (val >> 8) & 0xFF;
286 mt->i2c_trans.buf[5] = val & 0xFF;
287 } else {
288 printf("[MT9V117] write_reg with incorrect length %d\r\n", len);
289 }
290
291 // Transmit the buffer
292 i2c_checked(mt->i2c_periph, &mt->i2c_trans, MT9V117_ADDRESS, addr, len + 2, 0, 0.1, "MT9V117");
293}
294
299{
300 uint32_t ret = 0;
301 mt->i2c_trans.buf[0] = addr >> 8;
302 mt->i2c_trans.buf[1] = addr & 0xFF;
303
304 // Transmit the buffer and receive back
305 i2c_checked(mt->i2c_periph, &mt->i2c_trans, MT9V117_ADDRESS, addr, 2, len, 0.1, "MT9V117");
306
307 /* Fix sigdness */
308 for (uint8_t i = 0; i < len; i++) {
309 ret |= mt->i2c_trans.buf[len - i - 1] << (8 * i);
310 }
311 return ret;
312}
313
314/* Write a byte to a var */
316{
317 uint16_t addr = 0x8000 | (var << 10) | offset;
318 write_reg(mt, addr, val, len);
319}
320
321/* Read a byte from a var */
323{
324 uint16_t addr = 0x8000 | (var << 10) | offset;
325 return read_reg(mt, addr, len);
326}
327
328static inline void mt9v117_write_patch(struct mt9v117_t *mt)
329{
330 /* Errata item 2 */
331 write_reg(mt, 0x301a, 0x10d0, 2);
332 write_reg(mt, 0x31c0, 0x1404, 2);
333 write_reg(mt, 0x3ed8, 0x879c, 2);
334 write_reg(mt, 0x3042, 0x20e1, 2);
335 write_reg(mt, 0x30d4, 0x8020, 2);
336 write_reg(mt, 0x30c0, 0x0026, 2);
337 write_reg(mt, 0x301a, 0x10d4, 2);
338
339 /* Errata item 6 */
340 write_var(mt, MT9V117_AE_TRACK_VAR, 0x0002, 0x00d3, 2);
341 write_var(mt, MT9V117_CAM_CTRL_VAR, 0x0078, 0x00a0, 2);
342 write_var(mt, MT9V117_CAM_CTRL_VAR, 0x0076, 0x0140, 2);
343
344 /* Errata item 8 */
345 write_var(mt, MT9V117_LOW_LIGHT_VAR, 0x0004, 0x00fc, 2);
346 write_var(mt, MT9V117_LOW_LIGHT_VAR, 0x0038, 0x007f, 2);
347 write_var(mt, MT9V117_LOW_LIGHT_VAR, 0x003a, 0x007f, 2);
348 write_var(mt, MT9V117_LOW_LIGHT_VAR, 0x003c, 0x007f, 2);
349 write_var(mt, MT9V117_LOW_LIGHT_VAR, 0x0004, 0x00f4, 2);
350
351 /* Patch 0403; Critical; Sensor optimization */
352 write_reg(mt, MT9V117_ACCESS_CTL_STAT, 0x0001, 2);
354
355 /* Write patch */
356 for (uint8_t i = 0; i < MT9V117_PATCH_LINE_NUM; ++i) {
357 // Copy buffer
358 for (uint8_t j = 0; j < mt9v117_patch_lines[i].len; ++j) {
359 mt->i2c_trans.buf[j] = mt9v117_patch_lines[i].data[j];
360 }
361
362 // Transmit the buffer
363 i2c_checked(mt->i2c_periph, &mt->i2c_trans, mt->i2c_trans.slave_addr, i, mt9v117_patch_lines[i].len, 0, 0.1, "MT9V117 patch");
364 }
365
371
372 /* Wait for command OK */
373 for (uint8_t retries = 100; retries > 0; retries--) {
374 /* Wait 10ms */
375 usleep(10000);
376
377 /* Check the command */
378 uint16_t cmd = read_reg(mt, MT9V117_COMMAND, 2);
379 if ((cmd & MT9V117_COMMAND_APPLY_PATCH) == 0) {
380 if ((cmd & MT9V117_COMMAND_OK) == 0) {
381 printf("[MT9V117] Applying patch failed (No OK)\r\n");
382 }
383 return;
384 }
385 }
386
387 printf("[MT9V117] Applying patch failed after 10 retries\r\n");
388}
389
390/* Configure the sensor */
391static inline void mt9v117_config(struct mt9v117_t *mt)
392{
403
406
409
410 /* Set gain metric for 111.2 fps
411 * The final fps depends on the input clock
412 * (89.2fps on bebop) so a modification may be needed here */
415
416 /* set crop window */
422
423 /* Enable auto-stats mode */
432}
433
438void mt9v117_init(struct mt9v117_t *mt)
439{
440 /* bytes written to gpios/pwm */
441 int wc = 0;
442 /* Reset the device */
443 int gpio129 = open("/sys/class/gpio/gpio129/value", O_WRONLY | O_CREAT | O_TRUNC, 0666);
444 wc += write(gpio129, "0", 1);
445 wc += write(gpio129, "1", 1);
446 close(gpio129);
447
448 if (wc != 2) {
449 printf("[MT9V117] Couldn't write to GPIO 129\n");
450 }
451
452 /* Start PWM 9 (Which probably is the clock of the MT9V117) */
453 //#define BEBOP_CAMV_PWM_FREQ 43333333
454 int pwm9 = open("/sys/class/pwm/pwm_9/run", O_WRONLY | O_CREAT | O_TRUNC, 0666);
455 wc = 0;
456 wc += write(pwm9, "0", 1);
457 wc += write(pwm9, "1", 1);
458 close(pwm9);
459
460 if (wc != 2) {
461 printf("[MT9V117] Couldn't write to PWM\n");
462 }
463
464 //TODO: Make PWM and GPIO generic
465
466 /* Wait 50ms */
467 usleep(50000);
468
469 /* Setup i2c transaction */
471
472 /* See if the device is there and correct */
473 uint16_t chip_id = read_reg(mt, MT9V117_CHIP_ID, 2);
474 if (chip_id != MT9V117_CHIP_ID_RESP) {
475 printf("[MT9V117] Didn't get correct response from CHIP_ID (expected: 0x%04X, got: 0x%04X)\r\n", MT9V117_CHIP_ID_RESP,
476 chip_id);
477 return;
478 }
479
480 /* Reset the device with software */
483
484 /* Wait 50ms */
485 usleep(50000);
486
487 /* Apply MT9V117 software patch */
489
490 /* Set basic settings */
493
494 /* Set pixclk pad slew to 6 and data out pad slew to 1 */
495 write_reg(mt, MT9V117_PAD_SLEW, read_reg(mt, MT9V117_PAD_SLEW, 2) | 0x0600 | 0x0001, 2);
496
497 /* Configure the MT9V117 sensor */
498 mt9v117_config(mt);
499
500 /* Enable ITU656 */
504
505 /* Set autoexposure luma */
507
508 /* Apply the configuration */
511
512 /* Wait for command OK */
513 for (uint8_t retries = 100; retries > 0; retries--) {
514 /* Wait 10ms */
515 usleep(10000);
516
517 /* Check the command */
518 uint16_t cmd = read_reg(mt, MT9V117_COMMAND, 2);
519 if ((cmd & MT9V117_COMMAND_SET_STATE) == 0) {
520 if ((cmd & MT9V117_COMMAND_OK) == 0) {
521 printf("[MT9V117] Switching config failed (No OK)\r\n");
522 }
523
524 // Successfully configured!
525 //printf("[MT9V117] Switching config OK\r\n");
526 return;
527 }
528 }
529
530 printf("[MT9V117] Could not switch to new config\r\n");
531}
static void h(const real32_T x[7], const real32_T q[4], real32_T y[6])
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition i2c.h:123
enum I2CTransactionStatus status
Transaction status.
Definition i2c.h:127
uint8_t slave_addr
Slave address.
Definition i2c.h:105
I2CTransactionStatus
I2C transaction status.
Definition i2c.h:55
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.
Definition i2c.c:245
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.
Definition i2c.c:265
@ I2CTransRunning
transaction is currently ongoing
Definition i2c.h:57
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition i2c.h:58
@ I2CTransDone
transaction set to done by user level
Definition i2c.h:60
@ I2CTransPending
transaction is pending in queue
Definition i2c.h:56
I2C transaction structure.
Definition i2c.h:94
static float p[2][2]
static uint32_t s
static uint8_t patch_line3[]
Definition mt9v117.c:161
uint8_t * data
Definition mt9v117.c:248
static uint8_t patch_line8[]
Definition mt9v117.c:201
#define MT9V117_I2C_TRIES
Definition mt9v117.c:40
static uint8_t patch_line9[]
Definition mt9v117.c:209
static const struct mt9v117_patch_t mt9v117_patch_lines[MT9V117_PATCH_LINE_NUM]
Definition mt9v117.c:252
static uint8_t patch_line10[]
Definition mt9v117.c:217
static uint8_t patch_line2[]
Definition mt9v117.c:153
static uint8_t patch_line6[]
Definition mt9v117.c:185
static uint8_t patch_line7[]
Definition mt9v117.c:193
static uint8_t patch_line4[]
Definition mt9v117.c:169
uint16_t len
Definition mt9v117.c:249
static uint8_t patch_line13[]
Definition mt9v117.c:241
static void write_reg(struct mt9v117_t *mt, uint16_t addr, uint32_t val, uint16_t len)
Write multiple bytes to a single register.
Definition mt9v117.c:271
#define MS9v117_CROP_WIDTH
Definition mt9v117.c:93
static uint32_t read_reg(struct mt9v117_t *mt, uint16_t addr, uint16_t len)
Read multiple bytes from a register.
Definition mt9v117.c:298
#define MS9v117_CROP_HEIGHT
Definition mt9v117.c:97
static uint8_t patch_line12[]
Definition mt9v117.c:233
void mt9v117_init(struct mt9v117_t *mt)
Initialisation of the Aptina MT9V117 CMOS sensor (1/6 inch VGA, bottom camera).
Definition mt9v117.c:438
static bool i2c_checked(struct i2c_periph *p, struct i2c_transaction *t, uint8_t slave, uint16_t reg, uint8_t len_w, uint16_t len_r, float timeout, const char *tag)
Blocking I2C transaction with result check and retry.
Definition mt9v117.c:49
static void mt9v117_config(struct mt9v117_t *mt)
Definition mt9v117.c:391
static uint8_t patch_line5[]
Definition mt9v117.c:177
static uint8_t patch_line11[]
Definition mt9v117.c:225
static void write_var(struct mt9v117_t *mt, uint16_t var, uint16_t offset, uint32_t val, uint16_t len)
Definition mt9v117.c:315
static uint8_t patch_line1[]
Definition mt9v117.c:145
static void mt9v117_write_patch(struct mt9v117_t *mt)
Definition mt9v117.c:328
struct mt9v117_t mt9v117
Definition mt9v117.c:138
#define MT9V117_PATCH_LINE_NUM
Definition mt9v117.c:144
static uint32_t read_var(struct mt9v117_t *mt, uint16_t var, uint16_t offset, uint16_t len)
Definition mt9v117.c:322
Initialization and configuration of the MT9V117 CMOS Chip.
#define MT9V117_CENTER_Y
Definition mt9v117.h:50
#define MT9V117_TARGET_FPS
Definition mt9v117.h:36
#define MT9V117_DHANE_K
Definition mt9v117.h:53
#define MT9V117_FOCAL_X
Definition mt9v117.h:41
#define MT9V117_CENTER_X
Definition mt9v117.h:47
struct i2c_transaction i2c_trans
I2C transaction for comminication with CMOS chip.
Definition mt9v117.h:61
#define MT9V117_TARGET_LUMA
Definition mt9v117.h:56
struct i2c_periph * i2c_periph
I2C peripheral used to communicate over.
Definition mt9v117.h:60
#define MT9V117_FOCAL_Y
Definition mt9v117.h:44
#define bottom_camera
Definition mt9v117_nps.c:3
#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_AE_LUMA
#define MT9V117_CHIP_ID
Request the chip ID.
Definition mt9v117_regs.h:7
#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_AWB_VAR
#define MT9V117_CAM_STAT_AWB_HG_WINDOW_YSTART_OFFSET
#define MT9V117_CHIP_ID_RESP
Should be the response to CHIP_ID.
Definition mt9v117_regs.h:8
#define MT9V117_ADDRESS
The i2c address of the chip.
Definition mt9v117_regs.h:4
#define MT9V117_CAM_CROP_WINDOW_YOFFSET_OFFSET
#define MT9V117_CAM_CROP_MODE_OFFSET
#define MT9V117_CAM_SENSOR_CFG_FRAME_LENGTH_LINES_OFFSET
#define MT9V117_PAD_SLEW
#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_COMMAND
#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
Definition mt9v117_regs.h:9
#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
static float timeout
uint16_t val[TCOUPLE_NB]
static const float offset[]
V4L2 device settings.
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.