Всем привет. Использую камеру MT9D131 и проц at91sam9g20
сумел поднять под линукс twi и как следствие настроить камеру, получилось завести драйвер atmel-isi. могу получать картинки (raw) в режиме превью
получилось достичь результатов максимум 9-10 FPS.
Научился переключаться в контекст Б, при выключенном Jpeg можем получать картинку(raw) заданного размера (согласно контексту Б)
Но при включение Jpeg сжатия, нет прерывания в isi интерфейсе, и я так понимаю, что не приходят маркеры...
Вопрос: каким образом настроит камеру, чтобы при включении контекста Б можно было получить Jpeg картинку?
Что и как я делаю:Функция, которая прошивает регистры камеры:Код
unsigned char mt9d313_config_capture(int fd)
{
unsigned char status = 0;
struct twiData mode, state;
status = mt9d131_write_regs(fd, soft_reset1, 3);
usleep(1000);
status = mt9d131_write_regs(fd, soft_reset2, 1);
usleep(500000);
status = mt9d131_write_regs2(fd, settings, 177);
usleep(500000);
status = mt9d131_write_regs2(fd, set_Jpeg_mode,15);
usleep(500000);
status = mt9d131_write_regs2(fd, set_Capturing_Still_Pictures_mode, 17);
usleep(500000);
status = mt9d131_write_regs2(fd, refresh_seq_mode, 2);
usleep(1000000);
//status = mt9d131_write_regs2(fd, bt656_switch, 1);
//*
mode.Page = 1;
mode.Reg = 0xC6;
mode.Data = 0xA104; //mode.state
state.Page = 1;
state.Reg = 0xC8;
state.Data = 0;
mt9d131_write_regs(fd, Set_StepMode, 2);
//Переключаемся в контекст Б
while (1) // Waiting for context B state (hex: 0x07)
{
status = mt9d131_write_regs(fd, set_Capture_mode, 2);
if ((state.Data & 0xFF) == 0x04)
mt9d131_write_regs(fd,Next_step, 2);
if ((state.Data & 0xFF) == 0x05)
mt9d131_write_regs(fd,Next_step, 2);
if ((state.Data & 0xFF) == 0x06)
mt9d131_write_regs(fd,Next_step, 2);
usleep(50000);
write(fd, &mode, 1);
usleep(50000);
read(fd, &state, 1);
if ((state.Data & 0xFF) == 0x07) //0x07
break;
}
usleep(3000000);//1000000
status = mt9d131_write_regs2(fd, bt656_switch, 1);
//*/
if (status)
printf("TWI:Capture configuring failed \n");
return status;
}
Массивы настроек:Код
const struct twiData soft_reset1[] = {
{0, 0x65, 0xA000}, // bypassed PLL (prepare for soft reset)
{1, 0xC3, 0x0501}, // MCU_BOOT_MODE (MCU reset)
{0, 0x0D, 0x0021} // RESET_REG (enable soft reset)
};
const struct twiData soft_reset2[] = {
{0, 0x0D, 0x0000} // RESET_REG (disable soft reset)
};
const struct twiData settings[] = {
{0, 0x05, 0x011E}, //HBLANK (B) = 516
{0, 0x06, 0x000B}, //VBLANK (B) = 31
{0, 0x07, 0x011E}, //HBLANK (A) = 254
{0, 0x08, 0x000B}, //VBLANK (A) = 11
{0, 0x20, 0x0300}, //Read Mode (B) = 768
{0, 0x21, 0x0000}, //Read Mode (A) = 33792
{0, 0x66, 0xA00B}, //PLL Control 1 = 20235 0x400A
{0, 0x67, 0x0000}, //PLL Control 2 = 1280
{0, 0x65, 0xA000}, //Clock CNTRL: PLL ON = 40960
{0, 0x65, 0x2000}, //Clock CNTRL: USE PLL = 8192
//;Sequencer States...
{1, 0xC6, 0xA122}, //Enter Preview: Auto Exposure
{1, 0xC8, 0x01}, // = 1
{1, 0xC6, 0xA123}, //Enter Preview: Flicker Detection
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA124}, //Enter Preview: Auto White Balance
{1, 0xC8, 0x01}, // = 1
{1, 0xC6, 0xA125}, //Enter Preview: Auto Focus
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA126}, //Enter Preview: Histogram
{1, 0xC8, 0x01}, // = 1
{1, 0xC6, 0xA127}, //Enter Preview: Strobe Control
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA128}, //Enter Preview: Skip Control
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA129}, //In Preview: Auto Exposure
{1, 0xC8, 0x03}, // = 3
{1, 0xC6, 0xA12A}, //In Preview: Flicker Detection
{1, 0xC8, 0x02}, // = 2
{1, 0xC6, 0xA12B}, //In Preview: Auto White Balance
{1, 0xC8, 0x03}, // = 3
{1, 0xC6, 0xA12C}, //In Preview: Auto Focus
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA12D}, //In Preview: Histogram
{1, 0xC8, 0x03}, // = 3
{1, 0xC6, 0xA12E}, //In Preview: Strobe Control
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA12F}, //In Preview: Skip Control
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA130}, //Exit Preview: Auto Exposure
{1, 0xC8, 0x04}, // = 4
{1, 0xC6, 0xA131}, //Exit Preview: Flicker Detection
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA132}, //Exit Preview: Auto White Balance
{1, 0xC8, 0x01}, // = 1
{1, 0xC6, 0xA133}, //Exit Preview: Auto Focus
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA134}, //Exit Preview: Histogram
{1, 0xC8, 0x01}, // = 1
{1, 0xC6, 0xA135}, //Exit Preview: Strobe Control
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA136}, //Exit Preview: Skip Control
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA137}, //Capture: Auto Exposure
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA138}, //Capture: Flicker Detection
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA139}, //Capture: Auto White Balance
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA13A}, //Capture: Auto Focus
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA13B}, //Capture: Histogram
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA13C}, //Capture: Strobe Control
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA13D}, //Capture: Skip Control
{1, 0xC8, 0x00}, // = 0
//;Setting Up Output format and ITU-R BT.601/656
{1, 0xC6, 0xA77D},
{1, 0xC8, 0x10},
{1, 0xC6, 0XA77E},
{1, 0xC8, 0x10},
//;Setting decimation to 800x600 resolution (context A)
{1, 0xC6, 0x2703},
{1, 0xC8, 0x280}, // 0x280
{1, 0xC6, 0x2705},
{1, 0xC8, 0x1E0},//0x1E0
//;Setting decimation to 1600x1200 resolution (context B)
{1, 0xC6, 0x2707},
{1, 0xC8, 0x320},
{1, 0xC6, 0x2709},
{1, 0xC8, 0x258},
//;Custom gamma tables...
{1, 0xC6, 0xA745}, //Gamma Table 0 (A)
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA746}, //Gamma Table 1 (A)
{1, 0xC8, 0x27}, // = 39
{1, 0xC6, 0xA747}, //Gamma Table 2 (A)
{1, 0xC8, 0x35}, // = 53
{1, 0xC6, 0xA748}, //Gamma Table 3 (A)
{1, 0xC8, 0x48}, // = 72
{1, 0xC6, 0xA749}, //Gamma Table 4 (A)
{1, 0xC8, 0x63}, // = 99
{1, 0xC6, 0xA74A}, //Gamma Table 5 (A)
{1, 0xC8, 0x77}, // = 119
{1, 0xC6, 0xA74B}, //Gamma Table 6 (A)
{1, 0xC8, 0x88}, // = 136
{1, 0xC6, 0xA74C}, //Gamma Table 7 (A)
{1, 0xC8, 0x96}, // = 150
{1, 0xC6, 0xA74D}, //Gamma Table 8 (A)
{1, 0xC8, 0xA3}, // = 163
{1, 0xC6, 0xA74E}, //Gamma Table 9 (A)
{1, 0xC8, 0xAF}, // = 175
{1, 0xC6, 0xA74F}, //Gamma Table 10 (A)
{1, 0xC8, 0xBA}, // = 186
{1, 0xC6, 0xA750}, //Gamma Table 11 (A)
{1, 0xC8, 0xC4}, // = 196
{1, 0xC6, 0xA751}, //Gamma Table 12 (A)
{1, 0xC8, 0xCE}, // = 206
{1, 0xC6, 0xA752}, //Gamma Table 13 (A)
{1, 0xC8, 0xD7}, // = 215
{1, 0xC6, 0xA753}, //Gamma Table 14 (A)
{1, 0xC8, 0xE0}, // = 224
{1, 0xC6, 0xA754}, //Gamma Table 15 (A)
{1, 0xC8, 0xE8}, // = 232
{1, 0xC6, 0xA755}, //Gamma Table 16 (A)
{1, 0xC8, 0xF0}, // = 240
{1, 0xC6, 0xA756}, //Gamma Table 17 (A)
{1, 0xC8, 0xF8}, // = 248
{1, 0xC6, 0xA757}, //Gamma Table 18 (A)
{1, 0xC8, 0xFF}, // = 255
{1, 0xC6, 0xA758}, //Gamma Table 0 (B)
{1, 0xC8, 0x00}, // = 0
{1, 0xC6, 0xA759}, //Gamma Table 1 (B)
{1, 0xC8, 0x27}, // = 39
{1, 0xC6, 0xA75A}, //Gamma Table 2 (B)
{1, 0xC8, 0x35}, // = 53
{1, 0xC6, 0xA75B}, //Gamma Table 3 (B)
{1, 0xC8, 0x48}, // = 72
{1, 0xC6, 0xA75C}, //Gamma Table 4 (B)
{1, 0xC8, 0x63}, // = 99
{1, 0xC6, 0xA75D}, //Gamma Table 5 (B)
{1, 0xC8, 0x77}, // = 119
{1, 0xC6, 0xA75E}, //Gamma Table 6 (B)
{1, 0xC8, 0x88}, // = 136
{1, 0xC6, 0xA75F}, //Gamma Table 7 (B)
{1, 0xC8, 0x96}, // = 150
{1, 0xC6, 0xA760}, //Gamma Table 8 (B)
{1, 0xC8, 0xA3}, // = 163
{1, 0xC6, 0xA761}, //Gamma Table 9 (B)
{1, 0xC8, 0xAF}, // = 175
{1, 0xC6, 0xA762}, //Gamma Table 10 (B)
{1, 0xC8, 0xBA}, // = 186
{1, 0xC6, 0xA763}, //Gamma Table 11 (B)
{1, 0xC8, 0xC4}, // = 196
{1, 0xC6, 0xA764}, //Gamma Table 12 (B)
{1, 0xC8, 0xCE}, // = 206
{1, 0xC6, 0xA765}, //Gamma Table 13 (B)
{1, 0xC8, 0xD7}, // = 215
{1, 0xC6, 0xA766}, //Gamma Table 14 (B)
{1, 0xC8, 0xE0}, // = 224
{1, 0xC6, 0xA767}, //Gamma Table 15 (B)
{1, 0xC8, 0xE8}, // = 232
{1, 0xC6, 0xA768}, //Gamma Table 16 (B)
{1, 0xC8, 0xF0}, // = 240
{1, 0xC6, 0xA769}, //Gamma Table 17 (B)
{1, 0xC8, 0xF8}, // = 248
{1, 0xC6, 0xA76A}, //Gamma Table 18 (B)
{1, 0xC8, 0xFF}, // = 255
{1, 0xC6, 0x276D}, //FIFO_Conf1 (A)
{1, 0xC8, 0xE0E2}, // = 57570
{1, 0xC6, 0xA76F}, //FIFO_Conf2 (A)
{1, 0xC8, 0xE1}, // = 225
{1, 0xC6, 0x2774}, //FIFO_Conf1 (B)
{1, 0xC8, 0xE0E1}, // = 57569
{1, 0xC6, 0xA776}, //FIFO_Conf2 (B)
{1, 0xC8, 0xE1}, // = 225
{1, 0xC6, 0x220B}, //Max R12 (B)(Shutter Delay)
{1, 0xC8, 0x0192}, // = 402
{1, 0xC6, 0xA217}, //IndexTH23
{1, 0xC8, 0x08}, // = 8
{1, 0xC6, 0x2228}, //RowTime (msclk per)/4
{1, 0xC8, 0x020F}, // = 527
{1, 0xC6, 0x222F}, //R9 Step
{1, 0xC8, 0x009A}, // = 154
{1, 0xC6, 0xA408}, //search_f1_50
{1, 0xC8, 0x24}, // = 36
{1, 0xC6, 0xA409}, //search_f2_50
{1, 0xC8, 0x26}, // = 38
{1, 0xC6, 0xA40A}, //search_f1_60
{1, 0xC8, 0x1D}, // = 29
{1, 0xC6, 0xA40B}, //search_f2_60
{1, 0xC8, 0x1F}, // = 31
{1, 0xC6, 0x2411}, //R9_Step_60
{1, 0xC8, 0x009A}, // = 154
{1, 0xC6, 0x2413}, //R9_Step_50
{1, 0xC8, 0x00B9} // = 185
};
const struct twiData refresh_seq_mode[] = {
{1, 0xC6, 0xA103}, //Refresh Sequencer Mode
{1, 0xC8, 0x06} // = 6
};
const struct twiData refresh_seq[] = {
{1, 0xC6, 0xA103}, //Refresh Sequencer
{1, 0xC8, 0x05}, // = 5
};
const struct twiData bt656_switch[] = {
{2, 0x0D, 0x003E} //при включенном джипег
//{2, 0x0D, 0x0427} //при выключенном джипег
};
const struct twiData set_Capturing_Still_Pictures_mode[] = {
{1, 0xC6, 0xA120},
{1, 0xC8, 0x00}, //1. First clear the capture video mode bit: seq.captureParams.mode[1] = 0
//-- Image cropping and scaling
//2. Next, specify the output image size for context B by using the variables
//mode.Output Width_B and mode.Output Height_B.
{1, 0xC6, 0x2707},
{1, 0xC8, 0x0320},//mode.output_width_B = 800
{1, 0xC6, 0x2709},
{1, 0xC8, 0x0258},//mode.output_height_B = 600
{1, 0xC6, 0x2735}, //Crop_X0 (B)
{1, 0xC8, 0x0000}, // = 0
{1, 0xC6, 0x2737}, //Crop_X1 (B)
{1, 0xC8, 0x0640}, // = 1600
{1, 0xC6, 0x2739}, //Crop_Y0 (B)
{1, 0xC8, 0x0000}, // = 0
{1, 0xC6, 0x273B}, //Crop_Y1 (B)
{1, 0xC8, 0x04B0}, // = 1200
{0, 0x20, (1<<10) | (1 << 15)}, // R0x20:0[10] = 1 and R0x20:0[15] = 1
{1, 0xC6, 0xA121},
{1, 0xC8, 0x0002} // 2 for this example (ID = 1, Offset = 0x21)
};
const struct twiData Set_StepMode[] = {
{1, 0xC6, 0xA105},
{1, 0xC8, 0x0003}
};
const struct twiData Next_step[] = {
{1, 0xC6, 0xA105},
{1, 0xC8, 0x0003}
};
const struct twiData set_Jpeg_mode[] = {
{1, 0xC6, 0x270B},
{1, 0xC8, 0x00}, //To enable JPEG output, set mode.mode_config[5] = 0.
{1, 0xC6, 0xA906}, //jpeg.format // 0 = 4:2:2, 1 = 4:2:0, 2 = monochrome (ID = 9, Offset =0x06)
{1, 0xC8, 0x02}, //jpeg.format = 0x00
{1, 0xC6, 0xA907},
{1, 0xC8, 0x00},
{1, 0xC6, 0x2908},
{1, 0xC8, 0x01},
{1, 0xC6, 0xA120},
{1, 0xC8, 0x00}, //seq.captureParams_mode = 0x00[b] //capture still image
//-- JPEG config
{1, 0xC6, 0xA90A},
{1, 0xC8, 0x89}, //jpeg.qscale1 = 0x89[b]
{1, 0xC6, 0x2908},
{1, 0xC8, 0x0020},//jpeg.restartInt = 0x0020
{1, 0x97, 0x0010},
// {1, 0xC6, 0x270B},
// {1, 0xC8, 0x01 | (1 << 5)} //To Disable JPEG output
};
Вторую неделю пытаюсь настроить, но что-то я упускаю, не могу понять что.
При этом, если считывать статусный регистр Jpeg-а, то длинна данных всегда разная, я так понимаю, это говорит, что джипег всеже включился. Но прерывания так и нету.