Now copy the following code on the created file “main_camera.c”, save it, and analyze the code, comparing it with the D5M Datasheet, and the mentioned registers on the table 1.7, and 1.8.
/*
Written by Holguer Andres Becerra
for more go to www.fpgalover.com
*/
#include <stdio.h>
#include <stdlib.h>
#include <system.h>
#include "io.h"
#include "altera_up_avalon_audio_and_video_config.h"
#define D5M_COLUMN_SIZE 1919
#define D5M_ROW_SIZE 1079
#define D5M_COLUMN_BIN 0x0000
#define D5M_ROW_BIN 0x0000
#define EXPOSURE_LIMIT 1079
//Registers Addresses
unsigned char address[25] = { 0x00, 0x20, 0x09, 0x05, 0x06, 0x0A, 0x2B, 0x2C,
0x2D, 0x2E, 0x10, 0x11, 0x12, 0x10, 0x98, 0xA0, 0xA1, 0xA2, 0x01, 0x02,
0x03, 0x04, 0x22, 0x23, 0x49 };
//Registers Values
unsigned short data[25] = { 0x0000, 0xc000, EXPOSURE_LIMIT, 0x0000, 0x0019, 0x8000,
0x000b, 0x000f, 0x000f, 0x000b, 0x0051, 0x1807, 0x0002, 0x0053, 0x0000,
0x0000, 0x0000, 0x0FFF, 0x0036, 0x0010, D5M_ROW_SIZE, D5M_COLUMN_SIZE, D5M_ROW_BIN, D5M_COLUMN_BIN,
0x01A8 };
int i;
void init_d5m_camera(alt_up_av_config_dev * d5m) {
d5m->type = TRDB_D5M_CONFIG;
d5m->type = TRDB_D5M_CONFIG;
for (i = 0; i < 25; i++) {
alt_up_av_config_write_D5M_cfg_register(d5m, address[i], data[i]);
}
}
void set_d5m_exposure(alt_up_av_config_dev * d5m,unsigned short exposure){
alt_up_av_config_write_D5M_cfg_register(d5m, 0x09, exposure);
}
int main() {
alt_up_av_config_dev * d5m= alt_up_av_config_open_dev("/dev/camera_d5m_config");
init_d5m_camera(d5m);
unsigned short exposure = 0;
while (1) {
//exposure
set_d5m_exposure(d5m,exposure);
exposure += 100;
if(exposure>EXPOSURE_LIMIT*2){
exposure=0;
}
printf("exposure %d\n", exposure);
usleep(100000);
}
return 0;
}