/** * @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); /*##-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 Initialize the camera module. * @param None * @retval None */ void CAMERA_Init(void) { /* Disable AUDIO Clock, because of shared pins */ BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_SPEAKER, 0, 0); AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x200, 0x0); AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x300, 0x6010); /* Initialize the Camera */ CameraError = BSP_CAMERA_Init(RESOLUTION_R320x240); if( CameraError != CAMERA_ERROR) { GUI_Delay(100); /* Start the capture */ BSP_CAMERA_ContinuousStart((uint8_t *)CAMERA_FRAME_BUFFER); CAMERA_Set_ContrastBrightness(CameraSettings.b.contrast, CameraSettings.b.brightness); } }
/** * @brief Writes/Read a single data. * @param Addr: I2C address * @param Reg: Reg address * @param Value: Data to be written * @retval None */ static uint8_t CODEC_IO_Write(uint8_t Addr, uint16_t Reg, uint16_t Value) { uint32_t result = 0; AUDIO_IO_Write(Addr, Reg, Value); #ifdef VERIFY_WRITTENDATA /* Verify that the data has been correctly written */ result = (AUDIO_IO_Read(Addr, Reg) == Value)? 0:1; #endif /* VERIFY_WRITTENDATA */ return result; }
/** * @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 168 MHz */ SystemClock_Config(); /* Configure LED1 and LED3 */ BSP_LED_Init(LED1); BSP_LED_Init(LED3); /*##-1- Init Host Library ##################################################*/ USBH_Init(&hUSB_Host, USBH_UserProcess, 0); /* Add Supported Class */ USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS); /* Start Host Process */ USBH_Start(&hUSB_Host); /*##-2- 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, 70, AUDIO_FREQUENCY_48K); /* ADCDAT1 is tri-stated */ AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x200, 0); AUDIO_IO_Write(AUDIO_I2C_ADDRESS, 0x300, 0x6010); /*##-3- Configure TAMPER Button ############################################*/ BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO); /*##-4- Link the USB Host disk I/O driver ##################################*/ FATFS_LinkDriver(&USBH_Driver, MSC_Path); /*##-5- Initialize the LCD #################################################*/ BSP_LCD_Init(); /* Foreground Layer Initialization */ BSP_LCD_LayerDefaultInit(1, LCD_FRAME_BUFFER_LAYER1); /* Set Foreground Layer */ BSP_LCD_SelectLayer(1); /* Clear the LCD Foreground layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetLayerVisible(1, DISABLE); /* Background Layer Initialization */ BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Select the LCD Foreground layer */ BSP_LCD_SelectLayer(0); BSP_LCD_Clear(LCD_COLOR_WHITE); /*##-6- Camera Initialization and start capture ############################*/ /* Initialize the Camera */ BSP_CAMERA_Init(RESOLUTION_R480x272); /* Start the Camera Capture */ BSP_CAMERA_ContinuousStart((uint8_t *)CAMERA_FRAME_BUFFER); /*##-7- Run Application ####################################################*/ while (1) { /* USB Host Background task */ USBH_Process(&hUSB_Host); switch(Appli_state) { case STORAGE_READY: CAMERA_Capture(); break; case STORAGE_IDLE: break; } } }
//{{{ static uint8_t CODEC_IO_Write (uint8_t Addr, uint16_t Reg, uint16_t Value) { uint32_t result = 0; AUDIO_IO_Write (Addr, Reg, Value); return result; }