mirror of
https://github.com/STMicroelectronics/STM32CubeF4.git
synced 2025-05-03 22:17:07 +08:00
257 lines
8.1 KiB
C
257 lines
8.1 KiB
C
/**
|
|
******************************************************************************
|
|
* @file DCMI/DCMI_SnapShotMode/Src/main.c
|
|
* @author MCD Application Team
|
|
* @brief This example describes how to configure the camera in snapshot.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2017 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "main.h"
|
|
|
|
/** @addtogroup STM32F4xx_HAL_Examples
|
|
* @{
|
|
*/
|
|
|
|
/** @addtogroup DCMI_SnapShotMode
|
|
* @{
|
|
*/
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* Private define ------------------------------------------------------------*/
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* Private variables ---------------------------------------------------------*/
|
|
static DMA2D_HandleTypeDef hdma2d_eval;
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
static void SystemClock_Config(void);
|
|
static void Error_Handler(void);
|
|
static void LCD_LL_ConvertFrameToARGB8888(void *pSrc, void *pDst);
|
|
/* Private functions ---------------------------------------------------------*/
|
|
|
|
/**
|
|
* @brief Main program
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
int main(void)
|
|
{
|
|
/* STM32F4xx HAL library initialization:
|
|
- Configure the Flash prefetch, instruction and Data caches
|
|
- Configure the Systick to generate an interrupt each 1 msec
|
|
- Set NVIC Group Priority to 4
|
|
- Global MSP (MCU Support Package) initialization
|
|
*/
|
|
HAL_Init();
|
|
|
|
/* Configure the system clock to 180 MHz */
|
|
SystemClock_Config();
|
|
|
|
/*##-1- Disable SAI1_SDA signal ############################################*/
|
|
/* Note: In STM324X9I-EVAL RevB, PE6 pin is shared between data_7 of camera
|
|
and SAI1_SDA of codec WM8994, after power on, SAI1_SDA pin of codec WM8994
|
|
is in output state, thus preventing MCU from Receiving correct signal
|
|
from camera, so we need to configure SAI1_SDA pin of codec WM8994
|
|
in tri-state
|
|
*/
|
|
/* Initialize the Control interface of the Audio Codec */
|
|
BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_SPEAKER, 0, 0);
|
|
/* ADCDAT1 is tri-stated */
|
|
AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x200, 0);
|
|
AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x300, 0x6010);
|
|
|
|
/*##-2- Initialize the LCD #################################################*/
|
|
BSP_LCD_Init();
|
|
|
|
/*##-3- Initialize the LCD Layers ##########################################*/
|
|
BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER);
|
|
|
|
/* Enable the LCD */
|
|
BSP_LCD_DisplayOn();
|
|
|
|
/* Select the LCD Foreground layer */
|
|
BSP_LCD_SelectLayer(1);
|
|
|
|
/* Clear the LCD */
|
|
BSP_LCD_Clear(LCD_COLOR_WHITE);
|
|
|
|
/*##-4- Camera Initialization and start capture ############################*/
|
|
/* Initialize the Camera */
|
|
BSP_CAMERA_Init(RESOLUTION_R480x272);
|
|
|
|
/* Wait 1s before Camera snapshot */
|
|
HAL_Delay(1000);
|
|
|
|
/* Start the Camera Capture */
|
|
BSP_CAMERA_SnapshotStart((uint8_t *)CAMERA_FRAME_BUFFER);
|
|
|
|
/* Infinite loop */
|
|
while (1)
|
|
{
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief Camera frame event callback
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
void BSP_CAMERA_FrameEventCallback(void)
|
|
{
|
|
/* Convert captured frame to LCD ARGB8888 format */
|
|
LCD_LL_ConvertFrameToARGB8888((uint32_t *)CAMERA_FRAME_BUFFER, (uint32_t *)LCD_FRAME_BUFFER);
|
|
}
|
|
|
|
/**
|
|
* @brief Converts a frame to an ARGB8888 pixel format.
|
|
* @param pSrc: Pointer to source buffer
|
|
* @param pDst: Output color
|
|
* @param xSize: Buffer width
|
|
* @param ColorMode: Input color mode
|
|
* @retval None
|
|
*/
|
|
static void LCD_LL_ConvertFrameToARGB8888(void *pSrc, void *pDst)
|
|
{
|
|
/* Enable DMA2D clock */
|
|
__HAL_RCC_DMA2D_CLK_ENABLE();
|
|
|
|
/* Configure the DMA2D Mode, Color Mode and output offset */
|
|
hdma2d_eval.Init.Mode = DMA2D_M2M_PFC;
|
|
hdma2d_eval.Init.ColorMode = DMA2D_ARGB8888;
|
|
hdma2d_eval.Init.OutputOffset = 0;
|
|
|
|
/* Foreground Configuration */
|
|
hdma2d_eval.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
|
|
hdma2d_eval.LayerCfg[1].InputAlpha = 0xFF;
|
|
hdma2d_eval.LayerCfg[1].InputColorMode = DMA2D_INPUT_RGB565;
|
|
hdma2d_eval.LayerCfg[1].InputOffset = 0;
|
|
|
|
hdma2d_eval.Instance = DMA2D;
|
|
|
|
/* DMA2D Initialization */
|
|
if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK)
|
|
{
|
|
if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, 1) == HAL_OK)
|
|
{
|
|
if (HAL_DMA2D_Start(&hdma2d_eval, (uint32_t)pSrc, (uint32_t)pDst, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) == HAL_OK)
|
|
{
|
|
/* Polling For DMA transfer */
|
|
HAL_DMA2D_PollForTransfer(&hdma2d_eval, 30);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
/* FatFs Initialization Error */
|
|
Error_Handler();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief This function is executed in case of error occurrence.
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void Error_Handler(void)
|
|
{
|
|
/* Turn LED3 on */
|
|
BSP_LED_On(LED3);
|
|
while(1)
|
|
{
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief System Clock Configuration
|
|
* The system Clock is configured as follow :
|
|
* System Clock source = PLL (HSE)
|
|
* SYSCLK(Hz) = 180000000
|
|
* HCLK(Hz) = 180000000
|
|
* AHB Prescaler = 1
|
|
* APB1 Prescaler = 4
|
|
* APB2 Prescaler = 2
|
|
* HSE Frequency(Hz) = 25000000
|
|
* PLL_M = 25
|
|
* PLL_N = 360
|
|
* PLL_P = 2
|
|
* PLL_Q = 7
|
|
* VDD(V) = 3.3
|
|
* Main regulator output voltage = Scale1 mode
|
|
* Flash Latency(WS) = 5
|
|
* @param None
|
|
* @retval None
|
|
*/
|
|
static void SystemClock_Config(void)
|
|
{
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
RCC_OscInitTypeDef RCC_OscInitStruct;
|
|
|
|
/* Enable Power Control clock */
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
|
|
/* The voltage scaling allows optimizing the power consumption when the device is
|
|
clocked below the maximum system frequency, to update the voltage scaling value
|
|
regarding system frequency refer to product datasheet. */
|
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
|
|
|
/* Enable HSE Oscillator and activate PLL with HSE as source */
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
RCC_OscInitStruct.PLL.PLLM = 25;
|
|
RCC_OscInitStruct.PLL.PLLN = 360;
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
|
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
|
|
|
/* Activate the Over-Drive mode */
|
|
HAL_PWREx_EnableOverDrive();
|
|
|
|
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
|
|
clocks dividers */
|
|
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
|
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);
|
|
}
|
|
|
|
#ifdef USE_FULL_ASSERT
|
|
/**
|
|
* @brief Reports the name of the source file and the source line number
|
|
* where the assert_param error has occurred.
|
|
* @param file: pointer to the source file name
|
|
* @param line: assert_param error line source number
|
|
* @retval None
|
|
*/
|
|
void assert_failed(uint8_t* file, uint32_t line)
|
|
{
|
|
/* User can add his own implementation to report the file name and line number,
|
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
|
|
/* Infinite loop */
|
|
while (1)
|
|
{
|
|
}
|
|
}
|
|
#endif
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|