/** * @brief Disables the Display. * @param None * @retval LCD Register Value. */ uint16_t ili9341_ReadID(void) { if (Is_ili9341_Initialized == 0) { ili9341_Init(); } return ((uint16_t) ili9341_ReadData(LCD_READ_ID4, LCD_READ_ID4_SIZE)); }
/* LTDC init function */ static void MX_LTDC_Init(void) { LTDC_LayerCfgTypeDef pLayerCfg; ili9341_Init(); hltdc.Instance = LTDC; hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL; hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL; hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL; hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC; hltdc.Init.HorizontalSync = 9; hltdc.Init.VerticalSync = 1; hltdc.Init.AccumulatedHBP = 29; hltdc.Init.AccumulatedVBP = 3; hltdc.Init.AccumulatedActiveW = 269; hltdc.Init.AccumulatedActiveH = 323; hltdc.Init.TotalWidth = 279; hltdc.Init.TotalHeigh = 327; hltdc.Init.Backcolor.Blue = 0; hltdc.Init.Backcolor.Green = 0; hltdc.Init.Backcolor.Red = 0; if (HAL_LTDC_Init(&hltdc) != HAL_OK) { Error_Handler(); } pLayerCfg.WindowX0 = 0; pLayerCfg.WindowX1 = 240; pLayerCfg.WindowY0 = 0; pLayerCfg.WindowY1 = 320; pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888; pLayerCfg.Alpha = 255; pLayerCfg.Alpha0 = 0; pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA; pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA; pLayerCfg.FBStartAdress = 0xd0000000; pLayerCfg.ImageWidth = 240; pLayerCfg.ImageHeight = 320; pLayerCfg.Backcolor.Blue = 0; pLayerCfg.Backcolor.Green = 255; pLayerCfg.Backcolor.Red = 0; if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK) { Error_Handler(); } }
void lcd_initialize( void ) { ili9341_Init( ); }
/** * @brief LCD configuration. * @note This function Configure tha LTDC peripheral : * 1) Configure the Pixel Clock for the LCD * 2) Configure the LTDC Timing and Polarity * 3) Configure the LTDC Layer 2 : * - RGB565 as pixel format * - The frame buffer is located at internal RAM : The output of DMA2D transfer * - The Layer size configuration : 240x160 * @retval * None */ static void LCD_Config(void) { RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; LTDC_LayerCfgTypeDef pLayerCfg; static LTDC_HandleTypeDef LtdcHandle; /* Initializaton of ILI9341 component*/ ili9341_Init(); /* LTDC Initialization -------------------------------------------------------*/ /* Polarity configuration */ /* Initialize the horizontal synchronization polarity as active low */ LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL; /* Initialize the vertical synchronization polarity as active low */ LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AL; /* Initialize the data enable polarity as active low */ LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL; /* Initialize the pixel clock polarity as input pixel clock */ LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC; /* Timing configuration (Typical configuration from ILI9341 datasheet) HSYNC=10 (9+1) HBP=20 (29-10+1) ActiveW=240 (269-20-10+1) HFP=10 (279-240-20-10+1) VSYNC=2 (1+1) VBP=2 (3-2+1) ActiveH=320 (323-2-2+1) VFP=4 (327-320-2-2+1) */ /* Timing configuration */ /* Horizontal synchronization width = Hsync - 1 */ LtdcHandle.Init.HorizontalSync = 9; /* Vertical synchronization height = Vsync - 1 */ LtdcHandle.Init.VerticalSync = 1; /* Accumulated horizontal back porch = Hsync + HBP - 1 */ LtdcHandle.Init.AccumulatedHBP = 29; /* Accumulated vertical back porch = Vsync + VBP - 1 */ LtdcHandle.Init.AccumulatedVBP = 3; /* Accumulated active width = Hsync + HBP + Active Width - 1 */ LtdcHandle.Init.AccumulatedActiveH = 323; /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */ LtdcHandle.Init.AccumulatedActiveW = 269; /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */ LtdcHandle.Init.TotalHeigh = 327; /* Total width = Hsync + HBP + Active Width + HFP - 1 */ LtdcHandle.Init.TotalWidth = 279; /* LCD clock configuration */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 Mhz */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; PeriphClkInitStruct.PLLSAI.PLLSAIN = 192; PeriphClkInitStruct.PLLSAI.PLLSAIR = 4; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); /* Configure R,G,B component values for LCD background color */ LtdcHandle.Init.Backcolor.Blue = 0; LtdcHandle.Init.Backcolor.Green = 0; LtdcHandle.Init.Backcolor.Red = 0; LtdcHandle.Instance = LTDC; /* Layer1 Configuration ------------------------------------------------------*/ /* Windowing configuration */ /* WindowX0 = Horizontal start WindowX1 = Horizontal stop WindowY0 = Vertical start WindowY1 = Vertical stop */ pLayerCfg.WindowX0 = 0; pLayerCfg.WindowX1 = 240; pLayerCfg.WindowY0 = 80; pLayerCfg.WindowY1 = 240; /* Pixel Format configuration*/ pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; /* Start Address configuration : frame buffer is located at FLASH memory */ pLayerCfg.FBStartAdress = (uint32_t)&aBlendedImage; /* Alpha constant (255 totally opaque) */ pLayerCfg.Alpha = 255; /* Default Color configuration (configure A,R,G,B component values) */ pLayerCfg.Alpha0 = 0; pLayerCfg.Backcolor.Blue = 0; pLayerCfg.Backcolor.Green = 0; pLayerCfg.Backcolor.Red = 0; /* Configure blending factors */ pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA; pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA; /* Configure the number of lines and number of pixels per line */ pLayerCfg.ImageWidth = 240; pLayerCfg.ImageHeight = 160; /* Configure the LTDC */ if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Configure the Layer*/ if(HAL_LTDC_ConfigLayer(&LtdcHandle, &pLayerCfg, 1) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }
/** * @brief LCD Configuration. * @note This function Configure the LTDC peripheral : * 1) Configure the Pixel Clock for the LCD * 2) Configure the LTDC Timing and Polarity * 3) Configure the LTDC Layer 1 : * - direct color (RGB565) as pixel format * - The frame buffer is located at FLASH memory * - The Layer size configuration : 240x160 * 4) Configure the LTDC Layer 2 : * - direct color (RGB565) as pixel format * - The frame buffer is located at FLASH memory * - The Layer size configuration : 240x160 * @retval * None */ static void LCD_Config(void) { LTDC_LayerCfgTypeDef pLayerCfg; LTDC_LayerCfgTypeDef pLayerCfg1; /* Initialization of ILI9341 component*/ ili9341_Init(); /* LTDC Initialization -------------------------------------------------------*/ /* Polarity configuration */ /* Initialize the horizontal synchronization polarity as active low */ LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL; /* Initialize the vertical synchronization polarity as active low */ LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AL; /* Initialize the data enable polarity as active low */ LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL; /* Initialize the pixel clock polarity as input pixel clock */ LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC; /* Timing configuration (Typical configuration from ILI9341 datasheet) HSYNC=10 (9+1) HBP=20 (29-10+1) ActiveW=240 (269-20-10+1) HFP=10 (279-240-20-10+1) VSYNC=2 (1+1) VBP=2 (3-2+1) ActiveH=320 (323-2-2+1) VFP=4 (327-320-2-2+1) */ /* Timing configuration */ /* Horizontal synchronization width = Hsync - 1 */ LtdcHandle.Init.HorizontalSync = 9; /* Vertical synchronization height = Vsync - 1 */ LtdcHandle.Init.VerticalSync = 1; /* Accumulated horizontal back porch = Hsync + HBP - 1 */ LtdcHandle.Init.AccumulatedHBP = 29; /* Accumulated vertical back porch = Vsync + VBP - 1 */ LtdcHandle.Init.AccumulatedVBP = 3; /* Accumulated active width = Hsync + HBP + Active Width - 1 */ LtdcHandle.Init.AccumulatedActiveH = 323; /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */ LtdcHandle.Init.AccumulatedActiveW = 269; /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */ LtdcHandle.Init.TotalHeigh = 327; /* Total width = Hsync + HBP + Active Width + HFP - 1 */ LtdcHandle.Init.TotalWidth = 279; /* Configure R,G,B component values for LCD background color */ LtdcHandle.Init.Backcolor.Blue = 0; LtdcHandle.Init.Backcolor.Green = 0; LtdcHandle.Init.Backcolor.Red = 0; LtdcHandle.Instance = LTDC; /* Layer1 Configuration ------------------------------------------------------*/ /* Windowing configuration */ pLayerCfg.WindowX0 = 0; pLayerCfg.WindowX1 = 240; pLayerCfg.WindowY0 = 0; pLayerCfg.WindowY1 = 160; /* Pixel Format configuration*/ pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; /* Start Address configuration : frame buffer is located at FLASH memory */ pLayerCfg.FBStartAdress = (uint32_t)&ST_LOGO_1; /* Alpha constant (255 totally opaque) */ pLayerCfg.Alpha = 255; /* Default Color configuration (configure A,R,G,B component values) */ pLayerCfg.Alpha0 = 0; pLayerCfg.Backcolor.Blue = 0; pLayerCfg.Backcolor.Green = 0; pLayerCfg.Backcolor.Red = 0; /* Configure blending factors */ pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; /* Configure the number of lines and number of pixels per line */ pLayerCfg.ImageWidth = 240; pLayerCfg.ImageHeight = 160; /* Layer2 Configuration ------------------------------------------------------*/ /* Windowing configuration */ pLayerCfg1.WindowX0 = 0; pLayerCfg1.WindowX1 = 240; pLayerCfg1.WindowY0 = 160; pLayerCfg1.WindowY1 = 320; /* Pixel Format configuration*/ pLayerCfg1.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; /* Start Address configuration : frame buffer is located at FLASH memory */ pLayerCfg1.FBStartAdress = (uint32_t)&ST_LOGO_2; /* Alpha constant (255 totally opaque) */ pLayerCfg1.Alpha = 200; /* Default Color configuration (configure A,R,G,B component values) */ pLayerCfg1.Alpha0 = 0; pLayerCfg1.Backcolor.Blue = 0; pLayerCfg1.Backcolor.Green = 0; pLayerCfg1.Backcolor.Red = 0; /* Configure blending factors */ pLayerCfg1.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; pLayerCfg1.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; /* Configure the number of lines and number of pixels per line */ pLayerCfg1.ImageWidth = 240; pLayerCfg1.ImageHeight = 160; /* Configure the LTDC */ if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Configure the Background Layer*/ if(HAL_LTDC_ConfigLayer(&LtdcHandle, &pLayerCfg, 0) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /* Configure the Foreground Layer*/ if(HAL_LTDC_ConfigLayer(&LtdcHandle, &pLayerCfg1, 1) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }