Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
mt9f002.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 "mt9f002.h"
33#include "mt9f002_regs.h"
34#include "isp/libisp.h"
37
38#include <stdio.h>
39#include <unistd.h>
40
41#ifndef MT9F002_I2C_TRIES
42#define MT9F002_I2C_TRIES 3
43#endif
44
51static bool i2c_checked(struct i2c_periph *p, struct i2c_transaction *t, uint8_t slave, uint16_t reg,
52 uint8_t len_w, uint16_t len_r, float timeout, const char *tag)
53{
54#if SITL // no sensor in the simulator: no I2C, registers read as 0
55 for (uint16_t i = 0; i < len_r; i++) {
56 t->buf[i] = 0;
57 }
58 return true;
59#endif
60 for (int tries = 1; tries <= MT9F002_I2C_TRIES; tries++) {
61 for (int w = 0; w < 500 && (t->status == I2CTransPending || t->status == I2CTransRunning); w++) {
62 usleep(1000);
63 }
65 if (len_r > 0) {
66 t->buf[0] = reg >> 8;
67 t->buf[1] = reg & 0xFF;
68 s = i2c_blocking_transceive(p, t, slave, len_w, len_r, timeout);
69 } else {
70 s = i2c_blocking_transmit(p, t, slave, len_w, timeout);
71 }
72 if (s == I2CTransSuccess) {
73 return true;
74 }
75 fprintf(stderr, "[%s] I2C %s of 0x%04x failed (status %d, try %d of %d)\n", tag,
76 len_r > 0 ? "read" : "write", reg, s, tries, MT9F002_I2C_TRIES);
77 usleep(10000);
78 }
79 return false;
80}
81#include <fcntl.h>
82#include <sys/ioctl.h>
83#include <linux/i2c-dev.h>
84#include <linux/videodev2.h>
85
86#include "generated/airframe.h"
87#ifdef BOARD_DISCO
88#include "boards/disco.h"
89#else
90#include "boards/bebop.h"
91#endif
92
93#define PRINT(string,...) fprintf(stderr, "[MT9F002->%s()] " string,__FUNCTION__ , ##__VA_ARGS__)
94
95#if MT9F002_VERBOSE
96#define VERBOSE_PRINT PRINT
97#else
98#define VERBOSE_PRINT(...)
99#endif
100
101// The sequencing of the pixel array is controlled by the x_addr_start, y_addr_start,
102// x_addr_end, and y_addr_end registers. For both parallel and serial HiSPi interfaces, the
103// output image size is controlled by the x_output_size and y_output_size registers.
104
105// Horizontal Mirror
106// Vertical Flip
107
113#ifndef MT9F002_TARGET_EXPOSURE
114#define MT9F002_TARGET_EXPOSURE 30
115#endif
116
117/* Set the colour balance gains */
118#ifndef MT9F002_GAIN_GREEN1
119#define MT9F002_GAIN_GREEN1 2.0
120#endif
121
122#ifndef MT9F002_GAIN_GREEN2
123#define MT9F002_GAIN_GREEN2 2.0
124#endif
125
126#ifndef MT9F002_GAIN_RED
127#define MT9F002_GAIN_RED 1.4
128#endif
129
130#ifndef MT9F002_GAIN_BLUE
131#define MT9F002_GAIN_BLUE 2.7
132#endif
133
134/* Camera structure */
136 .output_size = {
139 },
140 .sensor_size = {
143 },
144 .crop = {
145 .x = 0,
146 .y = 0,
149 },
150 .dev_name = "/dev/video1",
151 .subdev_name = "/dev/v4l-subdev1",
152 .format = V4L2_PIX_FMT_UYVY,
153 .subdev_format = V4L2_MBUS_FMT_SGRBG10_1X10,
154 .buf_cnt = 5,
155 .filters = VIDEO_FILTER_ISP,
156 .cv_listener = NULL,
157 .fps = MT9F002_TARGET_FPS,
158 .camera_intrinsics = {
159 .focal_x = MT9F002_FOCAL_X,
160 .focal_y = MT9F002_FOCAL_Y,
161 .center_x = MT9F002_CENTER_X,
162 .center_y = MT9F002_CENTER_Y,
163 .Dhane_k = MT9F002_DHANE_K,
164 }
165};
166
167/* Initialize MT9F002 chipset (Front camera) */
169 // Precomputed values to go from InputCLK of (26/2)MHz to 96MH
170 .interface = MT9F002_PARALLEL,
171 .input_clk_freq = (26 / 2),
172 .vt_pix_clk_div = 7,
173 .vt_sys_clk_div = 1,
174 .pre_pll_clk_div = 1,
175 .pll_multiplier = 59,
176 .op_pix_clk_div = 8,
177 .op_sys_clk_div = 1,
179 .rowSpeed_2_0 = 1,
180 .row_speed_10_8 = 1,
181
182 // Initial values
191 .output_scaler = 1,
198 .x_odd_inc = 1,
199 .y_odd_inc = 1,
200
201 // I2C connection port
202 .i2c_periph = &i2c0,
203
204 // settings
205 .set_zoom = MT9F002_ZOOM,
206 .set_offset_x = MT9F002_OFFSET_X,
207 .set_offset_y = MT9F002_OFFSET_Y,
208};
209
217
221static void write_reg(struct mt9f002_t *mt, uint16_t addr, uint32_t val, uint8_t len)
222{
223 mt->i2c_trans.buf[0] = addr >> 8;
224 mt->i2c_trans.buf[1] = addr & 0xFF;
225
226 // Fix signdness based on length
227 if (len == 1) {
228 mt->i2c_trans.buf[2] = val & 0xFF;
229 } else if (len == 2) {
230 mt->i2c_trans.buf[2] = (val >> 8) & 0xFF;
231 mt->i2c_trans.buf[3] = val & 0xFF;
232 } else if (len == 4) {
233 mt->i2c_trans.buf[2] = (val >> 24) & 0xFF;
234 mt->i2c_trans.buf[3] = (val >> 16) & 0xFF;
235 mt->i2c_trans.buf[4] = (val >> 8) & 0xFF;
236 mt->i2c_trans.buf[5] = val & 0xFF;
237 } else {
238 PRINT("Write_reg with incorrect length %d\r\n", len);
239 }
240
241 // Transmit the buffer
242 i2c_checked(mt->i2c_periph, &mt->i2c_trans, MT9F002_ADDRESS, addr, len + 2, 0, 0.5, "MT9F002");
243}
244
248static uint32_t read_reg(struct mt9f002_t *mt, uint16_t addr, uint8_t len)
249{
250 uint32_t ret = 0;
251 mt->i2c_trans.buf[0] = addr >> 8;
252 mt->i2c_trans.buf[1] = addr & 0xFF;
253
254 // Transmit the buffer and receive back
255 i2c_checked(mt->i2c_periph, &mt->i2c_trans, MT9F002_ADDRESS, addr, 2, len, 0.5, "MT9F002");
256
257 /* Fix signdness */
258 for (uint8_t i = 0; i < len; i++) {
259 ret |= mt->i2c_trans.buf[len - i - 1] << (8 * i);
260 }
261 return ret;
262}
263
267static inline void mt9f002_mipi_stage1(struct mt9f002_t *mt)
268{
269 write_reg(mt, MT9F002_RESET_REGISTER, 0x0118, 2);
270 write_reg(mt, MT9F002_MODE_SELECT, 0x00, 1);
271
272 uint32_t serialFormat;
273 if (mt->interface == MT9F002_HiSPi) {
274 serialFormat = (3 << 8) | 2; // 2 Serial lanes
275 } else {
276 serialFormat = (2 << 8) | 2; // 2 Serial lanes
277 }
278 write_reg(mt, MT9F002_SERIAL_FORMAT, serialFormat, 2);
279 uint32_t dataFormat = (8 << 8) | 8; // 8 Bits pixel depth
280 write_reg(mt, MT9F002_CPP_DATA_FORMAT, dataFormat, 2);
281
282 write_reg(mt, MT9F002_MFR_3D00, 0x0435, 2);
283 write_reg(mt, MT9F002_MFR_3D02, 0x435D, 2);
284 write_reg(mt, MT9F002_MFR_3D04, 0x6698, 2);
285 write_reg(mt, MT9F002_MFR_3D06, 0xFFFF, 2);
286 write_reg(mt, MT9F002_MFR_3D08, 0x7783, 2);
287 write_reg(mt, MT9F002_MFR_3D0A, 0x101B, 2);
288 write_reg(mt, MT9F002_MFR_3D0C, 0x732C, 2);
289 write_reg(mt, MT9F002_MFR_3D0E, 0x4230, 2);
290 write_reg(mt, MT9F002_MFR_3D10, 0x5881, 2);
291 write_reg(mt, MT9F002_MFR_3D12, 0x5C3A, 2);
292 write_reg(mt, MT9F002_MFR_3D14, 0x0140, 2);
293 write_reg(mt, MT9F002_MFR_3D16, 0x2300, 2);
294 write_reg(mt, MT9F002_MFR_3D18, 0x815F, 2);
295 write_reg(mt, MT9F002_MFR_3D1A, 0x6789, 2);
296 write_reg(mt, MT9F002_MFR_3D1C, 0x5920, 2);
297 write_reg(mt, MT9F002_MFR_3D1E, 0x0C20, 2);
298 write_reg(mt, MT9F002_MFR_3D20, 0x21C0, 2);
299 write_reg(mt, MT9F002_MFR_3D22, 0x4684, 2);
300 write_reg(mt, MT9F002_MFR_3D24, 0x4892, 2);
301 write_reg(mt, MT9F002_MFR_3D26, 0x1A00, 2);
302 write_reg(mt, MT9F002_MFR_3D28, 0xBA4C, 2);
303 write_reg(mt, MT9F002_MFR_3D2A, 0x8D48, 2);
304 write_reg(mt, MT9F002_MFR_3D2C, 0x4641, 2);
305 write_reg(mt, MT9F002_MFR_3D2E, 0x408C, 2);
306 write_reg(mt, MT9F002_MFR_3D30, 0x4784, 2);
307 write_reg(mt, MT9F002_MFR_3D32, 0x4A87, 2);
308 write_reg(mt, MT9F002_MFR_3D34, 0x561A, 2);
309 write_reg(mt, MT9F002_MFR_3D36, 0x00A5, 2);
310 write_reg(mt, MT9F002_MFR_3D38, 0x1A00, 2);
311 write_reg(mt, MT9F002_MFR_3D3A, 0x5693, 2);
312 write_reg(mt, MT9F002_MFR_3D3C, 0x4D8D, 2);
313 write_reg(mt, MT9F002_MFR_3D3E, 0x4A47, 2);
314 write_reg(mt, MT9F002_MFR_3D40, 0x4041, 2);
315 write_reg(mt, MT9F002_MFR_3D42, 0x8200, 2);
316 write_reg(mt, MT9F002_MFR_3D44, 0x24B7, 2);
317 write_reg(mt, MT9F002_MFR_3D46, 0x0024, 2);
318 write_reg(mt, MT9F002_MFR_3D48, 0x8D4F, 2);
319 write_reg(mt, MT9F002_MFR_3D4A, 0x831A, 2);
320 write_reg(mt, MT9F002_MFR_3D4C, 0x00B4, 2);
321 write_reg(mt, MT9F002_MFR_3D4E, 0x4684, 2);
322 write_reg(mt, MT9F002_MFR_3D50, 0x49CE, 2);
323 write_reg(mt, MT9F002_MFR_3D52, 0x4946, 2);
324 write_reg(mt, MT9F002_MFR_3D54, 0x4140, 2);
325 write_reg(mt, MT9F002_MFR_3D56, 0x9247, 2);
326 write_reg(mt, MT9F002_MFR_3D58, 0x844B, 2);
327 write_reg(mt, MT9F002_MFR_3D5A, 0xCE4B, 2);
328 write_reg(mt, MT9F002_MFR_3D5C, 0x4741, 2);
329 write_reg(mt, MT9F002_MFR_3D5E, 0x502F, 2);
330 write_reg(mt, MT9F002_MFR_3D60, 0xBD3A, 2);
331 write_reg(mt, MT9F002_MFR_3D62, 0x5181, 2);
332 write_reg(mt, MT9F002_MFR_3D64, 0x5E73, 2);
333 write_reg(mt, MT9F002_MFR_3D66, 0x7C0A, 2);
334 write_reg(mt, MT9F002_MFR_3D68, 0x7770, 2);
335 write_reg(mt, MT9F002_MFR_3D6A, 0x8085, 2);
336 write_reg(mt, MT9F002_MFR_3D6C, 0x6A82, 2);
337 write_reg(mt, MT9F002_MFR_3D6E, 0x6742, 2);
338 write_reg(mt, MT9F002_MFR_3D70, 0x8244, 2);
339 write_reg(mt, MT9F002_MFR_3D72, 0x831A, 2);
340 write_reg(mt, MT9F002_MFR_3D74, 0x0099, 2);
341 write_reg(mt, MT9F002_MFR_3D76, 0x44DF, 2);
342 write_reg(mt, MT9F002_MFR_3D78, 0x1A00, 2);
343 write_reg(mt, MT9F002_MFR_3D7A, 0x8542, 2);
344 write_reg(mt, MT9F002_MFR_3D7C, 0x8567, 2);
345 write_reg(mt, MT9F002_MFR_3D7E, 0x826A, 2);
346 write_reg(mt, MT9F002_MFR_3D80, 0x857C, 2);
347 write_reg(mt, MT9F002_MFR_3D82, 0x6B80, 2);
348 write_reg(mt, MT9F002_MFR_3D84, 0x7000, 2);
349 write_reg(mt, MT9F002_MFR_3D86, 0xB831, 2);
350 write_reg(mt, MT9F002_MFR_3D88, 0x40BE, 2);
351 write_reg(mt, MT9F002_MFR_3D8A, 0x6700, 2);
352 write_reg(mt, MT9F002_MFR_3D8C, 0x0CBD, 2);
353 write_reg(mt, MT9F002_MFR_3D8E, 0x4482, 2);
354 write_reg(mt, MT9F002_MFR_3D90, 0x7898, 2);
355 write_reg(mt, MT9F002_MFR_3D92, 0x7480, 2);
356 write_reg(mt, MT9F002_MFR_3D94, 0x5680, 2);
357 write_reg(mt, MT9F002_MFR_3D96, 0x9755, 2);
358 write_reg(mt, MT9F002_MFR_3D98, 0x8057, 2);
359 write_reg(mt, MT9F002_MFR_3D9A, 0x8056, 2);
360 write_reg(mt, MT9F002_MFR_3D9C, 0x9256, 2);
361 write_reg(mt, MT9F002_MFR_3D9E, 0x8057, 2);
362 write_reg(mt, MT9F002_MFR_3DA0, 0x8055, 2);
363 write_reg(mt, MT9F002_MFR_3DA2, 0x817C, 2);
364 write_reg(mt, MT9F002_MFR_3DA4, 0x969B, 2);
365 write_reg(mt, MT9F002_MFR_3DA6, 0x56A6, 2);
366 write_reg(mt, MT9F002_MFR_3DA8, 0x44BE, 2);
367 write_reg(mt, MT9F002_MFR_3DAA, 0x000C, 2);
368 write_reg(mt, MT9F002_MFR_3DAC, 0x867A, 2);
369 write_reg(mt, MT9F002_MFR_3DAE, 0x9474, 2);
370 write_reg(mt, MT9F002_MFR_3DB0, 0x8A79, 2);
371 write_reg(mt, MT9F002_MFR_3DB2, 0x9367, 2);
372 write_reg(mt, MT9F002_MFR_3DB4, 0xBF6A, 2);
373 write_reg(mt, MT9F002_MFR_3DB6, 0x816C, 2);
374 write_reg(mt, MT9F002_MFR_3DB8, 0x8570, 2);
375 write_reg(mt, MT9F002_MFR_3DBA, 0x836C, 2);
376 write_reg(mt, MT9F002_MFR_3DBC, 0x826A, 2);
377 write_reg(mt, MT9F002_MFR_3DBE, 0x8245, 2);
378 write_reg(mt, MT9F002_MFR_3DC0, 0xFFFF, 2);
379 write_reg(mt, MT9F002_MFR_3DC2, 0xFFD6, 2);
380 write_reg(mt, MT9F002_MFR_3DC4, 0x4582, 2);
381 write_reg(mt, MT9F002_MFR_3DC6, 0x6A82, 2);
382 write_reg(mt, MT9F002_MFR_3DC8, 0x6C83, 2);
383 write_reg(mt, MT9F002_MFR_3DCA, 0x7000, 2);
384 write_reg(mt, MT9F002_MFR_3DCC, 0x8024, 2);
385 write_reg(mt, MT9F002_MFR_3DCE, 0xB181, 2);
386 write_reg(mt, MT9F002_MFR_3DD0, 0x6859, 2);
387 write_reg(mt, MT9F002_MFR_3DD2, 0x732B, 2);
388 write_reg(mt, MT9F002_MFR_3DD4, 0x4030, 2);
389 write_reg(mt, MT9F002_MFR_3DD6, 0x4982, 2);
390 write_reg(mt, MT9F002_MFR_3DD8, 0x101B, 2);
391 write_reg(mt, MT9F002_MFR_3DDA, 0x4083, 2);
392 write_reg(mt, MT9F002_MFR_3DDC, 0x6785, 2);
393 write_reg(mt, MT9F002_MFR_3DDE, 0x3A00, 2);
394 write_reg(mt, MT9F002_MFR_3DE0, 0x8820, 2);
395 write_reg(mt, MT9F002_MFR_3DE2, 0x0C59, 2);
396 write_reg(mt, MT9F002_MFR_3DE4, 0x8546, 2);
397 write_reg(mt, MT9F002_MFR_3DE6, 0x8348, 2);
398 write_reg(mt, MT9F002_MFR_3DE8, 0xD04C, 2);
399 write_reg(mt, MT9F002_MFR_3DEA, 0x8B48, 2);
400 write_reg(mt, MT9F002_MFR_3DEC, 0x4641, 2);
401 write_reg(mt, MT9F002_MFR_3DEE, 0x4083, 2);
402 write_reg(mt, MT9F002_MFR_3DF0, 0x1A00, 2);
403 write_reg(mt, MT9F002_MFR_3DF2, 0x8347, 2);
404 write_reg(mt, MT9F002_MFR_3DF4, 0x824A, 2);
405 write_reg(mt, MT9F002_MFR_3DF6, 0x9A56, 2);
406 write_reg(mt, MT9F002_MFR_3DF8, 0x1A00, 2);
407 write_reg(mt, MT9F002_MFR_3DFA, 0x951A, 2);
408 write_reg(mt, MT9F002_MFR_3DFC, 0x0056, 2);
409 write_reg(mt, MT9F002_MFR_3DFE, 0x914D, 2);
410 write_reg(mt, MT9F002_MFR_3E00, 0x8B4A, 2);
411 write_reg(mt, MT9F002_MFR_3E02, 0x4700, 2);
412 write_reg(mt, MT9F002_MFR_3E04, 0x0300, 2);
413 write_reg(mt, MT9F002_MFR_3E06, 0x2492, 2);
414 write_reg(mt, MT9F002_MFR_3E08, 0x0024, 2);
415 write_reg(mt, MT9F002_MFR_3E0A, 0x8A1A, 2);
416 write_reg(mt, MT9F002_MFR_3E0C, 0x004F, 2);
417 write_reg(mt, MT9F002_MFR_3E0E, 0xB446, 2);
418 write_reg(mt, MT9F002_MFR_3E10, 0x8349, 2);
419 write_reg(mt, MT9F002_MFR_3E12, 0xB249, 2);
420 write_reg(mt, MT9F002_MFR_3E14, 0x4641, 2);
421 write_reg(mt, MT9F002_MFR_3E16, 0x408B, 2);
422 write_reg(mt, MT9F002_MFR_3E18, 0x4783, 2);
423 write_reg(mt, MT9F002_MFR_3E1A, 0x4BDB, 2);
424 write_reg(mt, MT9F002_MFR_3E1C, 0x4B47, 2);
425 write_reg(mt, MT9F002_MFR_3E1E, 0x4180, 2);
426 write_reg(mt, MT9F002_MFR_3E20, 0x502B, 2);
427 write_reg(mt, MT9F002_MFR_3E22, 0x4C3A, 2);
428 write_reg(mt, MT9F002_MFR_3E24, 0x4180, 2);
429 write_reg(mt, MT9F002_MFR_3E26, 0x737C, 2);
430 write_reg(mt, MT9F002_MFR_3E28, 0xD124, 2);
431 write_reg(mt, MT9F002_MFR_3E2A, 0x9068, 2);
432 write_reg(mt, MT9F002_MFR_3E2C, 0x8A20, 2);
433 write_reg(mt, MT9F002_MFR_3E2E, 0x2170, 2);
434 write_reg(mt, MT9F002_MFR_3E30, 0x8081, 2);
435 write_reg(mt, MT9F002_MFR_3E32, 0x6A67, 2);
436 write_reg(mt, MT9F002_MFR_3E34, 0x4257, 2);
437 write_reg(mt, MT9F002_MFR_3E36, 0x5544, 2);
438 write_reg(mt, MT9F002_MFR_3E38, 0x8644, 2);
439 write_reg(mt, MT9F002_MFR_3E3A, 0x9755, 2);
440 write_reg(mt, MT9F002_MFR_3E3C, 0x5742, 2);
441 write_reg(mt, MT9F002_MFR_3E3E, 0x676A, 2);
442 write_reg(mt, MT9F002_MFR_3E40, 0x807D, 2);
443 write_reg(mt, MT9F002_MFR_3E42, 0x3180, 2);
444 write_reg(mt, MT9F002_MFR_3E44, 0x7000, 2);
445 write_reg(mt, MT9F002_MFR_3E46, 0x0000, 2);
446 write_reg(mt, MT9F002_MFR_3E48, 0x0000, 2);
447 write_reg(mt, MT9F002_MFR_3E4A, 0x0000, 2);
448 write_reg(mt, MT9F002_MFR_3E4C, 0x0000, 2);
449 write_reg(mt, MT9F002_MFR_3E4E, 0x0000, 2);
450 write_reg(mt, MT9F002_MFR_3E50, 0x0000, 2);
451 write_reg(mt, MT9F002_MFR_3E52, 0x0000, 2);
452 write_reg(mt, MT9F002_MFR_3E54, 0x0000, 2);
453 write_reg(mt, MT9F002_MFR_3E56, 0x0000, 2);
454 write_reg(mt, MT9F002_MFR_3E58, 0x0000, 2);
455 write_reg(mt, MT9F002_MFR_3E5A, 0x0000, 2);
456 write_reg(mt, MT9F002_MFR_3E5C, 0x0000, 2);
457 write_reg(mt, MT9F002_MFR_3E5E, 0x0000, 2);
458 write_reg(mt, MT9F002_MFR_3E60, 0x0000, 2);
459 write_reg(mt, MT9F002_MFR_3E62, 0x0000, 2);
460 write_reg(mt, MT9F002_MFR_3E64, 0x0000, 2);
461 write_reg(mt, MT9F002_MFR_3E66, 0x0000, 2);
462 write_reg(mt, MT9F002_MFR_3E68, 0x0000, 2);
463 write_reg(mt, MT9F002_MFR_3E6A, 0x0000, 2);
464 write_reg(mt, MT9F002_MFR_3E6C, 0x0000, 2);
465 write_reg(mt, MT9F002_MFR_3E6E, 0x0000, 2);
466 write_reg(mt, MT9F002_MFR_3E70, 0x0000, 2);
467 write_reg(mt, MT9F002_MFR_3E72, 0x0000, 2);
468 write_reg(mt, MT9F002_MFR_3E74, 0x0000, 2);
469 write_reg(mt, MT9F002_MFR_3E76, 0x0000, 2);
470 write_reg(mt, MT9F002_MFR_3E78, 0x0000, 2);
471 write_reg(mt, MT9F002_MFR_3E7A, 0x0000, 2);
472 write_reg(mt, MT9F002_MFR_3E7C, 0x0000, 2);
473 write_reg(mt, MT9F002_MFR_3E7E, 0x0000, 2);
474 write_reg(mt, MT9F002_MFR_3E80, 0x0000, 2);
475 write_reg(mt, MT9F002_MFR_3E82, 0x0000, 2);
476 write_reg(mt, MT9F002_MFR_3E84, 0x0000, 2);
477 write_reg(mt, MT9F002_MFR_3E86, 0x0000, 2);
478 write_reg(mt, MT9F002_MFR_3E88, 0x0000, 2);
479 write_reg(mt, MT9F002_MFR_3E8A, 0x0000, 2);
480 write_reg(mt, MT9F002_MFR_3E8C, 0x0000, 2);
481 write_reg(mt, MT9F002_MFR_3E8E, 0x0000, 2);
482 write_reg(mt, MT9F002_MFR_3E90, 0x0000, 2);
483 write_reg(mt, MT9F002_MFR_3E92, 0x0000, 2);
484 write_reg(mt, MT9F002_MFR_3E94, 0x0000, 2);
485 write_reg(mt, MT9F002_MFR_3E96, 0x0000, 2);
486 write_reg(mt, MT9F002_MFR_3E98, 0x0000, 2);
487 write_reg(mt, MT9F002_MFR_3E9A, 0x0000, 2);
488 write_reg(mt, MT9F002_MFR_3E9C, 0x0000, 2);
489 write_reg(mt, MT9F002_MFR_3E9E, 0x0000, 2);
490 write_reg(mt, MT9F002_MFR_3EA0, 0x0000, 2);
491 write_reg(mt, MT9F002_MFR_3EA2, 0x0000, 2);
492 write_reg(mt, MT9F002_MFR_3EA4, 0x0000, 2);
493 write_reg(mt, MT9F002_MFR_3EA6, 0x0000, 2);
494 write_reg(mt, MT9F002_MFR_3EA8, 0x0000, 2);
495 write_reg(mt, MT9F002_MFR_3EAA, 0x0000, 2);
496 write_reg(mt, MT9F002_MFR_3EAC, 0x0000, 2);
497 write_reg(mt, MT9F002_MFR_3EAE, 0x0000, 2);
498 write_reg(mt, MT9F002_MFR_3EB0, 0x0000, 2);
499 write_reg(mt, MT9F002_MFR_3EB2, 0x0000, 2);
500 write_reg(mt, MT9F002_MFR_3EB4, 0x0000, 2);
501 write_reg(mt, MT9F002_MFR_3EB6, 0x0000, 2);
502 write_reg(mt, MT9F002_MFR_3EB8, 0x0000, 2);
503 write_reg(mt, MT9F002_MFR_3EBA, 0x0000, 2);
504 write_reg(mt, MT9F002_MFR_3EBC, 0x0000, 2);
505 write_reg(mt, MT9F002_MFR_3EBE, 0x0000, 2);
506 write_reg(mt, MT9F002_MFR_3EC0, 0x0000, 2);
507 write_reg(mt, MT9F002_MFR_3EC2, 0x0000, 2);
508 write_reg(mt, MT9F002_MFR_3EC4, 0x0000, 2);
509 write_reg(mt, MT9F002_MFR_3EC6, 0x0000, 2);
510 write_reg(mt, MT9F002_MFR_3EC8, 0x0000, 2);
511 write_reg(mt, MT9F002_MFR_3ECA, 0x0000, 2);
512 write_reg(mt, MT9F002_MFR_3176, 0x4000, 2);
513 write_reg(mt, MT9F002_MFR_317C, 0xA00A, 2);
514 write_reg(mt, MT9F002_MFR_3EE6, 0x0000, 2);
515 write_reg(mt, MT9F002_MFR_3ED8, 0xE0E0, 2);
516 write_reg(mt, MT9F002_MFR_3EE8, 0x0001, 2);
517 write_reg(mt, MT9F002_SMIA_TEST, 0x0005, 2);
518}
519
523static inline void mt9f002_mipi_stage2(struct mt9f002_t *mt)
524{
525 write_reg(mt, MT9F002_SMIA_TEST, 0x0045, 2);
526}
527
531static inline void mt9f002_mipi_stage3(struct mt9f002_t *mt)
532{
533 write_reg(mt, MT9F002_EXTRA_DELAY, 0x0000, 2);
534 write_reg(mt, MT9F002_RESET_REGISTER, 0x0118, 2);
535 write_reg(mt, MT9F002_MFR_3EDC, 0x68CF, 2);
536 write_reg(mt, MT9F002_MFR_3EE2, 0xE363, 2);
537}
538
542static inline void mt9f002_parallel_stage1(struct mt9f002_t *mt)
543{
544 write_reg(mt, MT9F002_RESET_REGISTER , 0x0010, 2);
545 write_reg(mt, MT9F002_GLOBAL_GAIN , 0x1430, 2);
546 write_reg(mt, MT9F002_RESET_REGISTER , 0x0010, 2);
547 write_reg(mt, MT9F002_RESET_REGISTER , 0x0010, 2);
548 write_reg(mt, MT9F002_RESET_REGISTER , 0x0010, 2);
549 write_reg(mt, MT9F002_DAC_LD_14_15 , 0xE525, 2);
550 write_reg(mt, MT9F002_CTX_CONTROL_REG, 0x0000, 2);
551 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xF873, 2);
552 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x08AA, 2);
553 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x3219, 2);
554 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x3219, 2);
555 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x3219, 2);
556 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x3200, 2);
557 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x3200, 2);
558 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x3200, 2);
559 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x3200, 2);
560 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x3200, 2);
561 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x1769, 2);
562 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA6F3, 2);
563 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA6F3, 2);
564 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA6F3, 2);
565 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA6F3, 2);
566 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA6F3, 2);
567 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA6F3, 2);
568 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA6F3, 2);
569 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xAFF3, 2);
570 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xFA64, 2);
571 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xFA64, 2);
572 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xFA64, 2);
573 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xF164, 2);
574 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xFA64, 2);
575 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xFA64, 2);
576 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xFA64, 2);
577 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xF164, 2);
578 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x276E, 2);
579 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x18CF, 2);
580 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x18CF, 2);
581 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x18CF, 2);
582 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x28CF, 2);
583 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x18CF, 2);
584 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x18CF, 2);
585 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x18CF, 2);
586 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x18CF, 2);
587 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x2363, 2);
588 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x2363, 2);
589 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x2352, 2);
590 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x2363, 2);
591 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x2363, 2);
592 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x2363, 2);
593 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x2352, 2);
594 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x2352, 2);
595 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA394, 2);
596 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA394, 2);
597 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x8F8F, 2);
598 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA3D4, 2);
599 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA394, 2);
600 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xA394, 2);
601 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x8F8F, 2);
602 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x8FCF, 2);
603 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xDC23, 2);
604 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xDC63, 2);
605 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xDC63, 2);
606 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xDC23, 2);
607 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xDC23, 2);
608 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xDC63, 2);
609 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xDC63, 2);
610 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0xDC23, 2);
611 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x0F73, 2);
612 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x85C0, 2);
613 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x85C0, 2);
614 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x85C0, 2);
615 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x85C0, 2);
616 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x85C0, 2);
617 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x85C0, 2);
618 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x85C0, 2);
619 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x85C4, 2);
620 write_reg(mt, MT9F002_CTX_WR_DATA_REG, 0x0000, 2);
621 write_reg(mt, MT9F002_ANALOG_CONTROL4, 0x8000, 2);
622 write_reg(mt, MT9F002_DAC_LD_14_15 , 0xE525, 2);
623 write_reg(mt, MT9F002_DATA_PEDESTAL_ , 0x00A8, 2);
624 write_reg(mt, MT9F002_RESET_REGISTER , 0x0090, 2);
625 write_reg(mt, MT9F002_SERIAL_FORMAT , 0x0301, 2);
626 write_reg(mt, MT9F002_RESET_REGISTER , 0x1090, 2);
627 write_reg(mt, MT9F002_SMIA_TEST , 0x0845, 2);
628 write_reg(mt, MT9F002_RESET_REGISTER , 0x1080, 2);
629 write_reg(mt, MT9F002_DATAPATH_SELECT, 0xD880, 2);
630 write_reg(mt, MT9F002_RESET_REGISTER , 0x9080, 2);
631 write_reg(mt, MT9F002_DATAPATH_SELECT, 0xD880, 2);
632 write_reg(mt, MT9F002_RESET_REGISTER , 0x10C8, 2);
633 write_reg(mt, MT9F002_DATAPATH_SELECT, 0xD880, 2);
634}
635
639static inline void mt9f002_parallel_stage2(struct mt9f002_t *mt)
640{
641 write_reg(mt, MT9F002_ANALOG_CONTROL4, 0x8000, 2);
642 write_reg(mt, MT9F002_READ_MODE, 0x0041, 2);
643
644 write_reg(mt, MT9F002_READ_MODE , 0x04C3, 2);
645 write_reg(mt, MT9F002_READ_MODE , 0x04C3, 2);
646 write_reg(mt, MT9F002_ANALOG_CONTROL5 , 0x0000, 2);
647 write_reg(mt, MT9F002_ANALOG_CONTROL5 , 0x0000, 2);
648 write_reg(mt, MT9F002_ANALOG_CONTROL5 , 0x0000, 2);
649 write_reg(mt, MT9F002_ANALOG_CONTROL5 , 0x0000, 2);
650 write_reg(mt, MT9F002_DAC_LD_28_29 , 0x0047, 2);
651 write_reg(mt, MT9F002_COLUMN_CORRECTION , 0xB080, 2);
652 write_reg(mt, MT9F002_COLUMN_CORRECTION , 0xB100, 2);
653 write_reg(mt, MT9F002_DARK_CONTROL3 , 0x0020, 2);
654 write_reg(mt, MT9F002_DAC_LD_24_25 , 0x6349, 2);
655 write_reg(mt, MT9F002_ANALOG_CONTROL7 , 0x800A, 2);
656 write_reg(mt, MT9F002_RESET_REGISTER , 0x90C8, 2);
657 write_reg(mt, MT9F002_CTX_CONTROL_REG , 0x8005, 2);
658 write_reg(mt, MT9F002_ANALOG_CONTROL7 , 0x800A, 2);
659 write_reg(mt, MT9F002_DAC_LD_28_29 , 0x0047, 2);
660 write_reg(mt, MT9F002_DAC_LD_30_31 , 0x15F0, 2);
661 write_reg(mt, MT9F002_DAC_LD_30_31 , 0x15F0, 2);
662 write_reg(mt, MT9F002_DAC_LD_30_31 , 0x15F0, 2);
663 write_reg(mt, MT9F002_DAC_LD_28_29 , 0x0047, 2);
664 write_reg(mt, MT9F002_DAC_LD_28_29 , 0x0047, 2);
665 write_reg(mt, MT9F002_RESET_REGISTER , 0x10C8, 2);
666 //write_reg(mt, MT9F002_RESET_REGISTER , 0x14C8, 2); // reset bad frame
668 write_reg(mt, MT9F002_DIGITAL_TEST, 0x0000 , 2);
669 //write_reg(mt, MT9F002_DATAPATH_SELECT , 0xd881, 2); // permanent line valid
670 write_reg(mt, MT9F002_DATAPATH_SELECT, 0xd880, 2);
671 write_reg(mt, MT9F002_MASK_CORRUPTED_FRAMES , 0x0001, 1); // 0 output corrupted frame, 1 mask them
672}
673
677static inline void mt9f002_set_pll(struct mt9f002_t *mt)
678{
679 // Update registers
686
687 uint16_t smia = read_reg(mt, MT9F002_SMIA_TEST, 2);
688 write_reg(mt, MT9F002_SMIA_TEST, (smia & 0xFFBF) | (mt->shift_vt_pix_clk_div << 6), 2); // shift_vt_pix_clk_div
689
690 uint16_t row_speed = read_reg(mt, MT9F002_ROW_SPEED, 2);
691 row_speed = (row_speed & 0xFFF8) | (mt->rowSpeed_2_0 & 0x07); // rowSpeed_2_0
692 row_speed = (row_speed & 0xF8FF) | ((mt->row_speed_10_8 & 0x07) << 8); // row_speed_10_8
693 row_speed = (row_speed & (~0x70)) | (0x2 << 4); // Change opclk_delay
694 write_reg(mt, MT9F002_ROW_SPEED, row_speed, 2);
695
696 // Compute clocks
697 mt->vt_pix_clk = mt->input_clk_freq * (float)mt->pll_multiplier * (float)(1 + mt->shift_vt_pix_clk_div)
698 / ((float)mt->pre_pll_clk_div * (float)mt->vt_sys_clk_div * (float)mt->vt_pix_clk_div);
699 mt->op_pix_clk = mt->input_clk_freq * (float)mt->pll_multiplier
700 / ((float)mt->pre_pll_clk_div * (float)mt->op_sys_clk_div * (float)mt->op_pix_clk_div);
701}
702
703// set the frame rate of the camera
704static void mt9f002_set_blanking(struct mt9f002_t *mt)
705{
706 //Set the blanking configuration
707 if (mt->x_odd_inc > 1) {
708 if (mt->y_odd_inc > 1) {
709 /* Binning XY */
710 mt9f002_blanking.min_line_blanking_pck = 2950;
711 mt9f002_blanking.min_line_length_pck = 4650;
712 mt9f002_blanking.min_line_fifo_pck = 120;
713 mt9f002_blanking.fine_integration_time_max_margin = 2000;
714 mt9f002_blanking.fine_integration_time_min = 2200;
715 } else {
716 /* Binning X */
717 mt9f002_blanking.min_line_blanking_pck = 0;
718 mt9f002_blanking.min_line_length_pck = 3495;
719 mt9f002_blanking.min_line_fifo_pck = 60;
720 mt9f002_blanking.fine_integration_time_max_margin = 1500;
721 mt9f002_blanking.fine_integration_time_min = 1900;
722 }
723 } else {
724 mt9f002_blanking.fine_integration_time_max_margin = 1316;
725 mt9f002_blanking.fine_integration_time_min = 1032;
726 mt9f002_blanking.min_line_fifo_pck = 60;
727 if (mt->output_scaler > 1) {
728 /* Scaler mode */
729 mt9f002_blanking.min_line_blanking_pck = 2400;
730 mt9f002_blanking.min_line_length_pck = 1750;
731 } else {
732 /* Normal mode */
733 mt9f002_blanking.min_line_blanking_pck = 1316;
734 mt9f002_blanking.min_line_length_pck = 1032;
735 }
736 }
737
738 uint16_t x_addr_start = read_reg(mt, MT9F002_X_ADDR_START, 2);
739 uint16_t x_addr_end = read_reg(mt, MT9F002_X_ADDR_END, 2);
740
741 float subsamplingX_factor = (float)(1 + mt->x_odd_inc) / 2.0f; // See page 52
742 float subsamplingY_factor = (float)(1 + mt->y_odd_inc) / 2.0f; // See page 52
743
744 /* Calculate minimum line length based on p. 53 */
745 // line length based on window width
746 uint16_t min_line_length = (uint16_t)((x_addr_end - x_addr_start + mt->x_odd_inc) / subsamplingX_factor / 2) +
747 mt9f002_blanking.min_line_blanking_pck;
748
749 // must be strictly longer than min length set in the min_line_length_pck register
750 min_line_length = Max(min_line_length, mt9f002_blanking.min_line_length_pck + 1);
751
752 // row time must be strictly larger than the time needed for the FIFO to output the data
753 if (mt->interface == MT9F002_MIPI || mt->interface == MT9F002_HiSPi) {
754 // 2 lanes, pll clocks
755 min_line_length = Max(min_line_length,
756 (mt->output_width * mt->vt_pix_clk / mt->op_pix_clk / 2) + mt9f002_blanking.min_line_fifo_pck + 1);
757 } else {
758 // pll clocks
759 min_line_length = Max(min_line_length,
760 (mt->output_width * mt->vt_pix_clk / mt->op_pix_clk) + mt9f002_blanking.min_line_fifo_pck + 1);
761 }
762
763 /* Do some magic to get it to work with P7 ISP (with horizontal blanking) */
764 uint32_t clkRatio_num = mt->op_sys_clk_div * mt->op_pix_clk_div * mt->row_speed_10_8 * (1 + mt->shift_vt_pix_clk_div);
765 uint32_t clkRatio_den = mt->vt_sys_clk_div * mt->vt_pix_clk_div;
766
767 /* Divide by the GCD to find smallest ratio */
768 uint32_t clkRatio_gcd = int32_gcd(clkRatio_num, clkRatio_den);
769 clkRatio_num = clkRatio_num / clkRatio_gcd;
770 clkRatio_den = clkRatio_den / clkRatio_gcd;
771
772 /* Calculate minimum horizontal blanking, since fpga line_length must be divisible by 2 */
773 uint32_t min_horizontal_blanking = clkRatio_num;
774 if ((clkRatio_den % 2) != 0) {
775 min_horizontal_blanking *= 2;
776 }
777
778 /* Fix fpga correction based on min horizontal blanking */
779 if ((min_line_length % min_horizontal_blanking) != 0) {
780 min_line_length += min_horizontal_blanking - (min_line_length % min_horizontal_blanking);
781 }
782 mt->line_length = min_line_length;
783
784 /* Calculate minimum frame length lines */
785 uint16_t y_addr_start = read_reg(mt, MT9F002_Y_ADDR_START, 2);
786 uint16_t y_addr_end = read_reg(mt, MT9F002_Y_ADDR_END, 2);
787 uint16_t min_frame_blanking_lines = read_reg(mt, MT9F002_MIN_FRAME_BLANKING_LINES, 2);
788 // frame time is limited by total number of rows (EQ 10)
789 uint16_t min_frame_length = (y_addr_end - y_addr_start + 1) / subsamplingY_factor + min_frame_blanking_lines;
790 mt->frame_length = min_frame_length;
791
792 /* Calculate FPS we get using these minimums (Maximum FPS) */
793 mt->real_fps = mt->vt_pix_clk * 1e6 / (float)(mt->line_length * mt->frame_length);
794 VERBOSE_PRINT("Maximum FPS: %0.3f\n", mt->real_fps);
795
796 /* Check if we need to downscale the FPS and bruteforce better solution */
797 if (mt->target_fps > 0 && mt->target_fps < mt->real_fps) {
798 float min_fps_err = mt->real_fps - mt->target_fps;
799 float new_fps = mt->real_fps;
800
801 // Go through all possible line lengths
802 for (uint32_t ll = min_line_length; ll <= MT9F002_LINE_LENGTH_MAX; ll += min_horizontal_blanking) {
803 // Go through all possible frame lengths
804 for (uint32_t fl = min_frame_length; fl < MT9F002_FRAME_LENGTH_MAX; fl++) {
805 new_fps = mt->vt_pix_clk * 1000000 / (float)(ll * fl);
806
807 // Calculate FPS error and save if it is better
808 float fps_err = new_fps - mt->target_fps;
809
810 // Stop searching if FPS is lower or equal
811 if (fps_err < 0) {
812 break;
813 }
814
815 if (fps_err < min_fps_err) {
816 min_fps_err = fps_err;
817 mt->line_length = ll;
818 mt->frame_length = fl;
819 mt->real_fps = new_fps;
820 }
821 }
822
823 // Calculate if next step is still needed (since we only need to go one step below target_fps)
824 new_fps = mt->vt_pix_clk * 1000000 / (float)(ll * min_frame_length);
825
826 // Stop searching if FPS is lower or equal
827 if (new_fps - mt->target_fps <= 0.f) {
828 break;
829 }
830 }
831 }
832
833 VERBOSE_PRINT("Set FPS: %0.3f\n", mt->vt_pix_clk * 1000000 / (float)(mt->line_length * mt->frame_length));
834
835 /* Actually set the calculated values */
838}
839
845{
846 /* Fetch minimum and maximum integration times */
847 uint16_t coarse_integration_min = read_reg(mt, MT9F002_COARSE_INTEGRATION_TIME_MIN, 2);
848 uint16_t coarse_integration_max = mt->frame_length - read_reg(mt, MT9F002_COARSE_INTEGRATION_TIME_MAX_MARGIN, 2);
849 uint16_t fine_integration_min = mt9f002_blanking.fine_integration_time_min;
850 uint16_t fine_integration_max_margin = mt9f002_blanking.fine_integration_time_max_margin;
851 uint16_t fine_integration_max = mt->line_length - fine_integration_max_margin;
852
853 /* Compute fine and coarse integration time */
854 uint32_t integration = mt->target_exposure * mt->vt_pix_clk * 1000;
855 uint16_t coarse_integration = integration / mt->line_length;
856 uint16_t fine_integration = integration % mt->line_length;
857
858 /* Make sure fine integration is inside bounds */
859 if (fine_integration_min > fine_integration || fine_integration > fine_integration_max) {
860 int32_t upper_coarse_integration = coarse_integration + 1;
861 int32_t upper_fine_integration = fine_integration_min;
862
863 int32_t lower_coarse_integration = coarse_integration - 1;
864 int32_t lower_fine_integration = fine_integration_max;
865
866 // Check if lower case is invalid (take upper coarse)
867 if (lower_coarse_integration < coarse_integration_min) {
868 coarse_integration = upper_coarse_integration;
869 fine_integration = upper_fine_integration;
870 }
871 // Check if upper case is invalid (take lower coarse)
872 else if (upper_coarse_integration > coarse_integration_max) {
873 coarse_integration = lower_coarse_integration;
874 fine_integration = lower_fine_integration;
875 }
876 // Both are good
877 else {
878 // Calculate error to decide which is better
879 int32_t upper_error = abs((mt->line_length * upper_coarse_integration + upper_fine_integration) - (int32_t)integration);
880 int32_t lower_error = abs((mt->line_length * lower_coarse_integration + lower_fine_integration) - (int32_t)integration);
881
882 if (upper_error < lower_error) {
883 coarse_integration = upper_coarse_integration;
884 fine_integration = upper_fine_integration;
885 } else {
886 coarse_integration = lower_coarse_integration;
887 fine_integration = lower_fine_integration;
888 }
889 }
890 }
891
892 /* Fix saturations */
893 Bound(fine_integration, fine_integration_min, fine_integration_max);
894 Bound(coarse_integration, coarse_integration_min, coarse_integration_max);
895
896 /* Set the registers */
897 mt->real_exposure = (float)(coarse_integration * mt->line_length + fine_integration) / (mt->vt_pix_clk * 1000);
898 write_reg(mt, MT9F002_COARSE_INTEGRATION_TIME, coarse_integration, 2);
899 write_reg(mt, MT9F002_FINE_INTEGRATION_TIME_, fine_integration, 2);
900}
901
905static uint16_t mt9f002_calc_gain(float gain)
906{
907 // Check if gain is valid
908 if (gain < 1.0) {
909 gain = 1.0;
910 }
911
912 // Calculation of colamp, analg3 and digital gain based on table 19 p56
913 uint8_t colamp_gain, analog_gain3, digital_gain;
914 if (gain < 1.50) {
915 // This is not recommended
916 colamp_gain = 0;
917 analog_gain3 = 0;
918 digital_gain = 1;
919 } else if (gain < 3.0) {
920 colamp_gain = 1;
921 analog_gain3 = 0;
922 digital_gain = 1;
923 } else if (gain < 6.0) {
924 colamp_gain = 2;
925 analog_gain3 = 0;
926 digital_gain = 1;
927 } else if (gain < 16.0) {
928 colamp_gain = 3;
929 analog_gain3 = 0;
930 digital_gain = 1;
931 } else if (gain < 32.0) {
932 colamp_gain = 3;
933 analog_gain3 = 0;
934 digital_gain = 2;
935 } else {
936 colamp_gain = 3;
937 analog_gain3 = 0;
938 digital_gain = 4;
939 }
940
941 // Calculate gain 2 (fine gain)
942 uint16_t analog_gain2 = gain / (float)digital_gain / (float)(1 << colamp_gain) / (float)(1 << analog_gain3) * 64.0;
943 Bound(analog_gain2, 1, 127);
944
945 return (analog_gain2 & 0x7F) | ((analog_gain3 & 0x7) << 7) | ((colamp_gain & 0x3) << 10) | ((digital_gain & 0xF) << 12);
946}
947
948// settings to update resolution, color and exposure
952
953
964
965static void mt9f002_calc_resolution(struct mt9f002_t *mt)
966{
967 struct v4l2_rect crop, rect;
968 unsigned int x_odd_inc, y_odd_inc;
969 unsigned int hratio, vratio;
970 unsigned int width, height;
971 unsigned int ratio;
972 unsigned int xMultiple;
973 unsigned int div_res;
974 static const uint8_t xy_odd_inc_tab[] = {1, 1, 3, 3, 7, 7, 7, 7, 15};
975
976 crop.left = mt->offset_x;
977 crop.top = mt->offset_y;
978 crop.width = mt->sensor_width;
979 crop.height = mt->sensor_height;
980
981 VERBOSE_PRINT("Requested output - width: %i, height: %i\n", mt->output_width, mt->output_height);
982 VERBOSE_PRINT("Requested crop - top: %i, left: %i, width: %i, height: %i\n", crop.top, crop.left, crop.width,
983 crop.height);
984
985 /* Clamp the crop rectangle boundaries and Align them to a multiple of 2
986 * pixels to ensure a GRBG Bayer pattern.
987 */
988 rect.width = Clip(Align(crop.width, 4), 1, CFG_MT9F002_PIXEL_ARRAY_WIDTH);
989 rect.height = Clip(Align(crop.height, 4), 1, CFG_MT9F002_PIXEL_ARRAY_HEIGHT);
990
991 /* Clamp the width and height to avoid dividing by zero. */
992 width = Clip(Align(mt->output_width, 2), Max((int32_t)rect.width / 8, CFG_MT9F002_WINDOW_WIDTH_MIN), (int32_t)rect.width);
993 height = Clip(Align(mt->output_height, 2), Max((int32_t)rect.height / 8, CFG_MT9F002_WINDOW_HEIGHT_MIN), (int32_t)rect.height);
994
995 /* Calculate binning / skipping, we enforce that binning in X and Y are the same */
996 div_res = Min(rect.width / width, rect.height / height);
997 div_res = Clip(div_res, 1, 4);
998 x_odd_inc = xy_odd_inc_tab[div_res];
999 y_odd_inc = xy_odd_inc_tab[div_res];
1000
1001 /* Calculate remaining scaling not handled by binning / skipping */
1002 hratio = (rect.width / ((x_odd_inc + 1) / 2) * MT9F002_SCALER_N) / width;
1003 vratio = (rect.height / ((y_odd_inc + 1) / 2) * MT9F002_SCALER_N) / height;
1004 ratio = Min(hratio, vratio);
1005
1006 /* Check ratio */
1007 if (ratio > CFG_SCALER_M_MAX) {
1008 /* Fix ratio to maximum and adjust the crop window */
1009 ratio = CFG_SCALER_M_MAX;
1010 }
1011
1012 rect.width = mt->output_width * ratio * ((x_odd_inc + 1) / 2) / MT9F002_SCALER_N;
1013 rect.height = mt->output_height * ratio * ((y_odd_inc + 1) / 2) / MT9F002_SCALER_N;
1014
1015 VERBOSE_PRINT("Calculated skipping - x: %i, y: %i\n", x_odd_inc, y_odd_inc);
1016 VERBOSE_PRINT("Calculated scaler - %i/%i = %0.3f\n", MT9F002_SCALER_N, ratio, MT9F002_SCALER_N / ((float)ratio));
1017
1018 // center crop to same as requested
1019 rect.left = crop.left + ((int32_t)crop.width - (int32_t)rect.width) / 2;
1020 rect.top = crop.top + ((int32_t)crop.height - (int32_t)rect.height) / 2;
1021
1022 rect.left = Min(rect.left, CFG_MT9F002_PIXEL_ARRAY_WIDTH - (int32_t)rect.width);
1023 rect.top = Min(rect.top, CFG_MT9F002_PIXEL_ARRAY_HEIGHT - (int32_t)rect.height);
1024 rect.left = Clip(Align(rect.left, 2), CFG_MT9F002_X_ADDR_MIN, CFG_MT9F002_X_ADDR_MAX);
1025 rect.top = Clip(Align(rect.top, 2), CFG_MT9F002_Y_ADDR_MIN, CFG_MT9F002_Y_ADDR_MAX);
1026
1027 /* Align left offset to 8 */
1028 xMultiple = 8 * ((x_odd_inc + 1) / 2);
1029 rect.left = Align(rect.left, (int32_t)xMultiple);
1030
1031 /* Align top offset to 2 */
1032 rect.top = Align(rect.top, 4);
1033
1034 /* Update crop */
1035 crop = rect;
1036 VERBOSE_PRINT("Granted crop - top: %i, left: %i, width: %i, height: %i\n", crop.top, crop.left, crop.width,
1037 crop.height);
1038 VERBOSE_PRINT("Granted output - width: %i, height: %i\n", width, height);
1039
1040 /* Update values */
1041 mt->output_scaler = ratio;
1042 mt->x_odd_inc = x_odd_inc;
1043 mt->y_odd_inc = y_odd_inc;
1044
1045 mt->offset_x = crop.left;
1046 mt->offset_y = crop.top;
1047 mt->sensor_width = crop.width;
1048 mt->sensor_height = crop.height;
1049}
1050
1051static void mt9f002_set_resolution(struct mt9f002_t *mt)
1052{
1053 /* Set window pos */
1058
1059 /* Set output resolution */
1062
1063 /* scaler */
1064 if (mt->output_scaler > 1) {
1065 /* enable scaling mode */
1067 write_reg(mt, MT9F002_DATAPATH_SELECT, 0xd8b0, 2); // bayer resampling
1069 }
1070
1071 /* Binning / Skipping */
1072 if (mt->x_odd_inc > 1 || mt->x_odd_inc > 1) {
1073 write_reg(mt, MT9F002_READ_MODE, 0x0441, 2);
1074 } else {
1075 write_reg(mt, MT9F002_READ_MODE, 0x0041, 2);
1076 }
1079
1080 return;
1081}
1082
1087void mt9f002_init(struct mt9f002_t *mt)
1088{
1089 /* Reset the device */
1090 //TODO???
1091
1092 /* Setup i2c transaction */
1094
1095 /* Software reset */
1096 write_reg(mt, MT9F002_SOFTWARE_RESET, 0x1, 1);
1097 usleep(1500000); // Wait 1.5 seconds to give time for reset to finish
1098
1099 /* Based on the interface configure stage 1 */
1100 if (mt->interface == MT9F002_MIPI || mt->interface == MT9F002_HiSPi) {
1102 } else {
1104 }
1105
1106 /* Set the PLL based on Input clock and wanted clock frequency */
1107 mt9f002_set_pll(mt);
1108
1109 /* Calculate binning/skipping/scaling for requested sensor domain and output resolution */
1111
1112 /* Based on the interface configure stage 2 */
1113 if (mt->interface == MT9F002_MIPI || mt->interface == MT9F002_HiSPi) {
1115 } else {
1117 }
1118
1120
1121 /* Update blanking (based on FPS) */
1123
1124 /* Update statistics window (inside of cropped sensor area)*/
1126
1127 /* Update exposure (based on target_exposure) */
1129
1130 /* Update gains for the different pixel colors */
1132
1133 /* Based on the interface configure stage 3 */
1134 if (mt->interface == MT9F002_MIPI || mt->interface == MT9F002_HiSPi) {
1136 }
1137
1138 /* Turn the stream on */
1139 write_reg(mt, MT9F002_MODE_SELECT, 0x01, 1);
1140
1141 VERBOSE_PRINT("MT9F002 initialized\n");
1142}
1143
1152
1158
1159/* Handler for propagating user resolution change so the camera
1160 *
1161 */
1163{
1164 mt9f002.sensor_width = CFG_MT9F002_PIXEL_ARRAY_WIDTH / mt9f002.set_zoom;
1165 mt9f002.sensor_height = CFG_MT9F002_PIXEL_ARRAY_HEIGHT / mt9f002.set_zoom;
1166
1168 + mt9f002.set_offset_x * CFG_MT9F002_PIXEL_ARRAY_WIDTH);
1170 + mt9f002.set_offset_y * CFG_MT9F002_PIXEL_ARRAY_HEIGHT);
1171
1172 /* Calculate binning/skipping/scaling for requested sensor domain and output resolution */
1174
1176
1177 /* Update blanking (based on FPS) */
1179
1180 // Update the isp_config
1181 isp_request_statistics_yuv_window(0, mt9f002.sensor_width, 0, mt9f002.sensor_height, 1, 1);
1182}
1183
1188
1193
#define UNUSED(x)
#define Min(x, y)
Definition esc_dshot.c:110
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
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
uint32_t int32_gcd(uint32_t a, uint32_t b)
static float p[2][2]
int isp_request_statistics_yuv_window(uint16_t x_start, uint16_t x_end, uint16_t y_start, uint16_t y_end, uint16_t x_odd_inc, uint16_t y_odd_inc)
Definition libisp.c:214
static uint32_t s
#define VERBOSE_PRINT(...)
Definition mt9f002.c:98
struct mt9f002_t mt9f002
Definition mt9f002.c:168
static void mt9f002_parallel_stage1(struct mt9f002_t *mt)
Configure stage 1 for parallel connection.
Definition mt9f002.c:542
void mt9f002_reset_exposure(struct mt9f002_t *mt)
Definition mt9f002.c:1153
static uint16_t mt9f002_calc_gain(float gain)
Calculate the gain based on value of 1.0 -> 63.50.
Definition mt9f002.c:905
static void mt9f002_mipi_stage1(struct mt9f002_t *mt)
Configure stage 1 for both MiPi and HiSPi connection.
Definition mt9f002.c:267
uint16_t min_line_blanking_pck
Definition mt9f002.c:211
#define MT9F002_GAIN_RED
Definition mt9f002.c:127
void mt9f002_set_gains(struct mt9f002_t *mt)
Sets the GreenR, Blue, Red and GreenB gains.
Definition mt9f002.c:957
static void mt9f002_mipi_stage3(struct mt9f002_t *mt)
Configure stage 3 for both MiPi and HiSPi connection.
Definition mt9f002.c:531
static void mt9f002_parallel_stage2(struct mt9f002_t *mt)
Configure stage 2 for parallel connection.
Definition mt9f002.c:639
static void mt9f002_set_blanking(struct mt9f002_t *mt)
Definition mt9f002.c:704
uint16_t fine_integration_time_max_margin
Definition mt9f002.c:215
uint16_t min_line_length_pck
Definition mt9f002.c:212
#define MT9F002_GAIN_BLUE
Definition mt9f002.c:131
#define MT9F002_GAIN_GREEN1
Definition mt9f002.c:119
uint16_t fine_integration_time_min
Definition mt9f002.c:214
static uint32_t read_reg(struct mt9f002_t *mt, uint16_t addr, uint8_t len)
Read multiple bytes from a register.
Definition mt9f002.c:248
void mt9f002_init(struct mt9f002_t *mt)
Initialisation of the Aptina MT9F002 CMOS sensor (front camera).
Definition mt9f002.c:1087
float mt9f002_send_color
Definition mt9f002.c:950
static void mt9f002_set_pll(struct mt9f002_t *mt)
Set the PLL registers based on config.
Definition mt9f002.c:677
static void mt9f002_calc_resolution(struct mt9f002_t *mt)
Definition mt9f002.c:965
struct blanking_t mt9f002_blanking
float mt9f002_send_resolution
Definition mt9f002.c:949
static void mt9f002_mipi_stage2(struct mt9f002_t *mt)
Configure stage 2 for both MiPi and HiSPi connection.
Definition mt9f002.c:523
#define MT9F002_TARGET_EXPOSURE
Exposure of the front camera of the bebop.
Definition mt9f002.c:114
void mt9f002_setting_update_resolution(float in UNUSED)
Definition mt9f002.c:1162
static void write_reg(struct mt9f002_t *mt, uint16_t addr, uint32_t val, uint8_t len)
Write multiple bytes to a single register.
Definition mt9f002.c:221
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 mt9f002.c:51
void mt9f002_setting_update_exposure(float in UNUSED)
Definition mt9f002.c:1189
void mt9f002_set_exposure(struct mt9f002_t *mt)
Set the exposure configuration Depends on the blanking (and therefore the FPS).
Definition mt9f002.c:844
float mt9f002_send_exposure
Definition mt9f002.c:951
void mt9f002_reset_color(struct mt9f002_t *mt)
Definition mt9f002.c:1144
#define MT9F002_GAIN_GREEN2
Definition mt9f002.c:123
#define MT9F002_I2C_TRIES
Definition mt9f002.c:42
static void mt9f002_set_resolution(struct mt9f002_t *mt)
Definition mt9f002.c:1051
uint16_t min_line_fifo_pck
Definition mt9f002.c:213
#define PRINT(string,...)
Definition mt9f002.c:93
void mt9f002_setting_update_color(float in UNUSED)
Definition mt9f002.c:1184
Initialization and configuration of the MT9F002 CMOS Chip.
#define MT9F002_CENTER_X
Definition mt9f002.h:116
uint16_t op_sys_clk_div
Fixed PLL config from calculator tool.
Definition mt9f002.h:141
float target_exposure
Target exposure time in ms.
Definition mt9f002.h:152
#define MT9F002_OFFSET_X
Definition mt9f002.h:91
enum mt9f002_interface interface
Interface used to connect.
Definition mt9f002.h:134
uint16_t op_pix_clk_div
Fixed PLL config from calculator tool.
Definition mt9f002.h:140
uint8_t x_odd_inc
X increment for subsampling (1,3,7,15,31 accepted).
Definition mt9f002.h:171
float input_clk_freq
Input clock frequency.
Definition mt9f002.h:135
#define CFG_MT9F002_X_ADDR_MIN
Definition mt9f002.h:40
#define MT9F002_DHANE_K
Definition mt9f002.h:122
#define CFG_MT9F002_Y_ADDR_MIN
Definition mt9f002.h:42
float gain_red
Gain for the Red pixels [1., 63.50].
Definition mt9f002.h:157
uint16_t offset_x
Offset from left in pixels.
Definition mt9f002.h:165
#define CFG_MT9F002_WINDOW_HEIGHT_MIN
Definition mt9f002.h:37
float gain_green2
Gain for the GreenB pixels [1., 63.50].
Definition mt9f002.h:158
float target_fps
FPS wanted.
Definition mt9f002.h:150
uint16_t output_width
Output width.
Definition mt9f002.h:160
#define CFG_MT9F002_PIXEL_ARRAY_WIDTH
Definition mt9f002.h:39
float vt_pix_clk
Calculated based on PLL.
Definition mt9f002.h:145
#define MT9F002_ZOOM
Definition mt9f002.h:101
float gain_green1
Gain for the GreenR pixels [1., 63.50].
Definition mt9f002.h:155
uint8_t shift_vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition mt9f002.h:142
uint16_t frame_length
Calculated frame length of blanking.
Definition mt9f002.h:148
#define CFG_SCALER_M_MAX
Definition mt9f002.h:35
@ MT9F002_PARALLEL
Parallel type connection.
Definition mt9f002.h:129
@ MT9F002_HiSPi
HiSPi type connection.
Definition mt9f002.h:128
@ MT9F002_MIPI
MIPI type connection.
Definition mt9f002.h:127
#define MT9F002_CENTER_Y
Definition mt9f002.h:119
uint16_t pre_pll_clk_div
Fixed PLL config from calculator tool.
Definition mt9f002.h:138
uint16_t output_height
Output height.
Definition mt9f002.h:161
#define MT9F002_FOCAL_Y
Definition mt9f002.h:113
uint8_t row_speed_10_8
Fixed PLL config from calculator tool.
Definition mt9f002.h:144
float op_pix_clk
Calculated based on PLL.
Definition mt9f002.h:146
uint8_t rowSpeed_2_0
Fixed PLL config from calculator tool.
Definition mt9f002.h:143
uint16_t offset_y
Offset from top in pixels.
Definition mt9f002.h:166
uint8_t y_odd_inc
Y increment for subsampling (1,3,7,15,31 accepted).
Definition mt9f002.h:172
uint16_t vt_sys_clk_div
Fixed PLL config from calculator tool.
Definition mt9f002.h:137
float gain_blue
Gain for the Blue pixels [1., 63.50].
Definition mt9f002.h:156
#define MT9F002_OUTPUT_WIDTH
Definition mt9f002.h:82
#define CFG_MT9F002_WINDOW_WIDTH_MIN
Definition mt9f002.h:36
#define CFG_MT9F002_PIXEL_ARRAY_HEIGHT
Definition mt9f002.h:38
uint16_t sensor_width
Definition mt9f002.h:168
uint16_t output_scaler
Output scaler.
Definition mt9f002.h:162
uint16_t vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition mt9f002.h:136
struct i2c_periph * i2c_periph
I2C peripheral used to communicate over.
Definition mt9f002.h:174
#define CFG_MT9F002_Y_ADDR_MAX
Definition mt9f002.h:43
#define CFG_MT9F002_X_ADDR_MAX
Definition mt9f002.h:41
uint16_t pll_multiplier
Fixed PLL config from calculator tool.
Definition mt9f002.h:139
float real_exposure
Real exposure time in ms.
Definition mt9f002.h:153
uint16_t sensor_height
Definition mt9f002.h:169
uint16_t line_length
Calculated line length of blanking.
Definition mt9f002.h:147
#define MT9F002_OFFSET_Y
Definition mt9f002.h:96
struct i2c_transaction i2c_trans
I2C transaction for communication with CMOS chip.
Definition mt9f002.h:175
#define MT9F002_TARGET_FPS
Definition mt9f002.h:105
#define MT9F002_FOCAL_X
Definition mt9f002.h:110
#define MT9F002_OUTPUT_HEIGHT
Definition mt9f002.h:85
float real_fps
Real calculated FPS.
Definition mt9f002.h:151
#define front_camera
Definition mt9f002_nps.c:3
#define MT9F002_MFR_3EC4
#define MT9F002_MFR_3E3A
#define MT9F002_MFR_3D96
#define MT9F002_MFR_3E62
#define MT9F002_MFR_3EAE
#define MT9F002_MFR_3DDC
#define MT9F002_MFR_3E2C
#define MT9F002_MFR_3DBE
#define MT9F002_MFR_3E58
#define MT9F002_MFR_3EDC
#define MT9F002_MFR_3DE4
#define MT9F002_MFR_3E00
#define MT9F002_MFR_3D24
#define MT9F002_MFR_3E0C
#define MT9F002_GREEN1_GAIN
#define MT9F002_MFR_3E88
#define MT9F002_RED_GAIN
#define MT9F002_MFR_3E4E
#define MT9F002_MFR_3DC4
#define MT9F002_COLUMN_CORRECTION
#define MT9F002_MFR_3E08
#define MT9F002_MFR_3D4C
#define MT9F002_OP_PIX_CLK_DIV
#define MT9F002_MFR_3DB6
#define MT9F002_MFR_3D26
#define MT9F002_MFR_3EC2
#define MT9F002_MFR_3D3A
#define MT9F002_MFR_3D8E
#define MT9F002_MFR_3E28
#define MT9F002_MFR_3DCC
#define MT9F002_MFR_3DB2
#define MT9F002_MFR_3D4E
#define MT9F002_MFR_3D0C
#define MT9F002_MFR_3EAC
#define MT9F002_MFR_3DE0
#define MT9F002_MFR_3E32
#define MT9F002_MFR_3E48
#define MT9F002_MFR_3D6E
#define MT9F002_MFR_3D92
#define MT9F002_MFR_3DD4
#define MT9F002_MFR_3D48
#define MT9F002_MFR_3EB4
#define MT9F002_MFR_3DDA
#define MT9F002_MFR_3DAA
#define MT9F002_MFR_3EB6
#define MT9F002_MFR_3ED8
#define MT9F002_MFR_3D00
#define MT9F002_DATA_PEDESTAL_
#define MT9F002_MFR_3E92
#define MT9F002_MFR_3D46
#define MT9F002_MFR_3D50
#define MT9F002_MFR_3E10
#define MT9F002_MFR_3DBC
#define MT9F002_MFR_3D5E
#define MT9F002_MFR_3E9C
#define MT9F002_MFR_3E80
#define MT9F002_MFR_3E24
#define MT9F002_X_OUTPUT_SIZE
#define MT9F002_MFR_3E4A
#define MT9F002_MFR_3D2C
#define MT9F002_MFR_3DFA
#define MT9F002_DATAPATH_SELECT
#define MT9F002_MFR_3D16
#define MT9F002_MFR_3DBA
#define MT9F002_COARSE_INTEGRATION_TIME_MAX_MARGIN
#define MT9F002_MFR_3E6E
#define MT9F002_MFR_3D74
#define MT9F002_MFR_3EB2
#define MT9F002_EXTRA_DELAY
#define MT9F002_MFR_3D88
#define MT9F002_PRE_PLL_CLK_DIV
#define MT9F002_MFR_3E72
#define MT9F002_MFR_3D22
#define MT9F002_MFR_3D72
#define MT9F002_MFR_3EC0
#define MT9F002_MFR_3D44
#define MT9F002_MFR_3DFC
#define MT9F002_ROW_SPEED
#define MT9F002_CPP_DATA_FORMAT
#define MT9F002_MFR_3DAC
#define MT9F002_MFR_3DE6
#define MT9F002_MFR_3D0E
#define MT9F002_MFR_3DC8
#define MT9F002_MFR_3D7E
#define MT9F002_MFR_3D8A
#define MT9F002_OP_SYS_CLK_DIV
#define MT9F002_MFR_3E06
#define MT9F002_MFR_3D9A
#define MT9F002_SCALING_MODE
#define MT9F002_MFR_3DF2
#define MT9F002_MFR_3E12
#define MT9F002_GLOBAL_GAIN
#define MT9F002_MFR_3D42
#define MT9F002_GREEN2_GAIN
#define MT9F002_MFR_3EA6
#define MT9F002_MFR_3DDE
#define MT9F002_RESET_REGISTER
#define MT9F002_MFR_3DF6
#define MT9F002_MFR_3E8E
#define MT9F002_DAC_LD_14_15
#define MT9F002_MFR_3E84
#define MT9F002_MFR_3E9A
#define MT9F002_MFR_3DCE
#define MT9F002_DAC_LD_24_25
#define MT9F002_MFR_3DEE
#define MT9F002_MFR_3E7C
#define MT9F002_MFR_3DA8
#define MT9F002_MFR_3E1E
#define MT9F002_MFR_3E0A
#define MT9F002_MFR_3E3E
#define MT9F002_MFR_3D52
#define MT9F002_X_ADDR_END
#define MT9F002_MFR_3E52
#define MT9F002_Y_ODD_INC
#define MT9F002_MFR_3D68
#define MT9F002_FRAME_LENGTH_MAX
Definition mt9f002_regs.h:8
#define MT9F002_MFR_3D86
#define MT9F002_MFR_3DC2
#define MT9F002_DIGITAL_TEST
#define MT9F002_CTX_WR_DATA_REG
#define MT9F002_MFR_3E76
#define MT9F002_MFR_3E90
#define MT9F002_MFR_3EE6
#define MT9F002_X_ADDR_START
#define MT9F002_MFR_3E5E
#define MT9F002_MFR_3E26
#define MT9F002_READ_MODE
#define MT9F002_DAC_LD_28_29
#define MT9F002_MFR_3D60
#define MT9F002_MFR_3E8A
#define MT9F002_MFR_3EAA
#define MT9F002_MFR_3D7C
#define MT9F002_MFR_3D06
#define MT9F002_MFR_3E46
#define MT9F002_MFR_3E1C
#define MT9F002_MFR_3DA4
#define MT9F002_MFR_3E6A
#define MT9F002_MFR_3E20
#define MT9F002_MFR_3ECA
#define MT9F002_ADDRESS
Definition mt9f002_regs.h:4
#define MT9F002_MFR_3E38
#define MT9F002_MFR_3E82
#define MT9F002_MFR_3DA6
#define MT9F002_MFR_3D7A
#define MT9F002_MFR_3EBE
#define MT9F002_MFR_3E64
#define MT9F002_MFR_3D08
#define MT9F002_ANALOG_CONTROL5
#define MT9F002_FINE_INTEGRATION_TIME_
#define MT9F002_MFR_3E94
#define MT9F002_MFR_3E68
#define MT9F002_SMIA_TEST
#define MT9F002_MFR_3EC6
#define MT9F002_LINE_LENGTH_PCK
#define MT9F002_FRAME_LENGTH_LINES
#define MT9F002_MFR_3E9E
#define MT9F002_MFR_3EA2
#define MT9F002_MFR_3D76
#define MT9F002_SERIAL_FORMAT
#define MT9F002_MFR_3D78
#define MT9F002_MFR_3DC6
#define MT9F002_MFR_3D02
#define MT9F002_MFR_3D38
#define MT9F002_MFR_3E56
#define MT9F002_MFR_3E0E
#define MT9F002_MFR_3E04
#define MT9F002_MFR_3E78
#define MT9F002_MFR_3E5A
#define MT9F002_MFR_3D4A
#define MT9F002_ANALOG_CONTROL7
#define MT9F002_MFR_3EE8
#define MT9F002_VT_SYS_CLK_DIV
#define MT9F002_MFR_3D20
#define MT9F002_MFR_3D18
#define MT9F002_MFR_3DF8
#define MT9F002_BLUE_GAIN
#define MT9F002_MFR_3DF4
#define MT9F002_MFR_3DB4
#define MT9F002_ANALOG_CONTROL4
#define MT9F002_MFR_3E7E
#define MT9F002_MFR_3D2E
#define MT9F002_MIN_FRAME_BLANKING_LINES
#define MT9F002_MFR_3E6C
#define MT9F002_VT_PIX_CLK_DIV
#define MT9F002_MFR_3E36
#define MT9F002_MFR_3D82
#define MT9F002_MFR_3D1C
#define MT9F002_MFR_3E98
#define MT9F002_MFR_3DD6
#define MT9F002_MFR_3D6C
#define MT9F002_MFR_3D70
#define MT9F002_MFR_3D5C
#define MT9F002_MFR_3D56
#define MT9F002_MFR_3D3E
#define MT9F002_MFR_3D8C
#define MT9F002_MFR_3DA2
#define MT9F002_MFR_3D36
#define MT9F002_MFR_3DD8
#define MT9F002_MFR_3D1A
#define MT9F002_MFR_3D9C
#define MT9F002_MFR_3E30
#define MT9F002_MFR_3D04
#define MT9F002_MFR_3EA8
#define MT9F002_MFR_3E14
#define MT9F002_MFR_3D34
#define MT9F002_MFR_3E4C
#define MT9F002_MFR_3D66
#define MT9F002_MFR_3DEC
#define MT9F002_MFR_3E5C
#define MT9F002_MODE_SELECT
#define MT9F002_MFR_3EA0
#define MT9F002_MFR_3D3C
#define MT9F002_MFR_3E42
#define MT9F002_MFR_3DA0
#define MT9F002_MFR_3E54
#define MT9F002_MFR_3DF0
#define MT9F002_MFR_3E34
#define MT9F002_MFR_3D54
#define MT9F002_MFR_3E22
#define MT9F002_MFR_3D2A
#define MT9F002_Y_ADDR_END
#define MT9F002_MFR_3E18
#define MT9F002_MFR_3E7A
#define MT9F002_MFR_3D40
#define MT9F002_MFR_3DB0
#define MT9F002_MFR_3D98
#define MT9F002_MFR_317C
#define MT9F002_MFR_3DD0
#define MT9F002_MFR_3D90
#define MT9F002_PLL_MULTIPLIER
#define MT9F002_MFR_3DD2
#define MT9F002_MFR_3D58
#define MT9F002_MFR_3DFE
#define MT9F002_MFR_3E8C
#define MT9F002_DAC_LD_30_31
#define MT9F002_MFR_3E02
#define MT9F002_SCALER_N
Definition mt9f002_regs.h:6
#define MT9F002_MFR_3D10
#define MT9F002_SCALE_M
#define MT9F002_MFR_3E70
#define MT9F002_MFR_3DAE
#define MT9F002_MFR_3D14
#define MT9F002_MFR_3E16
#define MT9F002_MFR_3E2A
#define MT9F002_MFR_3D28
#define MT9F002_MFR_3D30
#define MT9F002_MFR_3DE2
#define MT9F002_MFR_3D9E
#define MT9F002_DARK_CONTROL3
#define MT9F002_MFR_3E44
#define MT9F002_MFR_3D62
#define MT9F002_MFR_3176
#define MT9F002_MFR_3DE8
#define MT9F002_MFR_3E86
#define MT9F002_MFR_3E2E
#define MT9F002_MFR_3E60
#define MT9F002_MFR_3E50
#define MT9F002_MFR_3EC8
#define MT9F002_MFR_3E3C
#define MT9F002_MFR_3EB8
#define MT9F002_MFR_3EA4
#define MT9F002_MASK_CORRUPTED_FRAMES
#define MT9F002_COARSE_INTEGRATION_TIME_MIN
#define MT9F002_MFR_3E74
#define MT9F002_MFR_3E1A
#define MT9F002_MFR_3E66
#define MT9F002_MFR_3D32
#define MT9F002_MFR_3DCA
#define MT9F002_MFR_3D84
#define MT9F002_Y_ADDR_START
#define MT9F002_MFR_3D94
#define MT9F002_MFR_3D0A
#define MT9F002_MFR_3DC0
#define MT9F002_SOFTWARE_RESET
#define MT9F002_MFR_3D80
#define MT9F002_MFR_3DB8
#define MT9F002_MFR_3EB0
#define MT9F002_MFR_3D6A
#define MT9F002_MFR_3D5A
#define MT9F002_Y_OUTPUT_SIZE
#define MT9F002_CTX_CONTROL_REG
#define MT9F002_X_ODD_INC
#define MT9F002_COARSE_INTEGRATION_TIME
#define MT9F002_MFR_3E96
#define MT9F002_MFR_3D1E
#define MT9F002_MFR_3DEA
#define MT9F002_MFR_3E40
#define MT9F002_MFR_3EE2
#define MT9F002_MFR_3D64
#define MT9F002_MFR_3EBA
#define MT9F002_MFR_3D12
#define MT9F002_MFR_3EBC
#define MT9F002_LINE_LENGTH_MAX
Definition mt9f002_regs.h:7
static float timeout
Paparazzi fixed point algebra.
uint16_t val[TCOUPLE_NB]
#define VIDEO_FILTER_ISP
Enable ISP.
V4L2 device settings.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.