void lcd_init(void) { BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(0, (uint32_t)LCD_FRAME_BUFFER); BSP_LCD_SelectLayer(0); BSP_LCD_Clear(LCD_COLOR_RED); BSP_LCD_SetBackColor(LCD_COLOR_RED); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); // BSP_LCD_LayerDefaultInit(1, (uint32_t)LCD_FRAME_BUFFER + 76800); // BSP_LCD_SelectLayer(1); // BSP_LCD_Clear(LCD_COLOR_RED); // BSP_LCD_SetBackColor(LCD_COLOR_RED); // BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetLayerVisible(0, ENABLE); // BSP_LCD_SetLayerVisible(1, ENABLE); BSP_LCD_DisplayOn(); for (int i = 0; i < LCD_SIZE; i ++) { lcd.screen[i] = ' '; } lcd.col = 0; }
int main(void) { HAL_Init(); /* Configure the system clock */ SystemClock_Config(); BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(1, (uint32_t) LCD_FRAME_BUFFER); BSP_LCD_SetLayerVisible(1, ENABLE); BSP_LCD_SelectLayer(1); BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_BLACK); BSP_LCD_DisplayOn(); BSP_LCD_DisplayStringAtLine(0, (uint8_t *) "Hello FreeRTOS"); #define LED_TASK_PRIORITY ((1 + tskIDLE_PRIORITY) | portPRIVILEGE_BIT) #define LCD_TASK_PRIORITY ((1 + tskIDLE_PRIORITY) | portPRIVILEGE_BIT) #define LED_TASK_PRIORITY_LOW ((1 + tskIDLE_PRIORITY) | portPRIVILEGE_BIT) #define LED_TASK_PRIORITY_HIGH ((2 + tskIDLE_PRIORITY) | portPRIVILEGE_BIT) //xTaskCreate( (pdTASK_CODE)test_task_delay, "test", configMINIMAL_STACK_SIZE, 0, LED_TASK_PRIORITY, NULL); //xTaskCreate( (pdTASK_CODE)test_task_delay_until, "test", configMINIMAL_STACK_SIZE, 0, LED_TASK_PRIORITY, NULL); /*std::stringstream output; std::string outputstring; const char * chararray; output.str(std::string()); output << "Counter: " << 0; outputstring = ""; outputstring = output.str(); chararray = ""; chararray = outputstring.c_str(); BSP_LCD_DisplayStringAtLine (1, (uint8_t *) chararray);*/ //xTaskCreate( (pdTASK_CODE)led1_task, "led1", 256, 0, LED_TASK_PRIORITY, NULL); //xTaskCreate( (pdTASK_CODE)led2_task, "led2", 256, 0, LED_TASK_PRIORITY, NULL); //xTaskCreate( (pdTASK_CODE)lcd_task, "lcd", 256, 0, LCD_TASK_PRIORITY, NULL); xTaskCreate( (pdTASK_CODE)led1_task_timeslicing, "led1", 256, 0, LED_TASK_PRIORITY, NULL); xTaskCreate( (pdTASK_CODE)led2_task_timeslicing, "led2", 256, 0, LED_TASK_PRIORITY+1, NULL); // was LED_TASK_PRIORITY //job_descriptor blink1_job_descriptor = job_descriptor(1000/3, LED3); //xTaskCreate( (pdTASK_CODE)blink1_task, "led3", 256, &blink1_job_descriptor, LED_TASK_PRIORITY, NULL); //job_descriptor blink2_job_descriptor = job_descriptor(2000/3, LED4); //xTaskCreate( (pdTASK_CODE)blink2_task, "led4", 256, &blink2_job_descriptor, LED_TASK_PRIORITY, NULL); //xTaskCreate( (pdTASK_CODE)blink_task_low_priority, "led3", 256, 0, LED_TASK_PRIORITY_LOW, NULL); //xTaskCreate( (pdTASK_CODE)blink_task_high_priority, "led4", 256, 0, LED_TASK_PRIORITY_HIGH, NULL); vTaskStartScheduler (); return 0; }
void initializeHardware() { HAL_Init(); BSP_LED_Init(LED3); BSP_LED_Init(LED4); BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); BSP_LED_On(LED3); BSP_LED_Off(LED4); BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(LCD_BACKGROUND_LAYER, LCD_FRAME_BUFFER); BSP_LCD_SetLayerVisible(LCD_BACKGROUND_LAYER, ENABLE); BSP_LCD_SelectLayer(LCD_BACKGROUND_LAYER); BSP_LCD_DisplayOn(); }
/** @brief LCD initialization * * needs to be once called before theLCD screen can be used * */ void lcd_init( void) { // Initialize the LCD BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(1, (uint32_t) LCD_FRAME_BUFFER); BSP_LCD_SetLayerVisible(1, ENABLE); BSP_LCD_SelectLayer(1); // Clear the LCD BSP_LCD_Clear(LCD_COLOR_YELLOW); // Set the LCD Back Color BSP_LCD_SetBackColor(LCD_COLOR_YELLOW); // Set the LCD Text Color BSP_LCD_SetTextColor(LCD_COLOR_BLUE); }
/** @brief LCD initialization * * needs to be once called before theLCD screen can be used * */ void lcd_init( void) { // Initialize the LCD BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(1, (uint32_t) LCD_FRAME_BUFFER); BSP_LCD_SetLayerVisible(1, ENABLE); BSP_LCD_SelectLayer(1); // Clear the LCD BSP_LCD_Clear(LCD_COLOR_WHITE); // Set the LCD Back Color BSP_LCD_SetBackColor(LCD_COLOR_WHITE); // Set the LCD Text Color BSP_LCD_SetTextColor(LCD_COLOR_BLACK); // 34 chars per line with 12 pt BSP_LCD_SetFont(&Font12); }
/** * @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- LCD Initialization #################################################*/ /* 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); /* Enable the color Key for foreground layer */ BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE); BSP_LCD_SetLayerVisible(1, DISABLE); /* Background Layer Initialization */ BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER_LAYER0); /* Set Foreground Layer */ BSP_LCD_SelectLayer(0); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Clear the LCD Background layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); /*##-2- Touch screen initialization ########################################*/ Touchscreen_Calibration(); /*##-3- USB Initialization #################################################*/ /* Init Host Library */ if (USBH_Init(&hUSB_Host, USBH_UserProcess, 0) != USBH_OK) { /* USB Initialization Error */ Error_Handler(); } /* Add Supported Class */ USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS); /* Start Host Process */ if (USBH_Start(&hUSB_Host) != USBH_OK) { /* USB Initialization Error */ Error_Handler(); } /*##-4- Link the USB Mass Storage disk I/O driver ##########################*/ if(FATFS_LinkDriver(&USBH_Driver, USB_Path) != 0) { /* FatFs Initialization Error */ Error_Handler(); } /*##-5- Register the file system object to the FatFs module ################*/ if(f_mount(&USBDISK_FatFs, (TCHAR const*)USB_Path, 0) != FR_OK) { /* FatFs Initialization Error */ Error_Handler(); } /*##-6- Draw the menu ######################################################*/ Draw_Menu(); /* Infinite loop */ while (1) { /*##-7- Configure the touch screen and Get the position ##################*/ GetPosition(); USBH_Process(&hUSB_Host); } }
/** * @brief Save the picture in USB Disk. * @param None * @retval None */ void Save_Picture(void) { FRESULT res1, res2; /* FatFs function common result code */ uint32_t byteswritten; /* File write count */ BSP_LCD_SetLayerVisible(1, ENABLE); BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE); /* Set foreground Layer */ BSP_LCD_SelectLayer(1); BSP_LCD_SetTextColor(LCD_COLOR_DARKRED); BSP_LCD_SetFont(&Font20); /* Turn LED1 and LED3 Off */ BSP_LED_Off(LED1); BSP_LED_Off(LED3); if (Appli_state == APPLICATION_RUNNIG) { BSP_LCD_DisplayStringAt(10, (BSP_LCD_GetYSize()-100), (uint8_t *)"Saving ... ", RIGHT_MODE); /*##-1- Prepare the image to be saved ####################################*/ Prepare_Picture(); /*##-2- Create and Open a new bmp file object with write access ##########*/ if(f_open(&MyFile, "image.bmp", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { /* 'image.bmp' file Open for write Error */ Error_Handler(); } else { /*##-3- Write data to the BMP file #####################################*/ /* Write the BMP header */ if (BSP_LCD_GetXSize() == 640) { /* if ampire 640x480 LCD is used */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader1, 54, (void *)&byteswritten); } else { /* if ampire 480x272 LCD is used */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader2, 54, (void *)&byteswritten); } /* Write the bmp file */ res2 = f_write(&MyFile, (uint32_t *)CONVERTED_FRAME_BUFFER, ((BSP_LCD_GetYSize()-60)*(BSP_LCD_GetXSize()-60)*3), (void *)&byteswritten); if((res1 != FR_OK) || (res2 != FR_OK) || (byteswritten == 0)) { /* 'image' file Write or EOF Error */ BSP_LED_On(LED3); BSP_LCD_DisplayStringAt(10, (BSP_LCD_GetYSize()-100), (uint8_t *)" Aborted...", RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); /* Disable the Layer 2 */ BSP_LCD_SetLayerVisible(1, DISABLE); /* Select Layer 1 */ BSP_LCD_SelectLayer(0); } else { /*##-4- Close the open text file #####################################*/ f_close(&MyFile); /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); BSP_LCD_DisplayStringAt(10, (BSP_LCD_GetYSize()-100), (uint8_t *)" Saved ", RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); /* Disable the Layer 2 */ BSP_LCD_SetLayerVisible(1, DISABLE); /* Select Layer 1 */ BSP_LCD_SelectLayer(0); } } } else { /* USB not connected */ BSP_LCD_DisplayStringAt(10, (BSP_LCD_GetYSize()-100), (uint8_t *)"USB KO... ", RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); /* Disable the Layer 2 */ BSP_LCD_SetLayerVisible(1, DISABLE); /* Select Layer 1 */ BSP_LCD_SelectLayer(0); } }
/** * @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; } } }
/** * @brief Saves Picture into USB disk. * @param None * @retval None */ static void SavePicture(void) { FRESULT res1, res2; /* FatFs function common result code */ uint32_t byteswritten; /* File write count */ static uint32_t counter = 0; uint8_t str[30]; /* Suspend the camera capture */ BSP_CAMERA_Suspend(); /* Prepare the image to be saved */ PicturePrepare(); /* Set foreground Layer */ BSP_LCD_SetLayerVisible(1, ENABLE); BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE); BSP_LCD_SelectLayer(1); BSP_LCD_SetTextColor(LCD_COLOR_DARKRED); BSP_LCD_SetFont(&Font24); /* Format the string */ sprintf((char *)str,"image_%d.bmp", (int)counter); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)"Saving ..", RIGHT_MODE); /* Create and Open a new text file object with write access */ if(f_open(&MyFile, (const char*)str, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { Error_Handler(); } else { /* Write data to the BMP file */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader, 54, (void *)&byteswritten); res2 = f_write(&MyFile, (uint32_t *)CONVERTED_FRAME_BUFFER, (BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*3), (void *)&byteswritten); if((res1 != FR_OK) || (res2 != FR_OK) || (byteswritten == 0)) { Error_Handler(); } else { /* Close the open BMP file */ f_close(&MyFile); /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-24), (uint8_t *)" Saved ", RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); /* Disable the Layer 2 */ BSP_LCD_SetLayerVisible(1, DISABLE); /* Select Layer 1 */ BSP_LCD_SelectLayer(0); counter++; BSP_LED_Off(LED1); /* Resume the camera capture */ BSP_CAMERA_Resume(); } } }
/** * @brief Saves Picture into USB disk. * @param None * @retval None */ static void SavePicture(void) { FRESULT res1, res2; /* FatFs function common result code */ uint32_t byteswritten; /* File write count */ static uint32_t counter = 0; uint8_t str[30]; uint8_t str_display[50]; /* Suspend the camera capture */ BSP_CAMERA_Suspend(); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)"Camera stopped...", RIGHT_MODE); /* Prepare the image to be saved */ PicturePrepare(); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" Picture Prepared...", RIGHT_MODE); HAL_Delay(1000); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); /* Set foreground Layer as visible */ BSP_LCD_SetLayerVisible(LTDC_ACTIVE_LAYER_FOREGROUND, ENABLE); BSP_LCD_SetColorKeying(LTDC_ACTIVE_LAYER_FOREGROUND, LCD_COLOR_WHITE); BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER_FOREGROUND); BSP_LCD_SetTextColor(LCD_COLOR_DARKRED); BSP_LCD_SetFont(&Font24); /* Format the string */ sprintf((char *)str,"image_%d.bmp", (int)counter); sprintf((char *)str_display," Saving picture in file %s ..", str); /* Display text on LTDC layer foreground */ BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), str_display, RIGHT_MODE); /* Create and Open a new text file object with write access */ if(f_open(&MyFile, (const char*)str, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { Error_Handler(); } else { /* Write data to the BMP file */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader, 54, (void *)&byteswritten); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" Header BMP written...", RIGHT_MODE); HAL_Delay(1000); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" BMP pixel data save ongoing...", RIGHT_MODE); res2 = f_write(&MyFile, (uint8_t *)p_bmp_converted_pixel_data, (CameraResX * CameraResY * RGB888_BYTE_PER_PIXEL), (void *)&byteswritten); if((res1 != FR_OK) || (res2 != FR_OK) || (byteswritten == 0)) { Error_Handler(); } else { /* Close the open BMP file */ f_close(&MyFile); /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); sprintf((char *)str_display,"File %s saved on USB disk ..", str); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-24), str_display, RIGHT_MODE); /* Wait for 2s */ HAL_Delay(2000); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)" ", RIGHT_MODE); /* Disable the Layer Foreground */ BSP_LCD_SetLayerVisible(LTDC_ACTIVE_LAYER_FOREGROUND, DISABLE); /* Select Layer Background */ BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER_BACKGROUND); counter++; BSP_LED_Off(LED1); /* Resume the camera capture */ BSP_CAMERA_Resume(); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-24), (uint8_t *)"Camera Play ", RIGHT_MODE); } } }
/** * @brief Main program * @param None * @retval None */ int main(void) { uint8_t lcd_status = LCD_OK; p_bmp_converted_pixel_data = (uint8_t *)CONVERTED_FRAME_BUFFER; offset_address_area_cam_in_lcd_buffer = ((((LcdResY - CameraResY) / 2) * LcdResX) + ((LcdResX - CameraResX) / 2)) * ARGB8888_BYTE_PER_PIXEL; /* For the first Camera line event callback : set the offset to display camera image in the center */ /* of LCD frame buffer background */ lcd_datapointer = offset_address_area_cam_in_lcd_buffer; /* 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(); BSP_IO_Init(); /* Reset and power down camera to be sure camera is Off prior start testing BSP */ BSP_CAMERA_HwReset(); BSP_CAMERA_PwrDown(); /* Configure LED1 and LED3 */ BSP_LED_Init(LED1); BSP_LED_Init(LED3); /*##-1- LCD DSI initialization in mode Video Burst with two LTDC layers of size 800x480 */ lcd_status = BSP_LCD_Init(); if(lcd_status != LCD_OK) { Error_Handler(); } BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER_BACKGROUND, LCD_BG_LAYER_ADDRESS); BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER_FOREGROUND, LCD_FB_START_ADDRESS); /* Select Foreground Layer */ BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER_FOREGROUND); /* Clear the LCD Foreground layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Disable the LTDC Foreground layer */ BSP_LCD_SetLayerVisible(LTDC_ACTIVE_LAYER_FOREGROUND, DISABLE); /* Select the LCD Background layer */ BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER_BACKGROUND); BSP_LCD_Clear(LCD_COLOR_WHITE); /*##-2- Init Host Library ##################################################*/ /* Display USB initialization message */ BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE); BSP_LCD_SetFont(&Font24); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)"USB init ..", RIGHT_MODE); USBH_Init(&hUSB_Host, USBH_UserProcess, 0); /* Add Supported Class */ USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS); /* Start Host Process */ USBH_Start(&hUSB_Host); /*##-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- Camera Initialization and start capture ############################*/ /* Display camera initialization message */ BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)"Camera init ..", RIGHT_MODE); /* Initialize the Camera */ BSP_CAMERA_Init(RESOLUTION_R480x272); /* Start the Camera Capture */ BSP_CAMERA_ContinuousStart((uint8_t *)CAMERA_FRAME_BUFFER); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 48), (uint8_t *)"Press TAMPER button to take snapshot", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)"Camera Play ..", RIGHT_MODE); /*##-6- 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; } } }
/** * @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 175 Mhz */ SystemClock_Config(); /* Configure LED1 and LED3 */ BSP_LED_Init(LED1); BSP_LED_Init(LED3); /*##-1- LCD Initialization #################################################*/ /* 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); /* Enable the color Key for foreground layer */ BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE); BSP_LCD_SetLayerVisible(1, DISABLE); /* Background Layer Initialization */ BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER_LAYER0); /* Set Foreground Layer */ BSP_LCD_SelectLayer(0); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Clear the LCD Background layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); /*##-2- Touch screen initialization ########################################*/ Touchscreen_Calibration(); BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); /*##-3- Link the SD Card disk I/O driver ###################################*/ if(FATFS_LinkDriver(&SD_Driver, SDPath) != 0) { /* FatFs Initialization Error */ Error_Handler(); } /* Create a FAT file system (format) on the logical drive */ f_mkfs((TCHAR const*)SDPath, 0, 0); /*##-4- Register the file system object to the FatFs module ################*/ if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK) { /* FatFs Initialization Error */ Error_Handler(); } /*##-5- Draw the menu ######################################################*/ Draw_Menu(); while (1) { /*##-6- Configure the touch screen and Get the position ####################*/ GetPosition(); } }
/** * @brief Saves the picture in microSD. * @param None * @retval None */ void Save_Picture(void) { FRESULT res1, res2; /* FatFs function common result code */ uint32_t byteswritten = 0; /* File write count */ static uint32_t counter = 0; uint8_t str[30]; BSP_LCD_SetLayerVisible(1, ENABLE); BSP_LCD_SetColorKeying(1, LCD_COLOR_WHITE); /* Set foreground Layer */ BSP_LCD_SelectLayer(1); BSP_LCD_SetTextColor(LCD_COLOR_DARKRED); BSP_LCD_SetFont(&Font24); /* Initialize IOE */ BSP_IO_Init(); /* Check if the SD card is plugged in the slot */ if(BSP_SD_IsDetected() != SD_PRESENT) { BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-125), (uint8_t *)"SD Not Connected", RIGHT_MODE); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-100), (uint8_t *)"Please inser SDCard", RIGHT_MODE); } else { BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-100), (uint8_t *)"Saving ..", RIGHT_MODE); /* Format the string */ sprintf((char *)str,"image_%d.bmp", (int)counter); /*##-1- Prepare the image to be saved ######################################*/ Prepare_Picture(); /*##-2- Create and Open a new bmp file object with write access ##########*/ if(f_open(&MyFile, (const char*)str, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { /* 'image.bmp' file Open for write Error */ Error_Handler(); } else { /*##-3- Write data to the BMP file #####################################*/ /* Write the BMP header */ if (BSP_LCD_GetXSize() == 640) { /* if ampire 640x480 LCD is used */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader1, 54, (void *)&byteswritten); } else { /* if ampire 480x272 LCD is used */ res1 = f_write(&MyFile, (uint32_t *)aBMPHeader2, 54, (void *)&byteswritten); } /* Write the bmp file */ res2 = f_write(&MyFile, (uint32_t *)CONVERTED_FRAME_BUFFER, ((BSP_LCD_GetYSize()-60)*(BSP_LCD_GetXSize()-60)*3), (void *)&byteswritten); if((res1 != FR_OK) || (res2 != FR_OK) || (byteswritten == 0)) { /* 'image' file Write or EOF Error */ Error_Handler(); } else { /*##-4- Close the open bmp file ######################################*/ f_close(&MyFile); /* Success of the demo: no error occurrence */ BSP_LED_On(LED1); BSP_LCD_SetTextColor(LCD_COLOR_DARKGREEN); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize()-100), (uint8_t *)" Saved ", RIGHT_MODE); /* Select Layer 1 */ BSP_LED_Off(LED1); counter++; } } } /* Wait for 2s */ HAL_Delay(2000); /* Disable the Layer 2 */ BSP_LCD_SetLayerVisible(1, DISABLE); /* Clear the LCD Foreground layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); BSP_LCD_SelectLayer(0); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* Enable the CPU Cache */ CPU_CACHE_Enable(); /* STM32F7xx HAL library initialization: - Configure the Flash ART accelerator on ITCM interface - 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 200 MHz */ SystemClock_Config(); /* Configure LED1 and LED3 */ BSP_LED_Init(LED1); BSP_LED_Init(LED3); /*##-1- Initialize the LCD #################################################*/ /* Two layers are used in this application simultaneously so "LCD_MIN_PCLK" is recommended to programme the PCLK at 20 MHz */ BSP_LCD_InitEx(LCD_MIN_PCLK); /* 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); BSP_LCD_SetLayerWindow(0, 0, 0, 480, 272); /*##-2- Init Host Library ##################################################*/ /* Display USB initialization message */ BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE); BSP_LCD_SetFont(&Font24); BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)"USB init ..", RIGHT_MODE); USBH_Init(&hUSB_Host, USBH_UserProcess, 0); /* Add Supported Class */ USBH_RegisterClass(&hUSB_Host, USBH_MSC_CLASS); /* Start Host Process */ USBH_Start(&hUSB_Host); /*##-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- Camera Initialization and start capture ############################*/ /* Display camera initialization message */ BSP_LCD_DisplayStringAt(20, (BSP_LCD_GetYSize() - 24), (uint8_t *)"Camera init ..", RIGHT_MODE); /* Initialize the Camera */ BSP_CAMERA_Init(RESOLUTION_R480x272); /* Start the Camera Capture */ BSP_CAMERA_ContinuousStart((uint8_t *)CAMERA_FRAME_BUFFER); /*##-6- 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; } } }
void LCD_DISCO_F469NI::SetLayerVisible(uint32_t LayerIndex, FunctionalState State) { BSP_LCD_SetLayerVisible(LayerIndex, State); }