Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mt9f002.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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 
27 #ifndef MT9F002H
28 #define MT9F002H
29 
30 #include "std.h"
31 #include "mcu_periph/i2c.h"
32 #include "generated/airframe.h"
33 
34 #define CFG_SCALER_M_MIN 16
35 #define CFG_SCALER_M_MAX 128
36 #define CFG_MT9F002_WINDOW_WIDTH_MIN 1
37 #define CFG_MT9F002_WINDOW_HEIGHT_MIN 1
38 #define CFG_MT9F002_PIXEL_ARRAY_HEIGHT 3288
39 #define CFG_MT9F002_PIXEL_ARRAY_WIDTH 4608
40 #define CFG_MT9F002_X_ADDR_MIN 24
41 #define CFG_MT9F002_X_ADDR_MAX 4647
42 #define CFG_MT9F002_Y_ADDR_MIN 0
43 #define CFG_MT9F002_Y_ADDR_MAX CFG_MT9F002_PIXEL_ARRAY_HEIGHT
44 
45 #define RES_VGA 0
46 #define RES_720p 1
47 #define RES_720p_4_3 2
48 #define RES_1080p 3
49 #define RES_1080p_4_3 4
50 #define RES_FULL 5
51 
52 #ifdef MT9F002_RESOLUTION
53 #if MT9F002_RESOLUTION == RES_VGA
54 #define MT9F002_OUTPUT_WIDTH 640
55 #define MT9F002_OUTPUT_HEIGHT 480
56 #elif MT9F002_RESOLUTION == RES_720p
57 #define MT9F002_OUTPUT_WIDTH 1280
58 #define MT9F002_OUTPUT_HEIGHT 720
59 #elif MT9F002_RESOLUTION == RES_720p_4_3
60 #define MT9F002_OUTPUT_WIDTH 960
61 #define MT9F002_OUTPUT_HEIGHT 720
62 #elif MT9F002_RESOLUTION == RES_1080p
63 #define MT9F002_OUTPUT_WIDTH 1920
64 #define MT9F002_OUTPUT_HEIGHT 1080
65 #elif MT9F002_RESOLUTION == RES_1080p_4_3
66 #define MT9F002_OUTPUT_WIDTH 1440
67 #define MT9F002_OUTPUT_HEIGHT 1080
68 #elif MT9F002_RESOLUTION == RES_FULL
69 // Doesn't work with isp
70 //#define MT9F002_OUTPUT_WIDTH 4384
71 //#define MT9F002_OUTPUT_HEIGHT 3288
72 #define MT9F002_OUTPUT_WIDTH 2048
73 #define MT9F002_OUTPUT_HEIGHT 2048
74 #else // default MT9F002_RESOLUTION
75 #define MT9F002_OUTPUT_WIDTH 640
76 #define MT9F002_OUTPUT_HEIGHT 640
77 #endif
78 
79 #else // MT9F002_RESOLUTION
80 
81 #ifndef MT9F002_OUTPUT_WIDTH
82 #define MT9F002_OUTPUT_WIDTH 640
83 #endif
84 #ifndef MT9F002_OUTPUT_HEIGHT
85 #define MT9F002_OUTPUT_HEIGHT 640
86 #endif
87 #endif
88 
89 // Signed fractional offset from centre of image of original sensor [-0.5,0.5]
90 #ifndef MT9F002_OFFSET_X
91 #define MT9F002_OFFSET_X 0.
92 #endif
93 
94 // Signed fractional offset from centre of image of original sensor [-0.5,0.5]
95 #ifndef MT9F002_OFFSET_Y
96 #define MT9F002_OFFSET_Y 0.
97 #endif
98 
99 // Zoom factor of image
100 #ifndef MT9F002_ZOOM
101 #define MT9F002_ZOOM 1.
102 #endif
103 
104 #ifndef MT9F002_TARGET_FPS
105 #define MT9F002_TARGET_FPS 30
106 #endif
107 
108 // parameters for undistortion, defaults are rough estimates
109 #ifndef MT9F002_FOCAL_X
110 #define MT9F002_FOCAL_X (MT9F002_ZOOM * MT9F002_OUTPUT_WIDTH / 2.f)
111 #endif
112 #ifndef MT9F002_FOCAL_Y
113 #define MT9F002_FOCAL_Y (MT9F002_ZOOM * MT9F002_OUTPUT_HEIGHT / 2.f)
114 #endif
115 #ifndef MT9F002_CENTER_X
116 #define MT9F002_CENTER_X (MT9F002_OUTPUT_WIDTH * (.5f - MT9F002_ZOOM * MT9F002_OFFSET_X))
117 #endif
118 #ifndef MT9F002_CENTER_Y
119 #define MT9F002_CENTER_Y (MT9F002_OUTPUT_HEIGHT * (.5f - MT9F002_ZOOM * MT9F002_OFFSET_Y))
120 #endif
121 #ifndef MT9F002_DHANE_K
122 #define MT9F002_DHANE_K 1.25f
123 #endif
124 
125 /* Interface types for the MT9F002 connection */
130 };
131 
132 /* Main configuration structure */
133 struct mt9f002_t {
145  float vt_pix_clk;
146  float op_pix_clk;
149 
150  float target_fps;
151  float real_fps;
154 
155  float gain_green1;
156  float gain_blue;
157  float gain_red;
158  float gain_green2;
159 
167 
170 
173 
176 
177  float set_zoom;
178  float set_offset_x;
179  float set_offset_y;
180 };
181 
182 /* ISP */
183 extern struct mt9f002_t mt9f002;
184 
185 extern void mt9f002_init(struct mt9f002_t *mt);
186 extern void mt9f002_reset_exposure(struct mt9f002_t *mt);
187 extern void mt9f002_set_exposure(struct mt9f002_t *mt);
188 extern void mt9f002_reset_color(struct mt9f002_t *mt);
189 extern void mt9f002_set_gains(struct mt9f002_t *mt);
190 
191 // settings to update resolution, color and exposure
195 
196 // handlers for propagating settings
197 extern void mt9f002_setting_update_resolution(float in);
198 extern void mt9f002_setting_update_color(float in);
199 extern void mt9f002_setting_update_exposure(float in);
200 
201 #endif /* MT9F002_H */
unsigned short uint16_t
Definition: types.h:16
uint16_t sensor_width
Definition: mt9f002.h:168
float mt9f002_send_exposure
Definition: mt9f002.h:194
float set_zoom
Image zoom set point.
Definition: mt9f002.h:177
uint8_t x_odd_inc
X increment for subsampling (1,3,7,15,31 accepted)
Definition: mt9f002.h:171
uint16_t output_height
Output height.
Definition: mt9f002.h:161
uint16_t op_sys_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:141
uint8_t rowSpeed_2_0
Fixed PLL config from calculator tool.
Definition: mt9f002.h:143
uint16_t vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:136
uint16_t pll_multiplier
Fixed PLL config from calculator tool.
Definition: mt9f002.h:139
void mt9f002_set_exposure(struct mt9f002_t *mt)
Set the exposure configuration Depends on the blanking (and therefore the FPS)
Definition: mt9f002.c:799
uint16_t scaled_width
Width after corrected scaling.
Definition: mt9f002.h:163
float set_offset_x
Signed fractional offset from centre of image of original sensor [-0.5,0.5].
Definition: mt9f002.h:178
float set_offset_y
Signed fractional offset from centre of image of original sensor [-0.5,0.5].
Definition: mt9f002.h:179
void mt9f002_reset_color(struct mt9f002_t *mt)
Definition: mt9f002.c:1093
float gain_blue
Gain for the Blue pixels [1., 63.50].
Definition: mt9f002.h:156
uint16_t offset_x
Offset from left in pixels.
Definition: mt9f002.h:165
HiSPi type connection.
Definition: mt9f002.h:128
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
void mt9f002_init(struct mt9f002_t *mt)
Initialisation of the Aptina MT9F002 CMOS sensor (front camera)
Definition: mt9f002.c:1036
uint16_t output_scaler
Output scaler.
Definition: mt9f002.h:162
void mt9f002_setting_update_color(float in)
Definition: mt9f002.c:1133
uint8_t shift_vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:142
uint8_t row_speed_10_8
Fixed PLL config from calculator tool.
Definition: mt9f002.h:144
enum mt9f002_interface interface
Interface used to connect.
Definition: mt9f002.h:134
uint16_t line_length
Calculated line length of blanking.
Definition: mt9f002.h:147
float real_fps
Real calculated FPS.
Definition: mt9f002.h:151
float gain_green1
Gain for the GreenR pixels [1., 63.50].
Definition: mt9f002.h:155
uint16_t output_width
Output width.
Definition: mt9f002.h:160
float mt9f002_send_color
Definition: mt9f002.h:193
float vt_pix_clk
Calculated based on PLL.
Definition: mt9f002.h:145
mt9f002_interface
Definition: mt9f002.h:126
float target_fps
FPS wanted.
Definition: mt9f002.h:150
float gain_red
Gain for the Red pixels [1., 63.50].
Definition: mt9f002.h:157
I2C transaction structure.
Definition: i2c.h:93
void mt9f002_setting_update_exposure(float in)
Definition: mt9f002.c:1138
struct i2c_periph * i2c_periph
I2C peripheral used to communicate over.
Definition: mt9f002.h:174
float gain_green2
Gain for the GreenB pixels [1., 63.50].
Definition: mt9f002.h:158
void mt9f002_reset_exposure(struct mt9f002_t *mt)
Definition: mt9f002.c:1102
uint16_t offset_y
Offset from top in pixels.
Definition: mt9f002.h:166
float real_exposure
Real exposure time in ms.
Definition: mt9f002.h:153
struct i2c_transaction i2c_trans
I2C transaction for communication with CMOS chip.
Definition: mt9f002.h:175
unsigned char uint8_t
Definition: types.h:14
uint16_t op_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:140
float op_pix_clk
Calculated based on PLL.
Definition: mt9f002.h:146
float mt9f002_send_resolution
Definition: mt9f002.h:192
uint16_t pre_pll_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:138
Parallel type connection.
Definition: mt9f002.h:129
void mt9f002_setting_update_resolution(float in)
Definition: mt9f002.c:1111
uint16_t scaled_height
Height after corrected scaling.
Definition: mt9f002.h:164
struct mt9f002_t mt9f002
Definition: mt9f002.c:123
uint16_t sensor_height
Definition: mt9f002.h:169
uint16_t frame_length
Calculated frame length of blanking.
Definition: mt9f002.h:148
float input_clk_freq
Input clock frequency.
Definition: mt9f002.h:135
MIPI type connection.
Definition: mt9f002.h:127
float target_exposure
Target exposure time in ms.
Definition: mt9f002.h:152
void mt9f002_set_gains(struct mt9f002_t *mt)
Sets the GreenR, Blue, Red and GreenB gains.
Definition: mt9f002.c:906
Architecture independent I2C (Inter-Integrated Circuit Bus) API.