35 #include <sys/ioctl.h>
37 #include <linux/i2c-dev.h>
38 #include <linux/types.h>
45 .dev_name =
"/dev/video0",
47 .format = V4L2_PIX_FMT_UYVY,
55 .dev_name =
"/dev/video1",
56 .subdev_name =
"/dev/v4l-subdev1",
57 .format = V4L2_PIX_FMT_SGBRG10,
67 if (write(fd, addr_val, cnt) != cnt) {
68 printf(
"Write failed!\n");
71 if (write(fd, addr_val, 2) != 2) {
72 printf(
"Write2 failed!\n");
75 while (read(fd, resp, cnt - 2) != cnt - 2) { ; }
76 for (i = 0; i < cnt - 2; i++) {
77 if (resp[i] != addr_val[i + 2]) {
78 printf(
"[video] Could not write register %X%X\n", addr_val[0], addr_val[1]);
87 if (write(fd, data, cnt) != cnt) {
93 #pragma GCC diagnostic push
94 #pragma GCC diagnostic ignored "-Wunused-result"
106 int pwm9 = open(
"/sys/class/pwm/pwm_9/run", O_WRONLY | O_CREAT | O_TRUNC, 0666);
112 tim.tv_nsec = 50000000;
113 nanosleep(&tim, NULL);
116 int fd_i2c = open(
"/dev/i2c-0", O_RDWR);
118 printf(
"[MT9V117] Could not open i2c-0\n");
121 if (ioctl(fd_i2c, 0x703, 0x5d) < 0) {
122 printf(
"[MT9V117] Could not change the i2c address to 0x5d\n");
127 write_reg(fd_i2c,
"\x00\x1a\x00\x01", 4);
128 write_reg(fd_i2c,
"\x00\x1a\x00\x00", 4);
130 tim.tv_nsec = 100000000;
131 nanosleep(&tim, NULL);
134 write_reg(fd_i2c,
"\x30\x1a\x10\xd0", 4);
135 write_reg(fd_i2c,
"\x31\xc0\x14\x04", 4);
136 write_reg(fd_i2c,
"\x3e\xd8\x87\x9c", 4);
137 write_reg(fd_i2c,
"\x30\x42\x20\xe1", 4);
138 write_reg(fd_i2c,
"\x30\xd4\x80\x20", 4);
139 write_reg(fd_i2c,
"\x30\xc0\x00\x26", 4);
140 write_reg(fd_i2c,
"\x30\x1a\x10\xd4", 4);
141 write_reg(fd_i2c,
"\xa8\x02\x00\xd3", 4);
142 write_reg(fd_i2c,
"\xc8\x78\x00\xa0", 4);
143 write_reg(fd_i2c,
"\xc8\x76\x01\x40", 4);
144 write_reg(fd_i2c,
"\xbc\x04\x00\xfc", 4);
145 write_reg(fd_i2c,
"\xbc\x38\x00\x7f", 4);
146 write_reg(fd_i2c,
"\xbc\x3a\x00\x7f", 4);
147 write_reg(fd_i2c,
"\xbc\x3c\x00\x7f", 4);
148 write_reg(fd_i2c,
"\xbc\x04\x00\xf4", 4);
150 _write(fd_i2c,
"\x09\x82\x00\x01", 4);
151 _write(fd_i2c,
"\x09\x8a\x70\x00", 4);
153 "\xf0\x00\x72\xcf\xff\x00\x3e\xd0\x92\x00\x71\xcf\xff\xff\xf2\x18\xb1\x10\x92\x05\xb1\x11\x92\x04\xb1\x12\x70\xcf\xff\x00\x30\xc0\x90\x00\x7f\xe0\xb1\x13\x70\xcf\xff\xff\xe7\x1c\x88\x36\x09\x0f\x00\xb3",
156 "\xf0\x30\x69\x13\xe1\x80\xd8\x08\x20\xca\x03\x22\x71\xcf\xff\xff\xe5\x68\x91\x35\x22\x0a\x1f\x80\xff\xff\xf2\x18\x29\x05\x00\x3e\x12\x22\x11\x01\x21\x04\x0f\x81\x00\x00\xff\xf0\x21\x8c\xf0\x10\x1a\x22",
159 "\xf0\x60\x10\x44\x12\x20\x11\x02\xf7\x87\x22\x4f\x03\x83\x1a\x20\x10\xc4\xf0\x09\xba\xae\x7b\x50\x1a\x20\x10\x84\x21\x45\x01\xc1\x1a\x22\x10\x44\x70\xcf\xff\x00\x3e\xd0\xb0\x60\xb0\x25\x7e\xe0\x78\xe0",
162 "\xf0\x90\x71\xcf\xff\xff\xf2\x18\x91\x12\x72\xcf\xff\xff\xe7\x1c\x8a\x57\x20\x04\x0f\x80\x00\x00\xff\xf0\xe2\x80\x20\xc5\x01\x61\x20\xc5\x03\x22\xb1\x12\x71\xcf\xff\x00\x3e\xd0\xb1\x04\x7e\xe0\x78\xe0",
165 "\xf0\xc0\x70\xcf\xff\xff\xe7\x1c\x88\x57\x71\xcf\xff\xff\xf2\x18\x91\x13\xea\x84\xb8\xa9\x78\x10\xf0\x03\xb8\x89\xb8\x8c\xb1\x13\x71\xcf\xff\x00\x30\xc0\xb1\x00\x7e\xe0\xc0\xf1\x09\x1e\x03\xc0\xc1\xa1",
168 "\xf0\xf0\x75\x08\x76\x28\x77\x48\xc2\x40\xd8\x20\x71\xcf\x00\x03\x20\x67\xda\x02\x08\xae\x03\xa0\x73\xc9\x0e\x25\x13\xc0\x0b\x5e\x01\x60\xd8\x06\xff\xbc\x0c\xce\x01\x00\xd8\x00\xb8\x9e\x0e\x5a\x03\x20",
171 "\xf1\x20\xd9\x01\xd8\x00\xb8\x9e\x0e\xb6\x03\x20\xd9\x01\x8d\x14\x08\x17\x01\x91\x8d\x16\xe8\x07\x0b\x36\x01\x60\xd8\x07\x0b\x52\x01\x60\xd8\x11\x8d\x14\xe0\x87\xd8\x00\x20\xca\x02\x62\x00\xc9\x03\xe0",
174 "\xf1\x50\xc0\xa1\x78\xe0\xc0\xf1\x08\xb2\x03\xc0\x76\xcf\xff\xff\xe5\x40\x75\xcf\xff\xff\xe5\x68\x95\x17\x96\x40\x77\xcf\xff\xff\xe5\x42\x95\x38\x0a\x0d\x00\x01\x97\x40\x0a\x11\x00\x40\x0b\x0a\x01\x00",
177 "\xf1\x80\x95\x17\xb6\x00\x95\x18\xb7\x00\x76\xcf\xff\xff\xe5\x44\x96\x20\x95\x15\x08\x13\x00\x40\x0e\x1e\x01\x20\xd9\x00\x95\x15\xb6\x00\xff\xa1\x75\xcf\xff\xff\xe7\x1c\x77\xcf\xff\xff\xe5\x46\x97\x40",
180 "\xf1\xb0\x8d\x16\x76\xcf\xff\xff\xe5\x48\x8d\x37\x08\x0d\x00\x81\x96\x40\x09\x15\x00\x80\x0f\xd6\x01\x00\x8d\x16\xb7\x00\x8d\x17\xb6\x00\xff\xb0\xff\xbc\x00\x41\x03\xc0\xc0\xf1\x0d\x9e\x01\x00\xe8\x04",
183 "\xf1\xe0\xff\x88\xf0\x0a\x0d\x6a\x01\x00\x0d\x8e\x01\x00\xe8\x7e\xff\x85\x0d\x72\x01\x00\xff\x8c\xff\xa7\xff\xb2\xd8\x00\x73\xcf\xff\xff\xf2\x40\x23\x15\x00\x01\x81\x41\xe0\x02\x81\x20\x08\xf7\x81\x34",
186 "\xf2\x10\xa1\x40\xd8\x00\xc0\xd1\x7e\xe0\x53\x51\x30\x34\x20\x6f\x6e\x5f\x73\x74\x61\x72\x74\x5f\x73\x74\x72\x65\x61\x6d\x69\x6e\x67\x20\x25\x64\x20\x25\x64\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
188 _write(fd_i2c,
"\xf2\x40\xff\xff\xe8\x28\xff\xff\xf0\xe8\xff\xff\xe8\x08\xff\xff\xf1\x54", 18);
189 _write(fd_i2c,
"\x09\x8e\x00\x00", 4);
190 _write(fd_i2c,
"\xe0\x00\x05\xd8", 4);
191 _write(fd_i2c,
"\xe0\x02\x04\x03", 4);
192 _write(fd_i2c,
"\xe0\x04\x00\x43\x01\x04", 6);
195 _write(fd_i2c,
"\x00\x40\x80\x01", 4);
196 while (test[0] != 0xFF || test[1] != 0XF8) {
198 tim.tv_nsec = 100000000;
199 nanosleep(&tim, NULL);
200 write(fd_i2c,
"\x00\x40", 2);
201 read(fd_i2c, test, 2);
202 printf(
"Da: %X%X\n", test[0], test[1]);
211 _write(fd_i2c,
"\xac\x40\x00\x00\xc3\x50", 6);
212 write_reg(fd_i2c,
"\xa4\x04\x00\x00", 4);
216 write_reg(fd_i2c,
"\x00\x30\x06\x01", 4);
217 write_reg(fd_i2c,
"\xc8\x00\x00\x0c", 4);
218 write_reg(fd_i2c,
"\xc8\x02\x00\x10", 4);
219 write_reg(fd_i2c,
"\xc8\x04\x01\xf3", 4);
220 write_reg(fd_i2c,
"\xc8\x06\x02\x97", 4);
221 write_reg(fd_i2c,
"\xc8\x08\x01\x11", 4);
222 write_reg(fd_i2c,
"\xc8\x0a\x00\xa4", 4);
223 write_reg(fd_i2c,
"\xc8\x0c\x02\xfa", 4);
224 write_reg(fd_i2c,
"\xc8\x12\x00\x31", 4);
225 write_reg(fd_i2c,
"\xc8\x14\x01\xe3", 4);
226 write_reg(fd_i2c,
"\xc8\x28\x00\x03", 4);
227 write_reg(fd_i2c,
"\xc8\x4c\x02\x80", 4);
228 write_reg(fd_i2c,
"\xc8\x4e\x01\xe0", 4);
231 write_reg(fd_i2c,
"\xc8\x54\x02\x80", 4);
232 write_reg(fd_i2c,
"\xc8\x56\x01\xe0", 4);
234 write_reg(fd_i2c,
"\xc8\xec\x00\x00", 4);
235 write_reg(fd_i2c,
"\xc8\xee\x00\x00", 4);
236 write_reg(fd_i2c,
"\xc8\xf0\x02\x7f", 4);
237 write_reg(fd_i2c,
"\xc8\xf2\x01\xdf", 4);
238 write_reg(fd_i2c,
"\xc8\xf4\x00\x02", 4);
239 write_reg(fd_i2c,
"\xc8\xf6\x00\x02", 4);
240 write_reg(fd_i2c,
"\xc8\xf8\x00\x7f", 4);
241 write_reg(fd_i2c,
"\xc8\xfa\x00\x5f", 4);
242 write_reg(fd_i2c,
"\xc8\x10\x03\x52", 4);
243 write_reg(fd_i2c,
"\xc8\x0e\x01\xff", 4);
244 write_reg(fd_i2c,
"\xc8\x16\x00\xd4", 4);
245 write_reg(fd_i2c,
"\xc8\x18\x00\xfe", 4);
246 write_reg(fd_i2c,
"\xc8\x1a\x00\x01", 4);
247 write_reg(fd_i2c,
"\xc8\x1c\x00\x02", 4);
248 write_reg(fd_i2c,
"\xc8\x1e\x00\x01", 4);
249 write_reg(fd_i2c,
"\xc8\x20\x00\x02", 4);
251 write(fd_i2c,
"\xc8\x58", 2);
252 read(fd_i2c, test, 2);
253 write_reg(fd_i2c,
"\xc8\x58\x00\x18", 4);
257 _write(fd_i2c,
"\x00\x40\x80\x02", 4);
260 while (test[0] != 0xFF || test[1] != 0XF8) {
262 tim.tv_nsec = 100000000;
263 nanosleep(&tim, NULL);
264 write(fd_i2c,
"\x00\x40", 2);
265 read(fd_i2c, test, 2);
266 printf(
"Dt: %X%X\n", test[0], test[1]);
287 printf(
"mt9f002_open");
300 printf(
"mt9f002_set_address");
311 data[0] = (
uint8_t)(reg >> 8) ;
316 printf(
"mt9f002_write_reg8");
333 data[2] = (
uint8_t)(value >> 8);
334 data[3] = value & 0xFF;
336 printf(
"mt9f002_write_reg16");
377 return data[1] | (data[0] << 8);
544 #pragma GCC diagnostic pop
#define MT9F002_P_GR_P3Q2
#define MT9F002_P_GB_P3Q1
#define MT9F002_P_GB_P1Q0
#define MT9F002_P_RD_P3Q4
#define MT9F002_P_GR_P4Q2
#define MT9F002_P_GB_P1Q2
#define MT9F002_X_ADDR_END_
#define MT9F002_P_GR_P4Q4
void mt9f002_init(void)
Initialisation of the Aptina MT9F002 CMOS sensor (1/2.3 inch 14Mp, front camera)
#define MT9F002_P_RD_P1Q1
#define MT9F002_GREEN2_GAIN
#define MT9F002_P_BL_P3Q4
#define MT9F002_P_BL_P0Q1
#define MT9F002_P_RD_P3Q1
#define MT9F002_P_GR_P4Q0
#define MT9F002_P_GR_P3Q4
#define MT9F002_P_BL_P4Q0
#define MT9F002_Y_ADDR_END_
#define MT9F002_CALIB_GREEN2
#define MT9F002_P_GB_P1Q1
#define MT9F002_P_GR_P1Q0
#define MT9F002_P_BL_P4Q3
#define MT9F002_P_GB_P3Q2
#define MT9F002_X_ODD_INC
#define MT9F002_P_GR_P3Q3
#define MT9F002_P_BL_P3Q1
#define MT9F002_P_BL_P2Q2
#define MT9F002_P_BL_P2Q3
#define MT9F002_P_BL_P2Q4
#define MT9F002_P_BL_P1Q1
#define MT9F002_P_GB_P1Q4
#define MT9F002_HISPI_TIMING
#define MT9F002_ANALOG_GAIN_CODE_RED
#define MT9F002_P_RD_P1Q3
#define MT9F002_P_RD_P1Q4
#define MT9F002_POLY_ORIGIN_R
#define MT9F002_P_BL_P2Q1
#define MT9F002_P_RD_P0Q2
#define MT9F002_P_BL_P3Q3
static bool_t write_reg(int fd, char *addr_val, uint8_t cnt)
#define MT9F002_ANALOG_GAIN_CODE_GREENB
#define MT9F002_P_GB_P0Q4
#define MT9F002_P_RD_P2Q1
#define MT9F002_P_BL_P0Q4
#define MT9F002_P_GB_P2Q0
#define MT9F002_P_RD_P3Q2
uint16_t mt9f002_read_reg16(uint16_t reg)
#define MT9F002_ROW_SPEED
Initialization of the video specific parts of the Bebop.
#define MT9F002_P_RD_P0Q1
#define MT9F002_P_BL_P0Q3
#define MT9F002_P_GB_P4Q1
struct video_config_t front_camera
#define MT9F002_P_BL_P0Q0
#define MT9F002_CALIB_RED_ASC1
#define MT9F002_P_RD_P2Q0
#define MT9F002_P_BL_P1Q0
#define MT9F002_CALIB_GREEN1
#define MT9F002_X_ADDR_START_
#define MT9F002_P_GB_P3Q0
#define MT9F002_P_RD_P1Q2
#define MT9F002_BLUE_GAIN
#define MT9F002_CALIB_GREEN2_ASC1
#define MT9F002_P_GB_P3Q3
#define MT9F002_P_BL_P2Q0
#define MT9F002_P_GR_P1Q2
#define MT9F002_P_GR_P2Q4
#define MT9F002_P_GB_P2Q4
#define MT9F002_P_GR_P0Q0
#define MT9F002_P_BL_P1Q3
#define MT9F002_P_GB_P4Q3
#define MT9F002_P_RD_P2Q4
#define MT9F002_P_GB_P2Q2
#define MT9F002_P_GR_P0Q3
#define MT9F002_P_RD_P3Q0
#define MT9F002_PLL_MULTIPLIER
#define MT9F002_READ_MODE
#define MT9F002_ANALOG_GAIN_CODE_BLUE
#define MT9F002_Y_ODD_INC
#define MT9F002_ANALOG_GAIN_CODE_GLOBAL
#define MT9F002_P_GR_P2Q3
void mt9f002_write_reg8(uint16_t reg, uint8_t value)
#define MT9F002_P_GB_P0Q3
#define MT9F002_CALIB_RED
#define MT9F002_P_BL_P1Q4
#define MT9F002_P_RD_P4Q0
#define VIDEO_FILTER_DEBAYER
#define MT9F002_CALIB_BLUE_ASC1
#define MT9F002_P_GB_P4Q4
#define MT9F002_P_GR_P3Q0
#define MT9F002_MIPI_TIMING_2
#define MT9F002_P_BL_P4Q1
#define MT9F002_MODE_SELECT
#define MT9F002_CALIB_GREEN1_ASC1
#define MT9F002_P_RD_P4Q2
void mt9v117_init(void)
Initialisation of the Aptina MT9V117 CMOS sensor (1/6 inch VGA, bottom camera)
#define MT9F002_P_GB_P2Q1
#define MT9F002_P_GR_P0Q4
#define MT9F002_P_BL_P4Q4
#define MT9F002_P_BL_P3Q0
#define MT9F002_P_GB_P2Q3
#define MT9F002_P_GR_P2Q0
#define MT9F002_P_GR_P1Q4
#define MT9F002_P_RD_P2Q2
struct video_config_t bottom_camera
#define MT9F002_ANALOG_GAIN_CODE_GREENR
#define MT9F002_P_RD_P4Q4
#define MT9F002_P_GR_P1Q1
#define MT9F002_OP_PIX_CLK_DIV
#define MT9F002_LINE_LENGTH_PCK
static bool_t _write(int fd, char *data, uint8_t cnt)
#define MT9F002_P_GR_P3Q1
#define MT9F002_P_GB_P0Q1
#define MT9F002_FRAME_LENGTH_LINES
#define MT9F002_CALIB_BLUE
#define MT9F002_P_GB_P4Q0
#define MT9F002_P_GR_P2Q1
uint8_t mt9f002_read_reg8(uint16_t reg)
#define MT9F002_GLOBAL_GAIN
#define MT9F002_P_GB_P4Q2
#define MT9F002_P_RD_P2Q3
#define MT9F002_P_RD_P0Q3
#define MT9F002_VT_PIX_CLK_DIV
#define MT9F002_P_GR_P4Q3
#define MT9F002_Y_ADDR_START_
#define MT9F002_P_GR_P2Q2
#define MT9F002_P_RD_P4Q1
void mt9f002_write_reg16(uint16_t reg, uint16_t value)
#define MT9F002_P_RD_P4Q3
#define MT9F002_P_RD_P0Q0
#define MT9F002_PRE_PLL_CLK_DIV
#define MT9F002_GREEN1_GAIN
#define MT9F002_P_GB_P3Q4
void mt9f002_set_address(uint8_t address)
#define MT9F002_P_GB_P0Q2
#define MT9F002_P_RD_P1Q0
#define MT9F002_P_BL_P3Q2
#define MT9F002_P_GR_P0Q2
#define MT9F002_P_BL_P0Q2
#define MT9F002_P_BL_P4Q2
#define MT9F002_DAC_ID_FBIAS
#define MT9F002_P_BL_P1Q2
#define MT9F002_SCALING_MODE
#define MT9F002_P_GR_P4Q1
#define MT9F002_POLY_ORIGIN_C
#define MT9F002_P_RD_P0Q4
#define MT9F002_P_GB_P0Q0
#define MT9F002_P_RD_P3Q3
#define MT9F002_P_GR_P1Q3
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
#define MT9F002_P_GB_P1Q3