Implemented group transmission, implemented camera init once

Develop
Sven Steudte 2017-09-03 04:10:34 +02:00
rodzic f4625bf753
commit 8f7d85f21e
3 zmienionych plików z 75 dodań i 56 usunięć

Wyświetl plik

@ -25,6 +25,8 @@
* With 1.8V only 15dBm can be done. Some serial-USB adapters also need a 3V IO level in
* order to work. However 3V takes a lot of power in idle. You can save energy using 1.8V. */
#define KEEP_CAM_SWITCHED_ON TRUE /* Keep camera switched on and initialized after it has been switched on once, no configuration change is possible */
void start_user_modules(void);
extern module_conf_t config[9];

Wyświetl plik

@ -469,63 +469,63 @@ static const struct regval_list OV5640_5MP_JPEG[] =
//320x240 QVGA
static const struct regval_list OV5640_QSXGA2QVGA[] =
{
{0x3800 ,0x00},
{0x3801 ,0x00},
{0x3802 ,0x00},
{0x3803 ,0x00},
{0x3804 ,0xA },
{0x3805 ,0x3f},
{0x3806 ,0x7 },
{0x3807 ,0x9f},
{0x3808 ,0x1 },
{0x3809 ,0x40},
{0x380a ,0x0 },
{0x380b ,0xf0},
{0x380c ,0xc },
{0x380d ,0x80},
{0x380e ,0x7 },
{0x380f ,0xd0},
{0x5001 ,0xa3},
{0x5680 ,0x0 },
{0x5681 ,0x0 },
{0x5682 ,0xA },
{0x5683 ,0x20},
{0x5684 ,0x0 },
{0x5685 ,0x0 },
{0x5686 ,0x7 },
{0x5687 ,0x98},
{0xffff, 0xff},
{0x3800 ,0x00},
{0x3801 ,0x00},
{0x3802 ,0x00},
{0x3803 ,0x00},
{0x3804 ,0xA },
{0x3805 ,0x3f},
{0x3806 ,0x7 },
{0x3807 ,0x9f},
{0x3808 ,0x1 },
{0x3809 ,0x40},
{0x380a ,0x0 },
{0x380b ,0xf0},
{0x380c ,0xc },
{0x380d ,0x80},
{0x380e ,0x7 },
{0x380f ,0xd0},
{0x5001 ,0xa3},
{0x5680 ,0x0 },
{0x5681 ,0x0 },
{0x5682 ,0xA },
{0x5683 ,0x20},
{0x5684 ,0x0 },
{0x5685 ,0x0 },
{0x5686 ,0x7 },
{0x5687 ,0x98},
{0xffff, 0xff},
};
//640x480 VGA
static const struct regval_list OV5640_QSXGA2VGA[] =
{
{0x3800 ,0x00},
{0x3801 ,0x00},
{0x3802 ,0x00},
{0x3803 ,0x00},
{0x3804 ,0xA },
{0x3805 ,0x3f},
{0x3806 ,0x7 },
{0x3807 ,0x9f},
{0x3808 ,0x2 },
{0x3809 ,0x80},
{0x380a ,0x1 },
{0x380b ,0xe0},
{0x380c ,0xc },
{0x380d ,0x80},
{0x380e ,0x7 },
{0x380f ,0xd0},
{0x5001 ,0xa3},
{0x5680 ,0x0 },
{0x5681 ,0x0 },
{0x5682 ,0xA },
{0x3800 ,0x00},
{0x3801 ,0x00},
{0x3802 ,0x00},
{0x3803 ,0x00},
{0x3804 ,0xA },
{0x3805 ,0x3f},
{0x3806 ,0x7 },
{0x3807 ,0x9f},
{0x3808 ,0x2 },
{0x3809 ,0x80},
{0x380a ,0x1 },
{0x380b ,0xe0},
{0x380c ,0xc },
{0x380d ,0x80},
{0x380e ,0x7 },
{0x380f ,0xd0},
{0x5001 ,0xa3},
{0x5680 ,0x0 },
{0x5681 ,0x0 },
{0x5682 ,0xA },
{0x5683 ,0x20},
{0x5684 ,0x0 },
{0x5685 ,0x0 },
{0x5686 ,0x7 },
{0x5687 ,0x98},
{0xffff, 0xff},
{0x5685 ,0x0 },
{0x5686 ,0x7 },
{0x5687 ,0x98},
{0xffff, 0xff},
};
//800x480 WVGA
@ -733,9 +733,15 @@ static bool vsync;
static bool dma_error;
static uint32_t dma_flags;
static uint32_t oldSpeed;
static uint32_t oldWS;
/* Increase AHB clock to 48 MHz */
void set48MHz(void)
{
oldSpeed = RCC->CFGR & RCC_CFGR_HPRE_Msk;
oldWS = FLASH->ACR & FLASH_ACR_LATENCY_Msk;
uint32_t new = (FLASH->ACR & ~FLASH_ACR_LATENCY_Msk) | FLASH_ACR_LATENCY_3WS;
FLASH->ACR = new;
while(FLASH->ACR != new);
@ -748,11 +754,11 @@ void set48MHz(void)
void set6MHz(void)
{
// Reduce AHB clock to 6 MHz
uint32_t new = (RCC->CFGR & ~RCC_CFGR_HPRE_Msk) | RCC_CFGR_HPRE_DIV8;
uint32_t new = (RCC->CFGR & ~RCC_CFGR_HPRE_Msk) | oldSpeed;
RCC->CFGR = new;
while(RCC->CFGR != new);
new = (FLASH->ACR & ~FLASH_ACR_LATENCY_Msk) | FLASH_ACR_LATENCY_0WS;
new = (FLASH->ACR & ~FLASH_ACR_LATENCY_Msk) | oldWS;
FLASH->ACR = new;
while(FLASH->ACR != new);
}
@ -1364,7 +1370,7 @@ void OV5640_init(ssdv_conf_t *config) {
// Power on OV5640
TRACE_INFO("CAM > Switch on");
palSetLine(LINE_CAM_EN); // Switch on camera
palSetLine(LINE_CAM_RESET); // Toggle reset
palSetLine(LINE_CAM_RESET); // Toggle reset
chThdSleepMilliseconds(1000);

Wyświetl plik

@ -379,6 +379,7 @@ void encode_ssdv(const uint8_t *image, uint32_t image_len, module_conf_t* conf,
THD_FUNCTION(imgThread, arg) {
module_conf_t* conf = (module_conf_t*)arg;
bool camInitialized = false;
systime_t time = chVTGetSystemTimeX();
while(true)
@ -406,7 +407,7 @@ THD_FUNCTION(imgThread, arg) {
bool camera_found = false;
// Detect camera
if(OV5640_isAvailable()) { // OV5640 available
if(camInitialized || OV5640_isAvailable()) { // OV5640 available
TRACE_INFO("IMG > OV5640 found");
camera_found = true;
@ -418,7 +419,10 @@ THD_FUNCTION(imgThread, arg) {
do {
// Init camera
OV5640_init(&conf->ssdv_conf);
if(!camInitialized) {
OV5640_init(&conf->ssdv_conf);
camInitialized = true;
}
// Sample data from DCMI through DMA into RAM
tries = 5; // Try 5 times at maximum
@ -435,7 +439,10 @@ THD_FUNCTION(imgThread, arg) {
} else { // Static resolution
// Init camera
OV5640_init(&conf->ssdv_conf);
if(!camInitialized) {
OV5640_init(&conf->ssdv_conf);
camInitialized = true;
}
// Sample data from DCMI through DMA into RAM
tries = 5; // Try 5 times at maximum
@ -446,7 +453,10 @@ THD_FUNCTION(imgThread, arg) {
}
// Switch off camera
#if !KEEP_CAM_SWITCHED_ON
OV5640_deinit();
camInitialized = false;
#endif
// Get image
image_len = OV5640_getBuffer(&image);
@ -454,6 +464,7 @@ THD_FUNCTION(imgThread, arg) {
} else { // Camera error
camInitialized = false;
TRACE_ERROR("IMG > No camera found");
}