-
Notifications
You must be signed in to change notification settings - Fork 340
/
mt9v034.h
148 lines (132 loc) · 5.17 KB
/
mt9v034.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/****************************************************************************
*
* Copyright (C) 2013 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef MT9V34_H_
#define MT9V34_H_
#include <stdint.h>
#include "settings.h"
/* Constants */
#define TIMEOUT_MAX 10000
#define BINNING_ROW_A 4
#define BINNING_COLUMN_A 4
#define BINNING_ROW_B 2
#define BINNING_COLUMN_B 2
#define MINIMUM_HORIZONTAL_BLANKING 91 // see datasheet
#define MAX_IMAGE_HEIGHT 480
#define MAX_IMAGE_WIDTH 752
#define MINIMUM_COLUMN_START 1
#define MINIMUM_ROW_START 4
/* Camera I2C registers */
#define mt9v034_DEVICE_WRITE_ADDRESS 0xB8
#define mt9v034_DEVICE_READ_ADDRESS 0xB9
/* Context A */
#define MTV_COLUMN_START_REG_A 0x01
#define MTV_ROW_START_REG_A 0x02
#define MTV_WINDOW_HEIGHT_REG_A 0x03
#define MTV_WINDOW_WIDTH_REG_A 0x04
#define MTV_HOR_BLANKING_REG_A 0x05
#define MTV_VER_BLANKING_REG_A 0x06
#define MTV_COARSE_SW_1_REG_A 0x08
#define MTV_COARSE_SW_2_REG_A 0x09
#define MTV_COARSE_SW_CTRL_REG_A 0x0A
#define MTV_COARSE_SW_TOTAL_REG_A 0x0B
#define MTV_FINE_SW_1_REG_A 0xD3
#define MTV_FINE_SW_2_REG_A 0xD4
#define MTV_FINE_SW_TOTAL_REG_A 0xD5
#define MTV_READ_MODE_REG_A 0x0D
#define MTV_V1_CTRL_REG_A 0x31
#define MTV_V2_CTRL_REG_A 0x32
#define MTV_V3_CTRL_REG_A 0x33
#define MTV_V4_CTRL_REG_A 0x34
#define MTV_ANALOG_GAIN_CTRL_REG_A 0x35
/* Context B */
#define MTV_COLUMN_START_REG_B 0xC9
#define MTV_ROW_START_REG_B 0xCA
#define MTV_WINDOW_HEIGHT_REG_B 0xCB
#define MTV_WINDOW_WIDTH_REG_B 0xCC
#define MTV_HOR_BLANKING_REG_B 0xCD
#define MTV_VER_BLANKING_REG_B 0xCE
#define MTV_COARSE_SW_1_REG_B 0xCF
#define MTV_COARSE_SW_2_REG_B 0xD0
#define MTV_COARSE_SW_CTRL_REG_B 0xD1
#define MTV_COARSE_SW_TOTAL_REG_B 0xD2
#define MTV_FINE_SW_1_REG_B 0xD6
#define MTV_FINE_SW_2_REG_B 0xD7
#define MTV_FINE_SW_TOTAL_REG_B 0xD8
#define MTV_READ_MODE_REG_B 0x0E
#define MTV_V1_CTRL_REG_B 0x39
#define MTV_V2_CTRL_REG_B 0x3A
#define MTV_V3_CTRL_REG_B 0x3B
#define MTV_V4_CTRL_REG_B 0x3C
#define MTV_ANALOG_GAIN_CTRL_REG_B 0x36
/* General Registers */
#define MTV_CHIP_VERSION_REG 0x00
#define MTV_CHIP_CONTROL_REG 0x07
#define MTV_SOFT_RESET_REG 0x0C
#define MTV_HDR_ENABLE_REG 0x0F
#define MTV_ADC_RES_CTRL_REG 0x1C
#define MTV_ROW_NOISE_CORR_CTRL_REG 0x70
#define MTV_TEST_PATTERN_REG 0x7F
#define MTV_TILED_DIGITAL_GAIN_REG 0x80
#define MTV_AGC_AEC_DESIRED_BIN_REG 0xA5
#define MTV_MAX_GAIN_REG 0xAB
#define MTV_MIN_EXPOSURE_REG 0xAC // datasheet min coarse shutter width
#define MTV_MAX_EXPOSURE_REG 0xAD // datasheet max coarse shutter width
#define MTV_AEC_AGC_ENABLE_REG 0xAF
#define MTV_AGC_AEC_PIXEL_COUNT_REG 0xB0
#define MTV_AEC_UPDATE_REG 0xA6
#define MTV_AEC_LOWPASS_REG 0xA8
#define MTV_AGC_UPDATE_REG 0xA9
#define MTV_AGC_LOWPASS_REG 0xAA
#define MTV_DIGITAL_TEST_REG 0x7F
/*
* Resolution:
* ROW_SIZE * BINNING_ROW <= MAX_IMAGE_WIDTH
* COLUMN_SIZE * BINNING_COLUMN <= MAX_IMAGE_HEIGHT
*/
#define FULL_IMAGE_SIZE (188*120)
#define FULL_IMAGE_ROW_SIZE (188)
#define FULL_IMAGE_COLUMN_SIZE (120)
/* Functions */
/**
* @brief Configures the mt9v034 camera with two context (binning 4 and binning 2).
*/
void mt9v034_context_configuration(void);
/**
* @brief Changes sensor context based on settings
*/
void mt9v034_set_context(void);
uint16_t mt9v034_ReadReg16(uint8_t address);
uint8_t mt9v034_WriteReg16(uint16_t address, uint16_t Data);
uint8_t mt9v034_ReadReg(uint16_t Addr);
uint8_t mt9v034_WriteReg(uint16_t Addr, uint8_t Data);
#endif /* MT9V34_H_ */