예제 #1
0
파일: main.c 프로젝트: szymon2103/Stm32
static void LCD_Config(void)
{
  /* LCD Initialization */
  LCD_Init();

  /* LCD Layers Initialization */
  LCD_LayerInit();

  /* Enable the LCD */
  LCD_DisplayOn();

  /* Set LCD Background Layer  */
  LCD_SetLayer(LCD_BACKGROUND_LAYER);
  /* Clear the Background Layer */
  LCD_Clear(LCD_COLOR_WHITE);

  /* Set LCD Foreground Layer  */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);
  /* Clear the Foreground Layer */
  LCD_Clear(LCD_COLOR_WHITE);

  /* Configure and enable the Color Keying feature */
  LCD_SetColorKeying(0);

  /* Configure the transparency for foreground : Increase the transprency */
  LCD_SetTransparency(100);

}
void MainTask_ColorKeying(void) 
{	
	uint32_t lastMiliseconds = 0;
	
	LCD_Init();
	SDRAM_Init();
		
	while(!tamperPushed)
	{
			LCD_ReSetColorKeying();
		
			LTDC_DitherCmd(ENABLE);
				
			DrawText((uint8_t*)" Color Keying OFF");
			DMA2D_CopySTLogo(LOGO_OFFSET);
			LCD_BackgroundLayerInit();
		
			/* wait 2s */
			lastMiliseconds = getMiliseconds();
			while (!tamperPushed && ((getMiliseconds()-lastMiliseconds)<2000))
			{
			}
		
			LCD_SetColorKeying(0xFFFFFF);
			DrawText((uint8_t*)" Color Keying ON");
			DMA2D_CopySTLogo(LOGO_OFFSET);

			/* wait 2s */
			lastMiliseconds = getMiliseconds();
			while (!tamperPushed && ((getMiliseconds()-lastMiliseconds)<2000))
			{
			}			
						
			LTDC_CLUTCmd(LTDC_Layer1, DISABLE);			
			LTDC_CLUTCmd(LTDC_Layer2, DISABLE);			
			LCD_ReSetColorKeying();
			
			LTDC_ReloadConfig(LTDC_IMReload);
	}
	
}
예제 #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
  file (startup_stm32f429_439xx.s) before to branch to application main.
  To reconfigure the default setting of SystemInit() function, refer to
  system_stm32f4xx.c file
  */      
  
  /* User button will be used */
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
  
  /* LCD Configuration */
  LCD_Config();
  
  /* Enable Layer1 */
  LTDC_LayerCmd(LTDC_Layer1, ENABLE);
  
  /* Reload configuration of Layer1 */
  LTDC_ReloadConfig(LTDC_IMReload);
  
  /* Enable The LCD */
  LTDC_Cmd(ENABLE);
  
  while (1)
  {
    /* Wait for User push-button is pressed */
    while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_RESET)
    {
    }
    
    /* Wait for User push-button is released */
    while (STM_EVAL_PBGetState(BUTTON_USER) != Bit_SET)
    {
    }
    
    if(ubPressedButton == PRESSED_1)
    {
      /* Set Color Keying to red (RGB = 0xFF0000) */
      LCD_SetColorKeying(0xFF0000);
      
      ubPressedButton = PRESSED_2;  
    }
    else if(ubPressedButton == PRESSED_2) 
    {
      /* Set Color Keying to blue (RGB = 0x0000FF) */
      LCD_SetColorKeying(0xFF);
      
      ubPressedButton = PRESSED_3; 
    }
    else if(ubPressedButton == PRESSED_3) 
    {
      /* Set Color Keying to green (RGB = 0x00FF00) */
      LCD_SetColorKeying(0xFF00);
      
      ubPressedButton = PRESSED_4; 
    }
    else if(ubPressedButton == PRESSED_4) 
    {
      /* Set Color Keying to blue and green (RGB = 0x00FFFF) */
      LCD_SetColorKeying(0xFFFF);
      
      ubPressedButton = PRESSED_5; 
    }
    else if(ubPressedButton == PRESSED_5) 
    {
      /* Set Color Keying to red and green (RGB = 0x00FFFF) */
      LCD_SetColorKeying(0xFFFF00);
      
      ubPressedButton = PRESSED_6; 
    }
    else
    {
      /* Set Color Keying to blue and red (RGB = 0x00FFFF) */ 
      LCD_SetColorKeying(0xFF00FF);
      
      ubPressedButton = PRESSED_1; 
    }      
  }
}
static void DrawText(uint8_t* text)
{
  /* Windowing configuration */
  /* In this case all the active display area is used to display a picture then :
     Horizontal start = horizontal synchronization + Horizontal back porch = 30 
     Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1
     Vertical start   = vertical synchronization + vertical back porch     = 4
     Vertical stop   = Vertical start + window height -1  = 4 + 320 -1      */      
  LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30;
  LTDC_Layer_InitStruct.LTDC_HorizontalStop = (LCD_PIXEL_WIDTH + 30 - 1); 
  LTDC_Layer_InitStruct.LTDC_VerticalStart = 4;
  LTDC_Layer_InitStruct.LTDC_VerticalStop = (LCD_PIXEL_HEIGHT + 4 - 1);
  
  /* Pixel Format configuration*/
  LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
  /* Alpha constant (255 totally opaque) */
  LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255; 
  /* Default Color configuration (configure A,R,G,B component values) */          
  LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0;        
  LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0;       
  LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0;         
  LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 255;
  
  /* the length of one line of pixels in bytes + 3 then :
  Line Lenth = Active high width x number of bytes per pixel + 3 
  Active high width         = LCD_PIXEL_WIDTH 
  number of bytes per pixel = 2    (pixel_format : RGB565) 
  */
  LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((LCD_PIXEL_WIDTH * 2) + 3);
  /* the pitch is the increment from the start of one line of pixels to the 
  start of the next line in bytes, then :
  Pitch = Active high width x number of bytes per pixel */ 
  LTDC_Layer_InitStruct.LTDC_CFBPitch = (LCD_PIXEL_WIDTH * 2);
  
  /* Configure the number of lines */  
  LTDC_Layer_InitStruct.LTDC_CFBLineNumber = LCD_PIXEL_HEIGHT;
    
  /* Configure Layer2 */
  /* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */     
  LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FRAME_BUFFER + BUFFER_OFFSET;
  
    /* Configure blending factors */       
  LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA;    
  LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA;

  /* Initialize LTDC layer 2 */
  LTDC_LayerInit(LTDC_Layer2, &LTDC_Layer_InitStruct);

  /* LTDC configuration reload */  
  LTDC_ReloadConfig(LTDC_IMReload);
  
  /* Enable foreground & background Layers */
  LTDC_LayerCmd(LTDC_Layer2, ENABLE);
	
		/* Set default font */    
  LCD_SetFont(&LCD_DEFAULT_FONT); 
	
  /* Set LCD foreground layer */
  LCD_SetLayer(LCD_FOREGROUND_LAYER);
	
	LCD_SetColorKeying(0x0);
  
  /* LCD display message */
	LCD_Clear(LCD_COLOR_BLACK);		
  LCD_SetTextColor(LCD_COLOR_RED); 
	LCD_SetBackColor(LCD_COLOR_BLACK);
  LCD_DisplayStringLine(LCD_LINE_1,(uint8_t*)text);

}