More optimalizations and multithreading - 1FPS

This commit is contained in:
Adam Prochazka
2023-04-09 23:48:05 +02:00
parent ae0f8749b5
commit 374a63bc0c
12 changed files with 436 additions and 270 deletions

View File

@ -132,9 +132,66 @@ void Cam_Init(I2C_HandleTypeDef *hi2c, SPI_HandleTypeDef *hspi)
Cam_I2C_write(hi2c, (uint16_t)0x3621, 0x10); // REGISTER FOR CORRECT MIRROR FUNCTION
Cam_I2C_write(hi2c, (uint16_t)0x3801, 0xb0); // TIMING HORIZONTAL START - ALSO FOR MIRROR
Cam_I2C_write(hi2c, (uint16_t)0x4407, 0x04); // COMPRESSION CONTROL
Cam_I2C_write(hi2c, (uint16_t)0x5000, 0xFF);
Cam_I2C_write_bulk(hi2c, ov5642_1024x768);
// Setup camera, H-sync: High, V-sync:high, Sensor_delay: no Delay, FIFO_mode:FIFO enabled, power_mode:Low_power
Cam_SPI_write(hspi, 0x03, 0x02);
Cam_SPI_write(hspi, 0x01, 0x00); // Capture Control Register - Set to capture n+1 frames
HAL_Delay(5);
/*
Cam_I2C_write(hi2c, (uint16_t)0x3008, 0x80);
Cam_I2C_write_bulk(hi2c, OV5642_QVGA_Preview);
HAL_Delay(100);
Cam_I2C_write_bulk(hi2c, OV5642_JPEG_Capture_QSXGA);
//Cam_I2C_write_bulk(hi2c, ov5642_320x240);
//Cam_I2C_write_bulk(hi2c, ov5642_640x480);
HAL_Delay(100);
//Cam_I2C_write_bulk(hi2c, OV5642_720P_Video_setting);
Cam_I2C_write(hi2c, (uint16_t)0x3818, 0xa8); // TIMING CONTROL - ENABLE COMPRESSION, THUMBNAIL MODE DISABLE, VERTICAL FLIP, MIRROR
Cam_I2C_write(hi2c, (uint16_t)0x3621, 0x10); // REGISTER FOR CORRECT MIRROR FUNCTION
Cam_I2C_write(hi2c, (uint16_t)0x3801, 0xb0); // TIMING HORIZONTAL START - ALSO FOR MIRROR
//Cam_I2C_write(hi2c, (uint16_t)0x4407, 0x04); // COMPRESSION CONTROL
Cam_I2C_write(hi2c, (uint16_t)0x4407, 0x04); // COMPRESSION CONTROL
//Cam_I2C_write(hi2c, (uint16_t)0x5888, 0x01);
Cam_I2C_write(hi2c, (uint16_t)0x5000, 0xFF);
// Setup camera, H-sync: High, V-sync:high, Sensor_delay: no Delay, FIFO_mode:FIFO enabled, power_mode:Low_power
Cam_SPI_write(hspi, 0x03, 0x02);
Cam_I2C_write_bulk(hi2c, ov5642_320x240);
//Cam_I2C_write_bulk(hi2c, ov5642_1024x768);
Cam_SPI_write(hspi, 0x04, 0x01);
Cam_SPI_write(hspi, 0x01, 0x00); // Capture Control Register - Set to capture n+1 frames
HAL_Delay(5);
*/
}
void Cam_Refresh(I2C_HandleTypeDef *hi2c, SPI_HandleTypeDef *hspi){
/*Cam_I2C_write(hi2c, (uint16_t)0x3008, 0x80);
Cam_I2C_write_bulk(hi2c, OV5642_QVGA_Preview);
Cam_I2C_write_bulk(hi2c, OV5642_JPEG_Capture_QSXGA);
Cam_I2C_write(hi2c, (uint16_t)0x3818, 0xa8); // TIMING CONTROL - ENABLE COMPRESSION, THUMBNAIL MODE DISABLE, VERTICAL FLIP, MIRROR
Cam_I2C_write(hi2c, (uint16_t)0x3621, 0x10); // REGISTER FOR CORRECT MIRROR FUNCTION
Cam_I2C_write(hi2c, (uint16_t)0x3801, 0xb0); // TIMING HORIZONTAL START - ALSO FOR MIRROR
Cam_I2C_write(hi2c, (uint16_t)0x4407, 0x04); // COMPRESSION CONTROL
Cam_I2C_write_bulk(hi2c, ov5642_1280x960);
@ -142,29 +199,82 @@ void Cam_Init(I2C_HandleTypeDef *hi2c, SPI_HandleTypeDef *hspi)
Cam_SPI_write(hspi, 0x03, 0x02);
Cam_SPI_write(hspi, 0x01, 0x00); // Capture Control Register - Set to capture n+1 frames
HAL_Delay(5);
}
void Cam_Refresh(I2C_HandleTypeDef *hi2c, SPI_HandleTypeDef *hspi){
Cam_I2C_write(hi2c, (uint16_t)0x3008, 0x80);
HAL_Delay(5);*/
// SAFE TO REMOVE
//Cam_I2C_write(hi2c, (uint16_t)0x3008, 0x80);
Cam_I2C_write_bulk(hi2c, OV5642_QVGA_Preview);
Cam_I2C_write_bulk(hi2c, OV5642_JPEG_Capture_QSXGA);
//Cam_I2C_write_bulk(hi2c, OV5642_720P_Video_setting);
Cam_I2C_write(hi2c, (uint16_t)0x3818, 0xa8); // TIMING CONTROL - ENABLE COMPRESSION, THUMBNAIL MODE DISABLE, VERTICAL FLIP, MIRROR
Cam_I2C_write(hi2c, (uint16_t)0x3621, 0x10); // REGISTER FOR CORRECT MIRROR FUNCTION
Cam_I2C_write(hi2c, (uint16_t)0x3801, 0xb0); // TIMING HORIZONTAL START - ALSO FOR MIRROR
Cam_I2C_write(hi2c, (uint16_t)0x4407, 0x04); // COMPRESSION CONTROL
Cam_I2C_write(hi2c, (uint16_t)0x5000, 0xFF);
//Cam_I2C_write_bulk(hi2c, ov5642_320x240);
//ov5642_1024x768
Cam_I2C_write_bulk(hi2c, ov5642_1024x768);
// Setup camera, H-sync: High, V-sync:high, Sensor_delay: no Delay, FIFO_mode:FIFO enabled, power_mode:Low_power
Cam_SPI_write(hspi, 0x03, 0x02);
// Brightness 4
Cam_I2C_write(hi2c, (uint16_t)0x5001, 0xff);
Cam_I2C_write(hi2c, (uint16_t)0x5589, 0x30);
Cam_I2C_write(hi2c, (uint16_t)0x5580, 0x04);
Cam_I2C_write(hi2c, (uint16_t)0x558a, 0x00);
//Cam_I2C_write(hi2c, (uint16_t)0x558a, 0x08);
//Contrast 0
//Cam_I2C_write(hi2c, (uint16_t)0x5587, 0xff);
//Cam_I2C_write(hi2c, (uint16_t)0x5588, 0xff);
/*
// Exposure _17
Cam_I2C_write(hi2c, (uint16_t)0x3a0f, 0x10);
Cam_I2C_write(hi2c, (uint16_t)0x3a10, 0x08);
Cam_I2C_write(hi2c, (uint16_t)0x3a1b, 0x10);
Cam_I2C_write(hi2c, (uint16_t)0x3a1e, 0x08);
Cam_I2C_write(hi2c, (uint16_t)0x3a11, 0x20);
Cam_I2C_write(hi2c, (uint16_t)0x3a1f, 0x10);
//Exposure 17 v2
Cam_I2C_write(hi2c, (uint16_t)0x3a0f, 0x60);
Cam_I2C_write(hi2c, (uint16_t)0x3a10, 0x58);
Cam_I2C_write(hi2c, (uint16_t)0x3a11, 0xa0);
Cam_I2C_write(hi2c, (uint16_t)0x3a1b, 0x60);
Cam_I2C_write(hi2c, (uint16_t)0x3a1e, 0x58);
Cam_I2C_write(hi2c, (uint16_t)0x3a1f, 0x20);
*/
// Exposure Manual
Cam_I2C_write(hi2c, (uint16_t)0x3503, 0x3);
Cam_I2C_write(hi2c, (uint16_t)0x350C, 0xFF);
Cam_I2C_write(hi2c, (uint16_t)0x350D, 0xFF);
Cam_I2C_write(hi2c, (uint16_t)0x3500, 0x0);
Cam_I2C_write(hi2c, (uint16_t)0x3501, 0x00);
Cam_I2C_write(hi2c, (uint16_t)0x3502, 0x0f);
//Gain MAX
Cam_I2C_write(hi2c, (uint16_t)0x350A, 0x0);
Cam_I2C_write(hi2c, (uint16_t)0x350B, 0x35);
Cam_I2C_write(hi2c, (uint16_t)0x3508, 0x0);
Cam_I2C_write(hi2c, (uint16_t)0x3509, 0x35);
// AWB
Cam_I2C_write(hi2c, (uint16_t)0x3406, 0x1);
Cam_I2C_write(hi2c, (uint16_t)0x3400, 0xf);
Cam_I2C_write(hi2c, (uint16_t)0x3401, 0xff);
Cam_I2C_write(hi2c, (uint16_t)0x3402, 0xf);
Cam_I2C_write(hi2c, (uint16_t)0x3403, 0x7f);
Cam_I2C_write(hi2c, (uint16_t)0x3404, 0xf);
Cam_I2C_write(hi2c, (uint16_t)0x3405, 0xff);
Cam_SPI_write(hspi, 0x01, 0x00); // Capture Control Register - Set to capture n+1 frames
HAL_Delay(5);
@ -200,12 +310,12 @@ void Cam_Start_Capture(SPI_HandleTypeDef *hspi)
Cam_SPI_write(hspi, 0x04, FIFO_Reg_Clear_Flags); // Reset FIFO Read Pointer
Cam_SPI_write(hspi, 0x04, FIFO_Reg_Clear_Flags);
*/
Cam_SPI_write(hspi, 0x04, 0x01); // Start capture
Cam_SPI_write(hspi, 0x04, 0x01); // Start capture
Cam_SPI_write(hspi, 0x04, 0x01);
Cam_SPI_write(hspi, 0x04, 0x01);
HAL_Delay(1);
HAL_Delay(10);
Cam_SPI_write(hspi, 0x04, 0x02); // Start capture
HAL_Delay(1);
HAL_Delay(10);
}
void Cam_Wait_Capture_Done(SPI_HandleTypeDef *hspi)
@ -229,6 +339,9 @@ void Cam_Start_Burst_Read(SPI_HandleTypeDef *hspi)
Cam_SPI_write(hspi, 0x04, FIFO_Reg_Clear_Flags);
*/
Cam_SPI_write(hspi, 0x04, 0x01);
Cam_SPI_write(hspi, 0x04, 0x01);
uint8_t BURST_FIFO_READ = 0x3c;
uint8_t empty = 0x00;