/** * @brief LCD configuration. * @param None * @retval None */ static void LCD_Config(void) { /* LCD Initialization */ BSP_LCD_Init(); /* LCD Layers Initialization */ BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_LayerDefaultInit(1, (LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4))); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Set LCD Background Layer */ BSP_LCD_SelectLayer(0); /* Clear the Background Layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set LCD Foreground Layer */ BSP_LCD_SelectLayer(1); /* Clear the Foreground Layer */ BSP_LCD_Clear(LCD_COLOR_BLACK); /* Configure and enable the Color Keying feature */ BSP_LCD_SetColorKeying(1, 0); /* Configure the transparency for foreground: Increase the transparency */ BSP_LCD_SetTransparency(1, 100); }
/** * @brief LCD configuration. * @param None * @retval None */ static void LCD_Config(void) { uint8_t lcd_status = LCD_OK; /* LCD DSI initialization in mode Video Burst */ lcd_status = LCD_Init(); if(lcd_status != LCD_OK) { Error_Handler(); } /* Activate foreground and background layers */ BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER_BACKGROUND, LCD_BG_LAYER_ADDRESS); BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER_FOREGROUND, LCD_FG_LAYER_ADDRESS); /* Set LCD Background Layer */ BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER_BACKGROUND); /* Clear the Background Layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set LCD Foreground Layer */ BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER_FOREGROUND); /* Clear the Foreground Layer */ BSP_LCD_Clear(LCD_COLOR_BLACK); /* Configure and enable the Color Keying feature */ BSP_LCD_SetColorKeying(1, 0); /* Configure the transparency for foreground: Increase the transparency */ BSP_LCD_SetTransparency(LTDC_ACTIVE_LAYER_FOREGROUND, 100); }
/** * @brief LCD configuration. * @param None * @retval None */ static void LCD_Config(void) { /* LCD Initialization */ /* 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); /* LCD Layers Initialization */ BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_LayerDefaultInit(1, (LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4))); /* Enable the LCD */ BSP_LCD_DisplayOn(); /* Set LCD Background Layer */ BSP_LCD_SelectLayer(0); /* Clear the Background Layer */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set LCD Foreground Layer */ BSP_LCD_SelectLayer(1); /* Clear the Foreground Layer */ BSP_LCD_Clear(LCD_COLOR_BLACK); /* Configure and enable the Color Keying feature */ BSP_LCD_SetColorKeying(1, 0); /* Configure the transparency for foreground: Increase the transparency */ BSP_LCD_SetTransparency(1, 100); }
/** * @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 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) { /* 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); }
void LCD_DISCO_F469NI::SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue) { BSP_LCD_SetColorKeying(LayerIndex, RGBValue); }