Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
mt9v117.c File Reference

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

#include "std.h"
#include "mt9v117.h"
#include "mt9v117_regs.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 <linux/v4l2-mediabus.h>
#include "boards/bebop.h"
Include dependency graph for mt9v117.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  mt9v117_patch_t

Macros

#define MT9V117_I2C_TRIES   3
#define MS9v117_CROP_WIDTH   240
#define MS9v117_CROP_HEIGHT   240
#define MT9V117_PATCH_LINE_NUM   13

Functions

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.
static void write_reg (struct mt9v117_t *mt, uint16_t addr, uint32_t val, uint16_t len)
 Write multiple bytes to a single register.
static uint32_t read_reg (struct mt9v117_t *mt, uint16_t addr, uint16_t len)
 Read multiple bytes from a register.
static void write_var (struct mt9v117_t *mt, uint16_t var, uint16_t offset, uint32_t val, uint16_t len)
static uint32_t read_var (struct mt9v117_t *mt, uint16_t var, uint16_t offset, uint16_t len)
static void mt9v117_write_patch (struct mt9v117_t *mt)
static void mt9v117_config (struct mt9v117_t *mt)
void mt9v117_init (struct mt9v117_t *mt)
 Initialisation of the Aptina MT9V117 CMOS sensor (1/6 inch VGA, bottom camera).

Variables

struct video_config_t bottom_camera
struct mt9v117_t mt9v117
static uint8_t patch_line1 []
static uint8_t patch_line2 []
static uint8_t patch_line3 []
static uint8_t patch_line4 []
static uint8_t patch_line5 []
static uint8_t patch_line6 []
static uint8_t patch_line7 []
static uint8_t patch_line8 []
static uint8_t patch_line9 []
static uint8_t patch_line10 []
static uint8_t patch_line11 []
static uint8_t patch_line12 []
static uint8_t patch_line13 []
static const struct mt9v117_patch_t mt9v117_patch_lines [MT9V117_PATCH_LINE_NUM]

Detailed Description

Initialization of MT9V117 chip and options to change settings.

Runs onboard AND in NPS (included by mt9v117_nps.c). NPS has no sensor: no I2C is done and every register reads as 0. So never configure from values read from the sensor (e.g. ask it for its resolution and store that in the struct): it would work onboard and break NPS.

Definition in file mt9v117.c.


Data Structure Documentation

◆ mt9v117_patch_t

struct mt9v117_patch_t

Definition at line 247 of file mt9v117.c.

Data Fields
uint8_t * data
uint16_t len

Macro Definition Documentation

◆ MS9v117_CROP_HEIGHT

#define MS9v117_CROP_HEIGHT   240

Definition at line 97 of file mt9v117.c.

◆ MS9v117_CROP_WIDTH

#define MS9v117_CROP_WIDTH   240

Definition at line 93 of file mt9v117.c.

◆ MT9V117_I2C_TRIES

#define MT9V117_I2C_TRIES   3

Definition at line 40 of file mt9v117.c.

Referenced by i2c_checked().

◆ MT9V117_PATCH_LINE_NUM

#define MT9V117_PATCH_LINE_NUM   13

Definition at line 144 of file mt9v117.c.

Referenced by mt9v117_write_patch().

Function Documentation

◆ i2c_checked()

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 )
static

Blocking I2C transaction with result check and retry.

Never resubmits while the previous transaction is still queued, and sets the register address again before each read (a failed read can overwrite it).

Returns
true when the transaction succeeded

Definition at line 49 of file mt9v117.c.

References i2c_transaction::buf, i2c_blocking_transceive(), i2c_blocking_transmit(), I2CTransPending, I2CTransRunning, I2CTransSuccess, MT9V117_I2C_TRIES, p, s, i2c_transaction::status, and timeout.

Referenced by mt9v117_write_patch(), read_reg(), and write_reg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mt9v117_config()

◆ mt9v117_init()

◆ mt9v117_write_patch()

◆ read_reg()

uint32_t read_reg ( struct mt9v117_t * mt,
uint16_t addr,
uint16_t len )
static

Read multiple bytes from a register.

Definition at line 298 of file mt9v117.c.

References i2c_transaction::buf, i2c_checked(), mt9v117_t::i2c_periph, mt9v117_t::i2c_trans, mt9v117_patch_t::len, and MT9V117_ADDRESS.

Referenced by mt9v117_init(), mt9v117_write_patch(), and read_var().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_var()

uint32_t read_var ( struct mt9v117_t * mt,
uint16_t var,
uint16_t offset,
uint16_t len )
static

Definition at line 322 of file mt9v117.c.

References mt9v117_patch_t::len, offset, and read_reg().

Referenced by mt9v117_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_reg()

void write_reg ( struct mt9v117_t * mt,
uint16_t addr,
uint32_t val,
uint16_t len )
static

Write multiple bytes to a single register.

Definition at line 271 of file mt9v117.c.

References i2c_transaction::buf, i2c_checked(), mt9v117_t::i2c_periph, mt9v117_t::i2c_trans, mt9v117_patch_t::len, MT9V117_ADDRESS, and val.

Referenced by mt9v117_config(), mt9v117_init(), mt9v117_write_patch(), and write_var().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_var()

void write_var ( struct mt9v117_t * mt,
uint16_t var,
uint16_t offset,
uint32_t val,
uint16_t len )
static

Definition at line 315 of file mt9v117.c.

References mt9v117_patch_t::len, offset, val, and write_reg().

Referenced by mt9v117_config(), mt9v117_init(), and mt9v117_write_patch().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ bottom_camera

struct video_config_t bottom_camera

Definition at line 106 of file mt9v117.c.

◆ mt9v117

struct mt9v117_t mt9v117
Initial value:
= {
.i2c_periph = &i2c0
}

Definition at line 138 of file mt9v117.c.

◆ mt9v117_patch_lines

const struct mt9v117_patch_t mt9v117_patch_lines[MT9V117_PATCH_LINE_NUM]
static
Initial value:
= {
}
static uint8_t patch_line3[]
Definition mt9v117.c:161
static uint8_t patch_line8[]
Definition mt9v117.c:201
static uint8_t patch_line9[]
Definition mt9v117.c:209
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
static uint8_t patch_line13[]
Definition mt9v117.c:241
static uint8_t patch_line12[]
Definition mt9v117.c:233
static uint8_t patch_line5[]
Definition mt9v117.c:177
static uint8_t patch_line11[]
Definition mt9v117.c:225
static uint8_t patch_line1[]
Definition mt9v117.c:145

Definition at line 252 of file mt9v117.c.

Referenced by mt9v117_write_patch().

◆ patch_line1

uint8_t patch_line1[]
static
Initial value:
= {
0xf0, 0x00, 0x72, 0xcf, 0xff, 0x00, 0x3e, 0xd0, 0x92, 0x00,
0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0xb1, 0x10, 0x92, 0x05,
0xb1, 0x11, 0x92, 0x04, 0xb1, 0x12, 0x70, 0xcf, 0xff, 0x00,
0x30, 0xc0, 0x90, 0x00, 0x7f, 0xe0, 0xb1, 0x13, 0x70, 0xcf,
0xff, 0xff, 0xe7, 0x1c, 0x88, 0x36, 0x09, 0x0f, 0x00, 0xb3
}

Definition at line 145 of file mt9v117.c.

◆ patch_line10

uint8_t patch_line10[]
static
Initial value:
= {
0xf1, 0xb0, 0x8d, 0x16, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x48,
0x8d, 0x37, 0x08, 0x0d, 0x00, 0x81, 0x96, 0x40, 0x09, 0x15,
0x00, 0x80, 0x0f, 0xd6, 0x01, 0x00, 0x8d, 0x16, 0xb7, 0x00,
0x8d, 0x17, 0xb6, 0x00, 0xff, 0xb0, 0xff, 0xbc, 0x00, 0x41,
0x03, 0xc0, 0xc0, 0xf1, 0x0d, 0x9e, 0x01, 0x00, 0xe8, 0x04
}

Definition at line 217 of file mt9v117.c.

◆ patch_line11

uint8_t patch_line11[]
static
Initial value:
= {
0xf1, 0xe0, 0xff, 0x88, 0xf0, 0x0a, 0x0d, 0x6a, 0x01, 0x00,
0x0d, 0x8e, 0x01, 0x00, 0xe8, 0x7e, 0xff, 0x85, 0x0d, 0x72,
0x01, 0x00, 0xff, 0x8c, 0xff, 0xa7, 0xff, 0xb2, 0xd8, 0x00,
0x73, 0xcf, 0xff, 0xff, 0xf2, 0x40, 0x23, 0x15, 0x00, 0x01,
0x81, 0x41, 0xe0, 0x02, 0x81, 0x20, 0x08, 0xf7, 0x81, 0x34
}

Definition at line 225 of file mt9v117.c.

◆ patch_line12

uint8_t patch_line12[]
static
Initial value:
= {
0xf2, 0x10, 0xa1, 0x40, 0xd8, 0x00, 0xc0, 0xd1, 0x7e, 0xe0,
0x53, 0x51, 0x30, 0x34, 0x20, 0x6f, 0x6e, 0x5f, 0x73, 0x74,
0x61, 0x72, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d,
0x69, 0x6e, 0x67, 0x20, 0x25, 0x64, 0x20, 0x25, 0x64, 0x0a,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}

Definition at line 233 of file mt9v117.c.

◆ patch_line13

uint8_t patch_line13[]
static
Initial value:
= {
0xf2, 0x40, 0xff, 0xff, 0xe8, 0x28, 0xff, 0xff, 0xf0, 0xe8,
0xff, 0xff, 0xe8, 0x08, 0xff, 0xff, 0xf1, 0x54
}

Definition at line 241 of file mt9v117.c.

◆ patch_line2

uint8_t patch_line2[]
static
Initial value:
= {
0xf0, 0x30, 0x69, 0x13, 0xe1, 0x80, 0xd8, 0x08, 0x20, 0xca,
0x03, 0x22, 0x71, 0xcf, 0xff, 0xff, 0xe5, 0x68, 0x91, 0x35,
0x22, 0x0a, 0x1f, 0x80, 0xff, 0xff, 0xf2, 0x18, 0x29, 0x05,
0x00, 0x3e, 0x12, 0x22, 0x11, 0x01, 0x21, 0x04, 0x0f, 0x81,
0x00, 0x00, 0xff, 0xf0, 0x21, 0x8c, 0xf0, 0x10, 0x1a, 0x22
}

Definition at line 153 of file mt9v117.c.

◆ patch_line3

uint8_t patch_line3[]
static
Initial value:
= {
0xf0, 0x60, 0x10, 0x44, 0x12, 0x20, 0x11, 0x02, 0xf7, 0x87,
0x22, 0x4f, 0x03, 0x83, 0x1a, 0x20, 0x10, 0xc4, 0xf0, 0x09,
0xba, 0xae, 0x7b, 0x50, 0x1a, 0x20, 0x10, 0x84, 0x21, 0x45,
0x01, 0xc1, 0x1a, 0x22, 0x10, 0x44, 0x70, 0xcf, 0xff, 0x00,
0x3e, 0xd0, 0xb0, 0x60, 0xb0, 0x25, 0x7e, 0xe0, 0x78, 0xe0
}

Definition at line 161 of file mt9v117.c.

◆ patch_line4

uint8_t patch_line4[]
static
Initial value:
= {
0xf0, 0x90, 0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x12,
0x72, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x8a, 0x57, 0x20, 0x04,
0x0f, 0x80, 0x00, 0x00, 0xff, 0xf0, 0xe2, 0x80, 0x20, 0xc5,
0x01, 0x61, 0x20, 0xc5, 0x03, 0x22, 0xb1, 0x12, 0x71, 0xcf,
0xff, 0x00, 0x3e, 0xd0, 0xb1, 0x04, 0x7e, 0xe0, 0x78, 0xe0
}

Definition at line 169 of file mt9v117.c.

◆ patch_line5

uint8_t patch_line5[]
static
Initial value:
= {
0xf0, 0xc0, 0x70, 0xcf, 0xff, 0xff, 0xe7, 0x1c, 0x88, 0x57,
0x71, 0xcf, 0xff, 0xff, 0xf2, 0x18, 0x91, 0x13, 0xea, 0x84,
0xb8, 0xa9, 0x78, 0x10, 0xf0, 0x03, 0xb8, 0x89, 0xb8, 0x8c,
0xb1, 0x13, 0x71, 0xcf, 0xff, 0x00, 0x30, 0xc0, 0xb1, 0x00,
0x7e, 0xe0, 0xc0, 0xf1, 0x09, 0x1e, 0x03, 0xc0, 0xc1, 0xa1
}

Definition at line 177 of file mt9v117.c.

◆ patch_line6

uint8_t patch_line6[]
static
Initial value:
= {
0xf0, 0xf0, 0x75, 0x08, 0x76, 0x28, 0x77, 0x48, 0xc2, 0x40,
0xd8, 0x20, 0x71, 0xcf, 0x00, 0x03, 0x20, 0x67, 0xda, 0x02,
0x08, 0xae, 0x03, 0xa0, 0x73, 0xc9, 0x0e, 0x25, 0x13, 0xc0,
0x0b, 0x5e, 0x01, 0x60, 0xd8, 0x06, 0xff, 0xbc, 0x0c, 0xce,
0x01, 0x00, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0x5a, 0x03, 0x20
}

Definition at line 185 of file mt9v117.c.

◆ patch_line7

uint8_t patch_line7[]
static
Initial value:
= {
0xf1, 0x20, 0xd9, 0x01, 0xd8, 0x00, 0xb8, 0x9e, 0x0e, 0xb6,
0x03, 0x20, 0xd9, 0x01, 0x8d, 0x14, 0x08, 0x17, 0x01, 0x91,
0x8d, 0x16, 0xe8, 0x07, 0x0b, 0x36, 0x01, 0x60, 0xd8, 0x07,
0x0b, 0x52, 0x01, 0x60, 0xd8, 0x11, 0x8d, 0x14, 0xe0, 0x87,
0xd8, 0x00, 0x20, 0xca, 0x02, 0x62, 0x00, 0xc9, 0x03, 0xe0
}

Definition at line 193 of file mt9v117.c.

◆ patch_line8

uint8_t patch_line8[]
static
Initial value:
= {
0xf1, 0x50, 0xc0, 0xa1, 0x78, 0xe0, 0xc0, 0xf1, 0x08, 0xb2,
0x03, 0xc0, 0x76, 0xcf, 0xff, 0xff, 0xe5, 0x40, 0x75, 0xcf,
0xff, 0xff, 0xe5, 0x68, 0x95, 0x17, 0x96, 0x40, 0x77, 0xcf,
0xff, 0xff, 0xe5, 0x42, 0x95, 0x38, 0x0a, 0x0d, 0x00, 0x01,
0x97, 0x40, 0x0a, 0x11, 0x00, 0x40, 0x0b, 0x0a, 0x01, 0x00
}

Definition at line 201 of file mt9v117.c.

◆ patch_line9

uint8_t patch_line9[]
static
Initial value:
= {
0xf1, 0x80, 0x95, 0x17, 0xb6, 0x00, 0x95, 0x18, 0xb7, 0x00,
0x76, 0xcf, 0xff, 0xff, 0xe5, 0x44, 0x96, 0x20, 0x95, 0x15,
0x08, 0x13, 0x00, 0x40, 0x0e, 0x1e, 0x01, 0x20, 0xd9, 0x00,
0x95, 0x15, 0xb6, 0x00, 0xff, 0xa1, 0x75, 0xcf, 0xff, 0xff,
0xe7, 0x1c, 0x77, 0xcf, 0xff, 0xff, 0xe5, 0x46, 0x97, 0x40
}

Definition at line 209 of file mt9v117.c.