Пример #1
0
/**
  * @brief  Initialize image capture process (start its thread) 
  * @param  None
  * @retval None
  */
void IPCAM_ImageCaptureInit(void)
{
  /* Initializes the DCMI interface (I2C and GPIO) used to configure the camera */
  OV2640_HW_Init();

  /* Read the OV9655/OV2640 Manufacturer identifier */
  OV9655_ReadID(&OV9655_Camera_ID);
  OV2640_ReadID(&OV2640_Camera_ID);

  if(OV9655_Camera_ID.PID  == 0x96)
  {
    IPCAM_ImageBuffer.Camera = OV9655_CAMERA;
  }
  else if(OV2640_Camera_ID.PIDH  == 0x26)
  {
    IPCAM_ImageBuffer.Camera = OV2640_CAMERA;
  }
  else
  {
    ETHERNET_UpdateCameraInit();
    return;
  }

  if (IPCAM_ImageBuffer.ImageFormat == BMP_QQVGA)
  {
    /* Initialize the camera structure */
    IPCAM_ImageBuffer.ImageHeaderLen = 159;
    IPCAM_ImageBuffer.ImageHeader = (uint8_t*)QQVGAImageHeader;
    IPCAM_ImageBuffer.ImageLen = (160*120*2);
    IPCAM_ImageBuffer.MaxImageLen = (160*120*3);
    IPCAM_ImageBuffer.ImageData = (uint8_t*)FSMC_SRAM_ADDRESS;
    IPCAM_ImageBuffer.BufferStatus = BUFFER_EMPTY;
  }
  else if (IPCAM_ImageBuffer.ImageFormat == BMP_QVGA)
  {
    /* Initialize the camera structure */
    IPCAM_ImageBuffer.ImageHeaderLen = 160;
    IPCAM_ImageBuffer.ImageHeader = (uint8_t*)QVGAImageHeader;
    IPCAM_ImageBuffer.ImageLen = (320*240*2);
    IPCAM_ImageBuffer.MaxImageLen = (320*240*3);
    IPCAM_ImageBuffer.ImageData = (uint8_t*)FSMC_SRAM_ADDRESS;
    IPCAM_ImageBuffer.BufferStatus = BUFFER_EMPTY;
  }

  /* Configure camera module mounted on STM322xG-EVAL board */
  eth_Camera_Config();

  /* Clears the DCMI's and DMA's pending bits */
  DCMI_ClearITPendingBit(DCMI_IT_FRAME | DCMI_IT_OVF);
  DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1 | DMA_IT_TEIF1);

  /* Enable DMA2 stream 1 and DCMI interface then start image capture */
  DMA_Cmd(DMA2_Stream1, ENABLE);
  DCMI_Cmd(ENABLE);
  DCMI_CaptureCmd(ENABLE);
}
Пример #2
0
int main() {
	SysTick_Config(SystemCoreClock / 1000);

	InitLeds();
	GPIO_SetBits(GPIOD,   GREEN_LED);
	Delay(100);
	GPIO_ResetBits(GPIOD, GREEN_LED);
	GPIO_SetBits(GPIOD,   ORANGE_LED);
	Delay(100);
	GPIO_ResetBits(GPIOD, ORANGE_LED);
	GPIO_SetBits(GPIOD,   RED_LED);
	Delay(100);
	GPIO_ResetBits(GPIOD, RED_LED);
	GPIO_SetBits(GPIOD,   BLUE_LED);
	Delay(100);
	GPIO_ResetBits(GPIOD, BLUE_LED);


	/**
	 * USART
	 */

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE);

	GPIO_PinAFConfig(USART2_TX_PORT, USART2_TX_PIN_SOURCE, GPIO_AF_USART2);
	GPIO_PinAFConfig(USART2_RX_PORT, USART2_RX_PIN_SOURCE, GPIO_AF_USART2);

	/* Configure USART Tx as alternate function  */
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

	GPIO_InitStructure.GPIO_Pin = USART2_TX_PIN;
	GPIO_Init(USART2_TX_PORT, &GPIO_InitStructure);

	/* Configure USART Rx as alternate function  */
	GPIO_InitStructure.GPIO_Pin = USART2_RX_PIN;
	GPIO_Init(USART2_RX_PORT, &GPIO_InitStructure);

	USART_InitTypeDef USART_InitStructure;
	USART_InitStructure.USART_BaudRate = 115200;
	USART_InitStructure.USART_WordLength = USART_WordLength_8b;
	USART_InitStructure.USART_StopBits = USART_StopBits_1;
	USART_InitStructure.USART_Parity = USART_Parity_No;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	USART_Init(USART2, &USART_InitStructure);


	/* Enable USART */
	USART_Cmd(USART2, ENABLE);

	Serial_print(USART2, "Hello World!  --  Compiled on: ");
	Serial_print(USART2, __DATE__);
	Serial_print(USART2, " - ");
	Serial_println(USART2, __TIME__);



	/**
	 * Interrupts
	 */

	NVIC_InitTypeDef NVIC_InitStructure;
	NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_Init(&NVIC_InitStructure);
	DCMI_ClearITPendingBit(DCMI_IT_FRAME | DCMI_IT_OVF | DCMI_IT_ERR);
	DCMI_ITConfig(DCMI_IT_FRAME | DCMI_IT_OVF | DCMI_IT_ERR, ENABLE);

	NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_Init(&NVIC_InitStructure);
	DMA_ClearITPendingBit(DMA2_Stream1, DMA_IT_TCIF1 | DMA_IT_TEIF1);
	DMA_ITConfig(DMA2_Stream1, DMA_IT_TC | DMA_IT_FE | DMA_IT_TE | DMA_IT_DME, ENABLE);
	Serial_print(USART2, "Interrupts done. \r\n");

	/** Camera Reset Pin & Power Down Pin */
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_Speed = GPIO_Low_Speed;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_9;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	GPIO_SetBits(GPIOA, GPIO_Pin_10);
	GPIO_ResetBits(GPIOA, GPIO_Pin_9);

	/**
	 * DCMI
	 */
	OV2640_HW_Init();
	Serial_print(USART2, "HW_Init done. \r\n");
	/* Print camera Id */
	OV2640_IDTypeDef camera_id;
	OV2640_ReadID(&camera_id);
	Serial_print(USART2, "Camera ID: ");
	Serial_print(USART2, camera_id.Manufacturer_ID1, 16);
	Serial_print(USART2, " - ");
	Serial_print(USART2, camera_id.Manufacturer_ID2, 16);
	Serial_print(USART2, " - ");
	Serial_print(USART2, camera_id.PIDH, 16);
	Serial_print(USART2, " - ");
	Serial_print(USART2, camera_id.PIDL, 16);
	Serial_println(USART2, "");

	OV2640_QQVGAConfig();
	Serial_print(USART2, "QQVGAConfig done. \r\n");
	// OV2640_BandWConfig(0x18); // BW


	OV2640_Init(BMP_QQVGA);
	Serial_print(USART2, "Init done. \r\n");

	// Memset
	int i;
	for (i=0; i<160*120; i++) {
		Targetbuffer[i] = 0xbeef;
	}

	DMA_Cmd(DMA2_Stream1, ENABLE);
	while ( DMA_GetCmdStatus(DMA2_Stream1) != ENABLE )
		;
	Serial_print(USART2, "DMA Enable done. \r\n");

	DCMI_Cmd(ENABLE);
	Serial_print(USART2, "DCMI Enable done. \r\n");
	DCMI_CaptureCmd(ENABLE);
	Serial_print(USART2, "DCMI Capture start. \r\n");


	Serial_print(USART2, "Print: \r\n.\r\n.\r\n");
	Serial_print(USART2, "done. \r\n");

	Delay(1);
	// Clear screen
	Serial_print(USART2, 0x1b);
	Serial_print(USART2, "[2J");

	while (1) {
		while (DCMI_GetFlagStatus(DCMI_FLAG_FRAMERI) == RESET)
			;

		print_CameraData();
		// Move cursor to home position.
		Serial_print(USART2, 0x1b);
		Serial_print(USART2, "[H");

	}
}
Пример #3
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f40_41xxx.s/startup_stm32f427_437xx.s/startup_stm32f429_439xx.s)
       before to branch to application main.
     */

  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

  /* Initialize LEDs mounted on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  STM_EVAL_LEDOn(LED1);

 /* Initialize the LCD */
  LCD_Init();
  LCD_Clear(Black);
  LCD_SetTextColor(White);

  LCD_LOG_SetHeader((uint8_t*)"STM32 Camera Demo");
  LCD_LOG_SetFooter ((uint8_t*)"   Copyright (c) STMicroelectronics" );

  /* ADC configuration */
  ADC_Config();

  /* Initializes the DCMI interface (I2C and GPIO) used to configure the camera */
  OV2640_HW_Init();

  /* Read the OV9655/OV2640 Manufacturer identifier */
  OV9655_ReadID(&OV9655_Camera_ID);
  OV2640_ReadID(&OV2640_Camera_ID);

  if(OV9655_Camera_ID.PID  == 0x96)
  {
    Camera = OV9655_CAMERA;
    sprintf((char*)abuffer, "OV9655 Camera ID 0x%x", OV9655_Camera_ID.PID);
    ValueMax = 2;
  }
  else if(OV2640_Camera_ID.PIDH  == 0x26)
  {
    Camera = OV2640_CAMERA;
    sprintf((char*)abuffer, "OV2640 Camera ID 0x%x", OV2640_Camera_ID.PIDH);
    ValueMax = 2;
  }
  else
  {
    LCD_SetTextColor(LCD_COLOR_RED);
    LCD_DisplayStringLine(LINE(4), (uint8_t*)"Check the Camera HW and try again");
    while(1);
  }

  LCD_SetTextColor(LCD_COLOR_YELLOW);
  LCD_DisplayStringLine(LINE(4), (uint8_t*)abuffer);
  LCD_SetTextColor(LCD_COLOR_WHITE);
  Delay(200);

  /* Initialize demo */
  ImageFormat = (ImageFormat_TypeDef)Demo_Init();

  /* Configure the Camera module mounted on STM324xG-EVAL/STM324x7I-EVAL boards */
  Demo_LCD_Clear();
  LCD_DisplayStringLine(LINE(4), (uint8_t*)"Camera Init..               ");
  Camera_Config();

  sprintf((char*)abuffer, " Image selected: %s", ImageForematArray[ImageFormat]);
  LCD_DisplayStringLine(LINE(4),(uint8_t*)abuffer);

  /* Enable DMA2 stream 1 and DCMI interface then start image capture */
  DMA_Cmd(DMA2_Stream1, ENABLE);
  DCMI_Cmd(ENABLE);

  /* Insert 100ms delay: wait 100ms */
  Delay(200);

  DCMI_CaptureCmd(ENABLE);

  LCD_ClearLine(LINE(4));
  Demo_LCD_Clear();

  if(ImageFormat == BMP_QQVGA)
  {
    /* LCD Display window */
    LCD_SetDisplayWindow(179, 239, 120, 160);
    LCD_WriteReg(LCD_REG_3, 0x1038);
    LCD_WriteRAM_Prepare();
  }
  else if(ImageFormat == BMP_QVGA)
  {
    /* LCD Display window */
    LCD_SetDisplayWindow(239, 319, 240, 320);
    LCD_WriteReg(LCD_REG_3, 0x1038);
    LCD_WriteRAM_Prepare();
  }

  while(1)
  {
    /* Blink LD1, LED2 and LED4 */
    STM_EVAL_LEDToggle(LED1);
    STM_EVAL_LEDToggle(LED2);
    STM_EVAL_LEDToggle(LED3);
    STM_EVAL_LEDToggle(LED4);

    /* Insert 100ms delay */
    Delay(10);

    /* Get the last ADC3 conversion result data */
    uhADCVal = ADC_GetConversionValue(ADC3);

    /* Change the Brightness of camera using "Brightness Adjustment" register:
       For OV9655 camera Brightness can be positively (0x01 ~ 0x7F) and negatively (0x80 ~ 0xFF) adjusted
       For OV2640 camera Brightness can be positively (0x20 ~ 0x40) and negatively (0 ~ 0x20) adjusted */
    if(Camera == OV9655_CAMERA)
    {
      OV9655_BrightnessConfig(uhADCVal);
    }
    if(Camera == OV2640_CAMERA)
    {
      OV2640_BrightnessConfig(uhADCVal/2);
    }
  }
}