Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.

Dependencies:   mbed

Revision:
11:404bd8bb7fa6
Parent:
10:f2447c682c0f
Child:
12:7d75ba5deed1
--- a/camera_app/camera_app.cpp	Mon Jul 06 23:20:14 2015 +0000
+++ b/camera_app/camera_app.cpp	Tue Jul 07 22:56:31 2015 +0000
@@ -326,29 +326,32 @@
 //!                               
 //
 //*****************************************************************************
-DCMI_HandleTypeDef phdcmi;
-DMA_HandleTypeDef hdma_dcmi;
 static unsigned short CaptureImage(char** WriteBuffer)
 {
+	DCMI_HandleTypeDef phdcmi;
+    DMA_HandleTypeDef hdma_dcmi;
 //    Uart_Write((uint8_t*)"CaptureImage \n\r");
-//    memset(g_image.g_image_buffer,0xF80F,sizeof(g_image.g_image_buffer));
-    memset(g_image.g_image_buffer,0x0F,sizeof(g_image.g_image_buffer));
+    memset(g_image.g_image_buffer,0xF80F,sizeof(g_image.g_image_buffer));
+//    memset(g_image.g_image_buffer,0x0F,sizeof(g_image.g_image_buffer));
     p_buffer = &(g_image.g_image_buffer[0]);
     
     DMAConfig();
-    
+
     //
     // Perform Image Capture 
     //
 //    wait_ms(500);
+#ifdef ENABLE_JPEG
     HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)p_buffer, NUM_OF_4B_CHUNKS);
-//    HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)p_buffer, FRAME_SIZE_IN_BYTES/4); 
+#else
+    HAL_DCMI_Start_DMA(&phdcmi, DCMI_MODE_CONTINUOUS, (uint32_t)p_buffer, NUM_OF_4B_CHUNKS);
+#endif
+    HttpDebug("CaptureImage Complete\n\r");    
     g_frame_end = 1;
  
-    /* Read the number of data items transferred (4 x uints = bytes)*/
-//    g_frame_size_in_bytes = (FRAME_SIZE_IN_BYTES - (hdma_dcmi.Instance->NDTR*4));
+    /* Read the number of data items transferred (4 x uint = 4 bytes) */
     g_frame_size_in_bytes = 4*(NUM_OF_4B_CHUNKS - hdma_dcmi.Instance->NDTR);
-    if(NUM_OF_4B_CHUNKS == hdma_dcmi.Instance->NDTR){
+    if(g_frame_size_in_bytes <= 0){
     	HttpDebug("\r\nFailed to capture any data, check camera connections!\r\n");
     	HAL_DCMI_MspDeInit(&phdcmi);
     	while(1){
@@ -360,12 +363,12 @@
     
     HttpDebug("g_frame_size_in_bytes = 0x%x \r\n",g_frame_size_in_bytes);
     
-    uint8_t* Image_Array = reinterpret_cast<uint8_t*>(&g_image.g_image_buffer);
-#if 0    
+    uint8_t* Image = reinterpret_cast<uint8_t*>(&g_image.g_image_buffer);
+//#if 0    
     for(int i =0;i< 10;i++){
-    	HttpDebug("0x%x ",Image_Array[i]);
+    	HttpDebug("0x%x ",Image[i]);
     }
-#endif//if 0    
+//#endif//if 0    
     //
     // Create JPEG Header
     //
@@ -375,17 +378,17 @@
                                        PIXELS_IN_Y_AXIS, 0, 0x0020, 9);
 
     // This pushes the header to the start of the array so that the entire picture can be contiguous in memory
-    memcpy(Image_Array + g_header_length,Image_Array,g_frame_size_in_bytes);
-    memcpy(Image_Array,g_image.g_header,g_header_length);
+    memcpy(Image + g_header_length, Image, g_frame_size_in_bytes);
+    memcpy(Image, g_image.g_header, g_header_length);
 #if 0    
-    for(int i =625;i< 725;i++){
-    	HttpDebug("0x%x ",Image_Array[i]);
+    for(int i =624;i< 725;i++){
+    	HttpDebug("0x%x ",Image[i]);
     }	 
 #endif//if 0
 
 #endif//ENABLE_JPEG
 
-    *WriteBuffer = (char*)Image_Array;
+    *WriteBuffer = (char*)Image;
 
 	return(g_header_length + g_frame_size_in_bytes);
 }
@@ -400,6 +403,8 @@
 //*****************************************************************************
 static void DMAConfig()
 {
+	DCMI_HandleTypeDef phdcmi;
+    DMA_HandleTypeDef hdma_dcmi;
 //    Uart_Write((uint8_t*)"DMAConfig \n\r");
     
     /* Peripheral DMA init*/
@@ -410,20 +415,20 @@
     hdma_dcmi.Init.Direction           = DMA_PERIPH_TO_MEMORY;
     hdma_dcmi.Init.PeriphInc           = DMA_PINC_DISABLE;
     hdma_dcmi.Init.MemInc              = DMA_MINC_ENABLE;
-    hdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;//Cam is 1 byte wide data (8 bits) should this be word as well?????
+    hdma_dcmi.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;//Cam is 1 byte wide data (8 bits) should this be word?????
     hdma_dcmi.Init.MemDataAlignment    = DMA_PDATAALIGN_WORD;//Memory is defined as uint (1 word)
     hdma_dcmi.Init.Mode                = DMA_CIRCULAR;
     hdma_dcmi.Init.Priority            = DMA_PRIORITY_HIGH;
-    hdma_dcmi.Init.FIFOMode            = DMA_FIFOMODE_ENABLE;
+    hdma_dcmi.Init.FIFOMode            = DMA_FIFOMODE_DISABLE;
     hdma_dcmi.Init.FIFOThreshold       = DMA_FIFO_THRESHOLD_FULL;
     hdma_dcmi.Init.MemBurst            = DMA_MBURST_SINGLE;
     hdma_dcmi.Init.PeriphBurst         = DMA_PBURST_SINGLE;
     hdma_dcmi.Instance                 = DMA2_Stream1;
     
-    __HAL_LINKDMA(&phdcmi,DMA_Handle,hdma_dcmi);
+    __HAL_LINKDMA(&phdcmi, DMA_Handle, hdma_dcmi);
     
      /* DMA interrupt init */
-    HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 1, 0);
+    HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 5, 0);
     HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
     
     /* Peripheral DCMI init*/
@@ -520,7 +525,7 @@
     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
   /* System interrupt init*/
-    HAL_NVIC_SetPriority(DCMI_IRQn, 1, 0);
+    HAL_NVIC_SetPriority(DCMI_IRQn, 5, 0);
     HAL_NVIC_EnableIRQ(DCMI_IRQn);
 
     HAL_DMA_Init(&hdma_dcmi);