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

Files at this revision

API Documentation at this revision

Comitter:
dflet
Date:
Thu Jun 25 18:37:49 2015 +0000
Parent:
0:50cedd586816
Child:
2:b92db44a29b4
Commit message:
WIP commit 2

Changed in this revision

camera_app/camera_app.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/mt9d111/i2cconfig.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/mt9d111/mt9d111.cpp Show annotated file Show diff for this revision Revisions of this file
camera_app/mt9d111/mt9d111.h Show annotated file Show diff for this revision Revisions of this file
camera_app/stm32f4xx_msp.c Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/camera_app/camera_app.cpp	Wed Jun 24 09:54:16 2015 +0000
+++ b/camera_app/camera_app.cpp	Thu Jun 25 18:37:49 2015 +0000
@@ -347,67 +347,29 @@
 static unsigned short CaptureImage(char** WriteBuffer)
 {
     Uart_Write((uint8_t*)"CaptureImage \n\r");
+    DCMI_HandleTypeDef hdcmi;
+    DMA_HandleTypeDef hdma_dcmi;
     //
     // Configure DMA in ping-pong mode
     //
 
     DMAConfig();
     
-//uint32_t addr;
-//uint16_t length;
- 
-//addr = (uint32_t) image->pixels;
-//length = MAX_XFER_SIZE;
- 
-/* Start the DCMI */
-//HAL_DCMI_Start_DMA(&DCMIHandle,
-//        DCMI_MODE_SNAPSHOT, addr, length);
+    HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_SNAPSHOT, (uint32_t)&WriteBuffer, FRAME_SIZE_IN_BYTES); 
+    
  
 /* Wait for frame */
-//while ((DCMI->CR & DCMI_CR_CAPTURE) != 0) {
+while ((DCMI->CR & DCMI_CR_CAPTURE) != 0) {
  
-//}
+}
  
 /* The frame is finished, but DMA still waiting
    for data because we set max frame size
    so we need to abort the DMA transfer here */
-//HAL_DMA_Abort(&DMAHandle);
+HAL_DMA_Abort(&hdma_dcmi);
  
 /* Read the number of data items transferred */
-//image->size = (MAX_XFER_SIZE - DMAHandle.Instance->NDTR)*4;
-
-/**
-  * @brief  Configures the MCO Module
-  * @param  None
-  * @retval None
-  */
-/*  
-void OV9655_MCO_Configuration(void){
-  GPIO_InitTypeDef GPIO_InitStructure;
-  
-  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
-  
-  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
-  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
-  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
-  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
-  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
-  GPIO_Init(GPIOC, &GPIO_InitStructure);
-  
-  GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_MCO);
-  
-  RCC_PLLI2SCmd(DISABLE);
-  
-  RCC_PLLI2SConfig(240, 5); // 192..432, 2..7, ie range of 27.429 Mhz to 192 MHz
-  // PLLI2SSCLK = 240 / 5 = 48Mhz 
-	// MCO2 Output Freq = 48 / 2 = 24Mhz
-  RCC_MCO2Config(RCC_MCO2Source_PLLI2SCLK, RCC_MCO2Div_2); // 24 MHz with default PLL fComp
-  
-  RCC_PLLI2SCmd(ENABLE);
-  
-  while(RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY) == RESET);
-}    
-*/    
+//image->size = (FRAME_SIZE_IN_BYTES - hdma_dcmi.Instance->NDTR)*4;      
     
     //
     // Perform Image Capture 
@@ -577,6 +539,8 @@
 static void CameraIntHandler()
 {
 	Uart_Write((uint8_t*)"CameraIntHandler \n\r");
+	DCMI_HandleTypeDef hdcmi;
+    DMA_HandleTypeDef hdma_dcmi;
 	//MAP_CameraIntClear(CAMERA_BASE, CAM_INT_FE);
  //   if(g_total_dma_intrpts > 1 && MAP_CameraIntStatus(CAMERA_BASE) & CAM_INT_FE)
 //    {
@@ -629,7 +593,8 @@
   /* Insert 100ms delay: wait 100ms */
 //  wait_ms(100); 
 
-//  DCMI_CaptureCmd(ENABLE); 
+//  DCMI_CaptureCmd(ENABLE);
+//HAL_DCMI_Start_DMA(hdcmi, DCMI_MODE_SNAPSHOT, WriteBuffer, Length) 
 }
 
 //*****************************************************************************
--- a/camera_app/mt9d111/i2cconfig.cpp	Wed Jun 24 09:54:16 2015 +0000
+++ b/camera_app/mt9d111/i2cconfig.cpp	Thu Jun 25 18:37:49 2015 +0000
@@ -51,38 +51,6 @@
 
 I2C i2c(PB_9, PB_8);
 
-void MT9D111Delay(uint32_t ucDelay);
-
-//*****************************************************************************
-//
-//! This function implements delay in the camera sensor
-//!
-//! \param                      delay value
-//!
-//! \return                     None
-//
-//*****************************************************************************
-#if defined(ewarm)
-	void MT9D111Delay(uint32_t ucDelay)
-	{
-    __asm("    subs    r0, #1\n"
-          "    bne.n   MT9D111Delay\n"
-          "    bx      lr");
-	}
-#endif
-#if defined(ccs)
-
-    __asm("    .sect \".text:MT9D111Delay\"\n"
-          "    .clink\n"
-          "    .thumbfunc MT9D111Delay\n"
-          "    .thumb\n"
-          "    .global MT9D111Delay\n"
-          "MT9D111Delay:\n"
-          "    subs r0, #1\n"
-          "    bne.n MT9D111Delay\n"
-          "    bx lr\n");
-
-#endif
 
 //*****************************************************************************
 //
--- a/camera_app/mt9d111/mt9d111.cpp	Wed Jun 24 09:54:16 2015 +0000
+++ b/camera_app/mt9d111/mt9d111.cpp	Thu Jun 25 18:37:49 2015 +0000
@@ -55,13 +55,6 @@
 #define SENSOR_PAGE_REG         0xF0
 #define CAM_I2C_SLAVE_ADDR      ((0xBA >> 1))
 
-typedef struct MT9D111RegLst
-{
-    unsigned char ucPageAddr;
-    unsigned char ucRegAddr;
-    unsigned short usValue;
-} s_RegList;
-
 #ifndef ENABLE_JPEG
 static const s_RegList preview_on_cmd_list[]= {
     {1, 0xC6, 0xA103    },  // SEQ_CMD
@@ -297,13 +290,6 @@
 };
 
 //*****************************************************************************
-// Static Function Declarations
-//*****************************************************************************
-static int RegLstWrite(s_RegList *pRegLst, unsigned int ulNofItems);
-extern void MT9D111Delay(unsigned int ucDelay);
-
-
-//*****************************************************************************
 //
 //! This function initilizes the camera sensor
 //!
--- a/camera_app/mt9d111/mt9d111.h	Wed Jun 24 09:54:16 2015 +0000
+++ b/camera_app/mt9d111/mt9d111.h	Thu Jun 25 18:37:49 2015 +0000
@@ -12,6 +12,13 @@
 {
 #endif
 
+typedef struct MT9D111RegLst
+{
+    unsigned char ucPageAddr;
+    unsigned char ucRegAddr;
+    unsigned short usValue;
+} s_RegList;
+
 /*!
     \brief                      This function initilizes the camera sensor
 
@@ -38,6 +45,7 @@
 */
 int StartSensorInJpegMode(int width, int height);
 int CameraSensorResolution(int width, int height);
+static int RegLstWrite(s_RegList *pRegLst, unsigned int ulNofItems);
 //*****************************************************************************
 //
 // Mark the end of the C bindings section for C++ compilers.
--- a/camera_app/stm32f4xx_msp.c	Wed Jun 24 09:54:16 2015 +0000
+++ b/camera_app/stm32f4xx_msp.c	Thu Jun 25 18:37:49 2015 +0000
@@ -75,17 +75,9 @@
    __GPIOC_CLK_ENABLE();  
    __GPIOH_CLK_ENABLE();   
       
-    /**MCO2 GPIO Configuration    
+   /**MCO2 GPIO Configuration is done else where  
     PC9     ------> MCO2    
     */
-
-    /*Configure GPIO pin : PC9 */
-//  GPIO_InitStruct.Pin = GPIO_PIN_9;
-//  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-//  GPIO_InitStruct.Pull = GPIO_NOPULL;
-//  GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
-//  GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
-//  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
        
   /* USER CODE BEGIN DCMI_MspInit 0 */
 
@@ -106,7 +98,7 @@
     PB6     ------> DCMI_D5
     PB7     ------> DCMI_VSYNC 
     */
-    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
+    GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
@@ -186,7 +178,10 @@
     PA10    ------> DCMI_D1
     PB6     ------> DCMI_D5
     PB7     ------> DCMI_VSYNC 
-    */
+    
+    PE1     ------> MCO2
+    */    
+    
     HAL_GPIO_DeInit(GPIOE, GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
 
     HAL_GPIO_DeInit(GPIOA, GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_9|GPIO_PIN_10);
--- a/main.cpp	Wed Jun 24 09:54:16 2015 +0000
+++ b/main.cpp	Thu Jun 25 18:37:49 2015 +0000
@@ -120,8 +120,10 @@
   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
   
-  /* 42MHz mco output on pin PC_9 (cam xclk) */
-  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_4);
+  /* RCC_MCODIV_5 33.6MHz mco output on pin PC_9 (cam xclk) */
+  /* RCC_MCODIV_4 42MHz mco output on pin PC_9 (cam xclk) */
+  /* RCC_MCODIV_3 56MHz mco output on pin PC_9 (cam xclk) */
+  HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_3);
 
   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
 
@@ -162,7 +164,7 @@
 
 }
 
-/* Warning if pin chages are made below then the same changes have to be made in the following files.
+/* Warning if pin changes are made below then the same changes have to be made in the following files.
  * httpserverapp.cpp
  * HttpCore.cpp
  * HttpSocket.cpp