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.c File Reference

Initialization of MT9F002 chip and options to change settings. More...

#include "std.h"
#include "mt9f002.h"
#include "mt9f002_regs.h"
#include "isp/libisp.h"
#include "math/pprz_algebra_int.h"
#include "peripherals/video_device.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <linux/videodev2.h>
#include "generated/airframe.h"
#include "boards/bebop.h"
+ Include dependency graph for mt9f002.c:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  blanking_t
 

Macros

#define PRINT(string,...)   fprintf(stderr, "[MT9F002->%s()] " string,__FUNCTION__ , ##__VA_ARGS__)
 
#define VERBOSE_PRINT(...)
 
#define MT9F002_TARGET_EXPOSURE   30
 Exposure of the front camera of the bebop. More...
 
#define MT9F002_GAIN_GREEN1   2.0
 
#define MT9F002_GAIN_GREEN2   2.0
 
#define MT9F002_GAIN_RED   1.4
 
#define MT9F002_GAIN_BLUE   2.7
 

Functions

static void write_reg (struct mt9f002_t *mt, uint16_t addr, uint32_t val, uint8_t len)
 Write multiple bytes to a single register. More...
 
static uint32_t read_reg (struct mt9f002_t *mt, uint16_t addr, uint8_t len)
 Read multiple bytes from a register. More...
 
static void mt9f002_mipi_stage1 (struct mt9f002_t *mt)
 Configure stage 1 for both MiPi and HiSPi connection. More...
 
static void mt9f002_mipi_stage2 (struct mt9f002_t *mt)
 Configure stage 2 for both MiPi and HiSPi connection. More...
 
static void mt9f002_mipi_stage3 (struct mt9f002_t *mt)
 Configure stage 3 for both MiPi and HiSPi connection. More...
 
static void mt9f002_parallel_stage1 (struct mt9f002_t *mt)
 Configure stage 1 for parallel connection. More...
 
static void mt9f002_parallel_stage2 (struct mt9f002_t *mt)
 Configure stage 2 for parallel connection. More...
 
static void mt9f002_set_pll (struct mt9f002_t *mt)
 Set the PLL registers based on config. More...
 
static void mt9f002_set_blanking (struct mt9f002_t *mt)
 
void mt9f002_set_exposure (struct mt9f002_t *mt)
 Set the exposure configuration Depends on the blanking (and therefore the FPS) More...
 
static uint16_t mt9f002_calc_gain (float gain)
 Calculate the gain based on value of 1.0 -> 63.50. More...
 
void mt9f002_set_gains (struct mt9f002_t *mt)
 Sets the GreenR, Blue, Red and GreenB gains. More...
 
static void mt9f002_calc_resolution (struct mt9f002_t *mt)
 
static void mt9f002_set_resolution (struct mt9f002_t *mt)
 
void mt9f002_init (struct mt9f002_t *mt)
 Initialisation of the Aptina MT9F002 CMOS sensor (front camera) More...
 
void mt9f002_reset_color (struct mt9f002_t *mt)
 
void mt9f002_reset_exposure (struct mt9f002_t *mt)
 
void mt9f002_setting_update_resolution (float in)
 
void mt9f002_setting_update_color (float in)
 
void mt9f002_setting_update_exposure (float in)
 

Variables

struct video_config_t front_camera
 
struct mt9f002_t mt9f002
 
struct blanking_t mt9f002_blanking
 

Detailed Description

Initialization of MT9F002 chip and options to change settings.

Definition in file mt9f002.c.


Data Structure Documentation

struct blanking_t

Definition at line 165 of file mt9f002.c.

Data Fields
uint16_t fine_integration_time_max_margin
uint16_t fine_integration_time_min
uint16_t min_line_blanking_pck
uint16_t min_line_fifo_pck
uint16_t min_line_length_pck

Macro Definition Documentation

#define MT9F002_GAIN_BLUE   2.7

Definition at line 86 of file mt9f002.c.

Referenced by mt9f002_reset_color().

#define MT9F002_GAIN_GREEN1   2.0

Definition at line 74 of file mt9f002.c.

Referenced by mt9f002_reset_color().

#define MT9F002_GAIN_GREEN2   2.0

Definition at line 78 of file mt9f002.c.

Referenced by mt9f002_reset_color().

#define MT9F002_GAIN_RED   1.4

Definition at line 82 of file mt9f002.c.

Referenced by mt9f002_reset_color().

#define MT9F002_TARGET_EXPOSURE   30

Exposure of the front camera of the bebop.

Experimental values: Outside: 15 Inside well lit: 30 Inside poorly lit: 60

Definition at line 69 of file mt9f002.c.

Referenced by mt9f002_reset_exposure().

#define PRINT (   string,
  ... 
)    fprintf(stderr, "[MT9F002->%s()] " string,__FUNCTION__ , ##__VA_ARGS__)

Definition at line 48 of file mt9f002.c.

Referenced by write_reg().

#define VERBOSE_PRINT (   ...)

Definition at line 53 of file mt9f002.c.

Referenced by mt9f002_calc_resolution(), mt9f002_init(), and mt9f002_set_blanking().

Function Documentation

static uint16_t mt9f002_calc_gain ( float  gain)
static

Calculate the gain based on value of 1.0 -> 63.50.

Definition at line 860 of file mt9f002.c.

Referenced by mt9f002_set_gains().

+ Here is the caller graph for this function:

static void mt9f002_mipi_stage1 ( struct mt9f002_t mt)
inlinestatic

Configure stage 1 for both MiPi and HiSPi connection.

Definition at line 222 of file mt9f002.c.

References mt9f002_t::interface, MT9F002_CPP_DATA_FORMAT, MT9F002_HiSPi, MT9F002_MFR_3176, MT9F002_MFR_317C, MT9F002_MFR_3D00, MT9F002_MFR_3D02, MT9F002_MFR_3D04, MT9F002_MFR_3D06, MT9F002_MFR_3D08, MT9F002_MFR_3D0A, MT9F002_MFR_3D0C, MT9F002_MFR_3D0E, MT9F002_MFR_3D10, MT9F002_MFR_3D12, MT9F002_MFR_3D14, MT9F002_MFR_3D16, MT9F002_MFR_3D18, MT9F002_MFR_3D1A, MT9F002_MFR_3D1C, MT9F002_MFR_3D1E, MT9F002_MFR_3D20, MT9F002_MFR_3D22, MT9F002_MFR_3D24, MT9F002_MFR_3D26, MT9F002_MFR_3D28, MT9F002_MFR_3D2A, MT9F002_MFR_3D2C, MT9F002_MFR_3D2E, MT9F002_MFR_3D30, MT9F002_MFR_3D32, MT9F002_MFR_3D34, MT9F002_MFR_3D36, MT9F002_MFR_3D38, MT9F002_MFR_3D3A, MT9F002_MFR_3D3C, MT9F002_MFR_3D3E, MT9F002_MFR_3D40, MT9F002_MFR_3D42, MT9F002_MFR_3D44, MT9F002_MFR_3D46, MT9F002_MFR_3D48, MT9F002_MFR_3D4A, MT9F002_MFR_3D4C, MT9F002_MFR_3D4E, MT9F002_MFR_3D50, MT9F002_MFR_3D52, MT9F002_MFR_3D54, MT9F002_MFR_3D56, MT9F002_MFR_3D58, MT9F002_MFR_3D5A, MT9F002_MFR_3D5C, MT9F002_MFR_3D5E, MT9F002_MFR_3D60, MT9F002_MFR_3D62, MT9F002_MFR_3D64, MT9F002_MFR_3D66, MT9F002_MFR_3D68, MT9F002_MFR_3D6A, MT9F002_MFR_3D6C, MT9F002_MFR_3D6E, MT9F002_MFR_3D70, MT9F002_MFR_3D72, MT9F002_MFR_3D74, MT9F002_MFR_3D76, MT9F002_MFR_3D78, MT9F002_MFR_3D7A, MT9F002_MFR_3D7C, MT9F002_MFR_3D7E, MT9F002_MFR_3D80, MT9F002_MFR_3D82, MT9F002_MFR_3D84, MT9F002_MFR_3D86, MT9F002_MFR_3D88, MT9F002_MFR_3D8A, MT9F002_MFR_3D8C, MT9F002_MFR_3D8E, MT9F002_MFR_3D90, MT9F002_MFR_3D92, MT9F002_MFR_3D94, MT9F002_MFR_3D96, MT9F002_MFR_3D98, MT9F002_MFR_3D9A, MT9F002_MFR_3D9C, MT9F002_MFR_3D9E, MT9F002_MFR_3DA0, MT9F002_MFR_3DA2, MT9F002_MFR_3DA4, MT9F002_MFR_3DA6, MT9F002_MFR_3DA8, MT9F002_MFR_3DAA, MT9F002_MFR_3DAC, MT9F002_MFR_3DAE, MT9F002_MFR_3DB0, MT9F002_MFR_3DB2, MT9F002_MFR_3DB4, MT9F002_MFR_3DB6, MT9F002_MFR_3DB8, MT9F002_MFR_3DBA, MT9F002_MFR_3DBC, MT9F002_MFR_3DBE, MT9F002_MFR_3DC0, MT9F002_MFR_3DC2, MT9F002_MFR_3DC4, MT9F002_MFR_3DC6, MT9F002_MFR_3DC8, MT9F002_MFR_3DCA, MT9F002_MFR_3DCC, MT9F002_MFR_3DCE, MT9F002_MFR_3DD0, MT9F002_MFR_3DD2, MT9F002_MFR_3DD4, MT9F002_MFR_3DD6, MT9F002_MFR_3DD8, MT9F002_MFR_3DDA, MT9F002_MFR_3DDC, MT9F002_MFR_3DDE, MT9F002_MFR_3DE0, MT9F002_MFR_3DE2, MT9F002_MFR_3DE4, MT9F002_MFR_3DE6, MT9F002_MFR_3DE8, MT9F002_MFR_3DEA, MT9F002_MFR_3DEC, MT9F002_MFR_3DEE, MT9F002_MFR_3DF0, MT9F002_MFR_3DF2, MT9F002_MFR_3DF4, MT9F002_MFR_3DF6, MT9F002_MFR_3DF8, MT9F002_MFR_3DFA, MT9F002_MFR_3DFC, MT9F002_MFR_3DFE, MT9F002_MFR_3E00, MT9F002_MFR_3E02, MT9F002_MFR_3E04, MT9F002_MFR_3E06, MT9F002_MFR_3E08, MT9F002_MFR_3E0A, MT9F002_MFR_3E0C, MT9F002_MFR_3E0E, MT9F002_MFR_3E10, MT9F002_MFR_3E12, MT9F002_MFR_3E14, MT9F002_MFR_3E16, MT9F002_MFR_3E18, MT9F002_MFR_3E1A, MT9F002_MFR_3E1C, MT9F002_MFR_3E1E, MT9F002_MFR_3E20, MT9F002_MFR_3E22, MT9F002_MFR_3E24, MT9F002_MFR_3E26, MT9F002_MFR_3E28, MT9F002_MFR_3E2A, MT9F002_MFR_3E2C, MT9F002_MFR_3E2E, MT9F002_MFR_3E30, MT9F002_MFR_3E32, MT9F002_MFR_3E34, MT9F002_MFR_3E36, MT9F002_MFR_3E38, MT9F002_MFR_3E3A, MT9F002_MFR_3E3C, MT9F002_MFR_3E3E, MT9F002_MFR_3E40, MT9F002_MFR_3E42, MT9F002_MFR_3E44, MT9F002_MFR_3E46, MT9F002_MFR_3E48, MT9F002_MFR_3E4A, MT9F002_MFR_3E4C, MT9F002_MFR_3E4E, MT9F002_MFR_3E50, MT9F002_MFR_3E52, MT9F002_MFR_3E54, MT9F002_MFR_3E56, MT9F002_MFR_3E58, MT9F002_MFR_3E5A, MT9F002_MFR_3E5C, MT9F002_MFR_3E5E, MT9F002_MFR_3E60, MT9F002_MFR_3E62, MT9F002_MFR_3E64, MT9F002_MFR_3E66, MT9F002_MFR_3E68, MT9F002_MFR_3E6A, MT9F002_MFR_3E6C, MT9F002_MFR_3E6E, MT9F002_MFR_3E70, MT9F002_MFR_3E72, MT9F002_MFR_3E74, MT9F002_MFR_3E76, MT9F002_MFR_3E78, MT9F002_MFR_3E7A, MT9F002_MFR_3E7C, MT9F002_MFR_3E7E, MT9F002_MFR_3E80, MT9F002_MFR_3E82, MT9F002_MFR_3E84, MT9F002_MFR_3E86, MT9F002_MFR_3E88, MT9F002_MFR_3E8A, MT9F002_MFR_3E8C, MT9F002_MFR_3E8E, MT9F002_MFR_3E90, MT9F002_MFR_3E92, MT9F002_MFR_3E94, MT9F002_MFR_3E96, MT9F002_MFR_3E98, MT9F002_MFR_3E9A, MT9F002_MFR_3E9C, MT9F002_MFR_3E9E, MT9F002_MFR_3EA0, MT9F002_MFR_3EA2, MT9F002_MFR_3EA4, MT9F002_MFR_3EA6, MT9F002_MFR_3EA8, MT9F002_MFR_3EAA, MT9F002_MFR_3EAC, MT9F002_MFR_3EAE, MT9F002_MFR_3EB0, MT9F002_MFR_3EB2, MT9F002_MFR_3EB4, MT9F002_MFR_3EB6, MT9F002_MFR_3EB8, MT9F002_MFR_3EBA, MT9F002_MFR_3EBC, MT9F002_MFR_3EBE, MT9F002_MFR_3EC0, MT9F002_MFR_3EC2, MT9F002_MFR_3EC4, MT9F002_MFR_3EC6, MT9F002_MFR_3EC8, MT9F002_MFR_3ECA, MT9F002_MFR_3ED8, MT9F002_MFR_3EE6, MT9F002_MFR_3EE8, MT9F002_MODE_SELECT, MT9F002_RESET_REGISTER, MT9F002_SERIAL_FORMAT, MT9F002_SMIA_TEST, and write_reg().

Referenced by mt9f002_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mt9f002_mipi_stage2 ( struct mt9f002_t mt)
inlinestatic

Configure stage 2 for both MiPi and HiSPi connection.

Definition at line 478 of file mt9f002.c.

References MT9F002_SMIA_TEST, and write_reg().

Referenced by mt9f002_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mt9f002_mipi_stage3 ( struct mt9f002_t mt)
inlinestatic

Configure stage 3 for both MiPi and HiSPi connection.

Definition at line 486 of file mt9f002.c.

References MT9F002_EXTRA_DELAY, MT9F002_MFR_3EDC, MT9F002_MFR_3EE2, MT9F002_RESET_REGISTER, and write_reg().

Referenced by mt9f002_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mt9f002_parallel_stage1 ( struct mt9f002_t mt)
inlinestatic

Configure stage 1 for parallel connection.

Definition at line 497 of file mt9f002.c.

References MT9F002_ANALOG_CONTROL4, MT9F002_CTX_CONTROL_REG, MT9F002_CTX_WR_DATA_REG, MT9F002_DAC_LD_14_15, MT9F002_DATA_PEDESTAL_, MT9F002_DATAPATH_SELECT, MT9F002_GLOBAL_GAIN, MT9F002_RESET_REGISTER, MT9F002_SERIAL_FORMAT, MT9F002_SMIA_TEST, and write_reg().

Referenced by mt9f002_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mt9f002_parallel_stage2 ( struct mt9f002_t mt)
inlinestatic
void mt9f002_reset_color ( struct mt9f002_t mt)

Definition at line 1093 of file mt9f002.c.

References mt9f002_t::gain_blue, mt9f002_t::gain_green1, mt9f002_t::gain_green2, mt9f002_t::gain_red, MT9F002_GAIN_BLUE, MT9F002_GAIN_GREEN1, MT9F002_GAIN_GREEN2, MT9F002_GAIN_RED, and mt9f002_set_gains().

Referenced by update_ae_awb().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mt9f002_reset_exposure ( struct mt9f002_t mt)

Definition at line 1102 of file mt9f002.c.

References mt9f002_set_exposure(), MT9F002_TARGET_EXPOSURE, and mt9f002_t::target_exposure.

Referenced by update_ae_awb().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mt9f002_set_gains ( struct mt9f002_t mt)

Sets the GreenR, Blue, Red and GreenB gains.

Definition at line 906 of file mt9f002.c.

References mt9f002_t::gain_blue, mt9f002_t::gain_green1, mt9f002_t::gain_green2, mt9f002_t::gain_red, MT9F002_BLUE_GAIN, mt9f002_calc_gain(), MT9F002_GREEN1_GAIN, MT9F002_GREEN2_GAIN, MT9F002_RED_GAIN, and write_reg().

Referenced by mt9f002_init(), mt9f002_reset_color(), mt9f002_setting_update_color(), and update_ae_awb().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mt9f002_setting_update_color ( float  in)

Definition at line 1133 of file mt9f002.c.

References mt9f002_set_gains().

+ Here is the call graph for this function:

void mt9f002_setting_update_exposure ( float  in)

Definition at line 1138 of file mt9f002.c.

References mt9f002_set_exposure().

+ Here is the call graph for this function:

static uint32_t read_reg ( struct mt9f002_t mt,
uint16_t  addr,
uint8_t  len 
)
static

Read multiple bytes from a register.

Definition at line 203 of file mt9f002.c.

References i2c_transaction::buf, i2c_blocking_transceive(), mt9f002_t::i2c_periph, mt9f002_t::i2c_trans, and MT9F002_ADDRESS.

Referenced by mt9f002_set_blanking(), mt9f002_set_exposure(), and mt9f002_set_pll().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void write_reg ( struct mt9f002_t mt,
uint16_t  addr,
uint32_t  val,
uint8_t  len 
)
static

Variable Documentation

struct video_config_t front_camera

Definition at line 90 of file mt9f002.c.

struct mt9f002_t mt9f002

Definition at line 123 of file mt9f002.c.

Referenced by update_ae_awb().

struct blanking_t mt9f002_blanking