/** * @brief Initializes the DSI LCD. * The ititialization is done as below: * - DSI PLL ititialization * - DSI ititialization * - LTDC ititialization * - OTM8009A LCD Display IC Driver ititialization * @param None * @retval LCD state */ static uint8_t LCD_Init(void){ GPIO_InitTypeDef GPIO_Init_Structure; /* Toggle Hardware Reset of the DSI LCD using * its XRES signal (active low) */ BSP_LCD_Reset(); /* Call first MSP Initialize only in case of first initialization * This will set IP blocks LTDC, DSI and DMA2D * - out of reset * - clocked * - NVIC IRQ related to IP blocks enabled */ BSP_LCD_MspInit(); /* LCD clock configuration */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 417 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 417 MHz / 5 = 83.4 MHz */ /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 83.4 / 2 = 41.7 MHz */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; PeriphClkInitStruct.PLLSAI.PLLSAIN = 417; PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */ hdsi_eval.Instance = DSI; HAL_DSI_DeInit(&(hdsi_eval)); #if defined(USE_STM32469I_DISCO_REVA) dsiPllInit.PLLNDIV = 100; dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5; #else dsiPllInit.PLLNDIV = 125; dsiPllInit.PLLIDF = DSI_PLL_IN_DIV2; #endif /* USE_STM32469I_DISCO_REVA */ dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1; hdsi_eval.Init.NumberOfLanes = DSI_TWO_DATA_LANES; hdsi_eval.Init.TXEscapeCkdiv = 0x4; HAL_DSI_Init(&(hdsi_eval), &(dsiPllInit)); /* Configure the DSI for Command mode */ CmdCfg.VirtualChannelID = 0; CmdCfg.HSPolarity = DSI_HSYNC_ACTIVE_HIGH; CmdCfg.VSPolarity = DSI_VSYNC_ACTIVE_HIGH; CmdCfg.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH; CmdCfg.ColorCoding = DSI_RGB888; CmdCfg.CommandSize = HACT; CmdCfg.TearingEffectSource = DSI_TE_EXTERNAL; CmdCfg.TearingEffectPolarity = DSI_TE_RISING_EDGE; CmdCfg.VSyncPol = DSI_VSYNC_FALLING; CmdCfg.AutomaticRefresh = DSI_AR_DISABLE; CmdCfg.TEAcknowledgeRequest = DSI_TE_ACKNOWLEDGE_ENABLE; HAL_DSI_ConfigAdaptedCommandMode(&hdsi_eval, &CmdCfg); LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_ENABLE; LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_ENABLE; LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_ENABLE; LPCmd.LPGenShortReadNoP = DSI_LP_GSR0P_ENABLE; LPCmd.LPGenShortReadOneP = DSI_LP_GSR1P_ENABLE; LPCmd.LPGenShortReadTwoP = DSI_LP_GSR2P_ENABLE; LPCmd.LPGenLongWrite = DSI_LP_GLW_ENABLE; LPCmd.LPDcsShortWriteNoP = DSI_LP_DSW0P_ENABLE; LPCmd.LPDcsShortWriteOneP = DSI_LP_DSW1P_ENABLE; LPCmd.LPDcsShortReadNoP = DSI_LP_DSR0P_ENABLE; LPCmd.LPDcsLongWrite = DSI_LP_DLW_ENABLE; HAL_DSI_ConfigCommand(&hdsi_eval, &LPCmd); /* Initialize LTDC */ LTDC_Init(); /* Start DSI */ HAL_DSI_Start(&(hdsi_eval)); /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver) * depending on configuration set in 'hdsivideo_handle'. */ OTM8009A_Init(OTM8009A_COLMOD_RGB888, LCD_ORIENTATION_LANDSCAPE); LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_DISABLE; LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_DISABLE; LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_DISABLE; LPCmd.LPGenShortReadNoP = DSI_LP_GSR0P_DISABLE; LPCmd.LPGenShortReadOneP = DSI_LP_GSR1P_DISABLE; LPCmd.LPGenShortReadTwoP = DSI_LP_GSR2P_DISABLE; LPCmd.LPGenLongWrite = DSI_LP_GLW_DISABLE; LPCmd.LPDcsShortWriteNoP = DSI_LP_DSW0P_DISABLE; LPCmd.LPDcsShortWriteOneP = DSI_LP_DSW1P_DISABLE; LPCmd.LPDcsShortReadNoP = DSI_LP_DSR0P_DISABLE; LPCmd.LPDcsLongWrite = DSI_LP_DLW_DISABLE; HAL_DSI_ConfigCommand(&hdsi_eval, &LPCmd); HAL_DSI_ConfigFlowControl(&hdsi_eval, DSI_FLOW_CONTROL_BTA); /* Enable GPIOJ clock */ __HAL_RCC_GPIOJ_CLK_ENABLE(); /* Configure DSI_TE pin from MB1166 : Tearing effect on separated GPIO from KoD LCD */ /* that is mapped on GPIOJ2 as alternate DSI function (DSI_TE) */ /* This pin is used only when the LCD and DSI link is configured in command mode */ /* Not used in DSI Video mode. */ GPIO_Init_Structure.Pin = GPIO_PIN_2; GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP; GPIO_Init_Structure.Pull = GPIO_NOPULL; GPIO_Init_Structure.Speed = GPIO_SPEED_HIGH; GPIO_Init_Structure.Alternate = GPIO_AF13_DSI; HAL_GPIO_Init(GPIOJ, &GPIO_Init_Structure); /* Refresh the display */ HAL_DSI_Refresh(&hdsi_eval); return LCD_OK; }
/** * @brief Initializes the DSI LCD. * The ititialization is done as below: * - DSI PLL ititialization * - DSI ititialization * - LTDC ititialization * - OTM8009A LCD Display IC Driver ititialization * @param None * @retval LCD state */ static uint8_t LCD_Init(void) { /* Toggle Hardware Reset of the DSI LCD using * its XRES signal (active low) */ BSP_LCD_Reset(); /* Call first MSP Initialize only in case of first initialization * This will set IP blocks LTDC, DSI and DMA2D * - out of reset * - clocked * - NVIC IRQ related to IP blocks enabled */ BSP_LCD_MspInit(); /* LCD clock configuration */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 417 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 417 MHz / 5 = 83.4 MHz */ /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 83.4 / 2 = 41.7 MHz */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; PeriphClkInitStruct.PLLSAI.PLLSAIN = 417; PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */ hdsi_eval.Instance = DSI; HAL_DSI_DeInit(&(hdsi_eval)); dsiPllInit.PLLNDIV = 100; dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5; dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1; hdsi_eval.Init.NumberOfLanes = DSI_TWO_DATA_LANES; hdsi_eval.Init.TXEscapeCkdiv = 0x4; HAL_DSI_Init(&(hdsi_eval), &(dsiPllInit)); /* Configure the DSI for Command mode */ CmdCfg.VirtualChannelID = 0; CmdCfg.HSPolarity = DSI_HSYNC_ACTIVE_HIGH; CmdCfg.VSPolarity = DSI_VSYNC_ACTIVE_HIGH; CmdCfg.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH; CmdCfg.ColorCoding = DSI_RGB888; CmdCfg.CommandSize = HACT; CmdCfg.TearingEffectSource = DSI_TE_DSILINK; CmdCfg.TearingEffectPolarity = DSI_TE_RISING_EDGE; CmdCfg.VSyncPol = DSI_VSYNC_FALLING; CmdCfg.AutomaticRefresh = DSI_AR_ENABLE; CmdCfg.TEAcknowledgeRequest = DSI_TE_ACKNOWLEDGE_ENABLE; HAL_DSI_ConfigAdaptedCommandMode(&hdsi_eval, &CmdCfg); LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_ENABLE; LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_ENABLE; LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_ENABLE; LPCmd.LPGenShortReadNoP = DSI_LP_GSR0P_ENABLE; LPCmd.LPGenShortReadOneP = DSI_LP_GSR1P_ENABLE; LPCmd.LPGenShortReadTwoP = DSI_LP_GSR2P_ENABLE; LPCmd.LPGenLongWrite = DSI_LP_GLW_ENABLE; LPCmd.LPDcsShortWriteNoP = DSI_LP_DSW0P_ENABLE; LPCmd.LPDcsShortWriteOneP = DSI_LP_DSW1P_ENABLE; LPCmd.LPDcsShortReadNoP = DSI_LP_DSR0P_ENABLE; LPCmd.LPDcsLongWrite = DSI_LP_DLW_ENABLE; HAL_DSI_ConfigCommand(&hdsi_eval, &LPCmd); /* Initialize LTDC */ LTDC_Init(); /* Start DSI */ HAL_DSI_Start(&(hdsi_eval)); /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver)*/ OTM8009A_Init(OTM8009A_COLMOD_RGB888, LCD_ORIENTATION_LANDSCAPE); /* Reconfigure the DSI for HS Command mode */ LPCmd.LPGenShortWriteNoP = DSI_LP_GSW0P_DISABLE; LPCmd.LPGenShortWriteOneP = DSI_LP_GSW1P_DISABLE; LPCmd.LPGenShortWriteTwoP = DSI_LP_GSW2P_DISABLE; LPCmd.LPGenShortReadNoP = DSI_LP_GSR0P_DISABLE; LPCmd.LPGenShortReadOneP = DSI_LP_GSR1P_DISABLE; LPCmd.LPGenShortReadTwoP = DSI_LP_GSR2P_DISABLE; LPCmd.LPGenLongWrite = DSI_LP_GLW_DISABLE; LPCmd.LPDcsShortWriteNoP = DSI_LP_DSW0P_DISABLE; LPCmd.LPDcsShortWriteOneP = DSI_LP_DSW1P_DISABLE; LPCmd.LPDcsShortReadNoP = DSI_LP_DSR0P_DISABLE; LPCmd.LPDcsLongWrite = DSI_LP_DLW_DISABLE; HAL_DSI_ConfigCommand(&hdsi_eval, &LPCmd); HAL_DSI_ConfigFlowControl(&hdsi_eval, DSI_FLOW_CONTROL_BTA); /* Refresh the display */ HAL_DSI_Refresh(&hdsi_eval); return LCD_OK; }
static uint8_t LCD_Init(void) { DSI_PLLInitTypeDef dsiPllInit; static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; uint32_t LcdClock = 19200; uint32_t Clockratio = 0; uint32_t laneByteClk_kHz = 0; uint32_t VSA; /*!< Vertical start active time in units of lines */ uint32_t VBP; /*!< Vertical Back Porch time in units of lines */ uint32_t VFP; /*!< Vertical Front Porch time in units of lines */ uint32_t VACT; /*!< Vertical Active time in units of lines = imageSize Y in pixels to display */ uint32_t HSA; /*!< Horizontal start active time in units of lcdClk */ uint32_t HBP; /*!< Horizontal Back Porch time in units of lcdClk */ uint32_t HFP; /*!< Horizontal Front Porch time in units of lcdClk */ uint32_t HACT; /*!< Horizontal Active time in units of lcdClk = imageSize X in pixels to display */ /* Toggle Hardware Reset of the DSI LCD using * its XRES signal (active low) */ BSP_LCD_Reset(); /* Call first MSP Initialize only in case of first initialization * This will set IP blocks LTDC, DSI and DMA2D * - out of reset * - clocked * - NVIC IRQ related to IP blocks enabled */ BSP_LCD_MspInit(); /*************************DSI Initialization***********************************/ /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */ hdsi_eval.Instance = DSI; HAL_DSI_DeInit(&(hdsi_eval)); #if !defined(USE_STM32469I_DISCO_REVA) dsiPllInit.PLLNDIV = 125; dsiPllInit.PLLIDF = DSI_PLL_IN_DIV2; dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1; #else dsiPllInit.PLLNDIV = 100; dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5; dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1; #endif laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */ /* Set number of Lanes */ hdsi_eval.Init.NumberOfLanes = DSI_TWO_DATA_LANES; /* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */ hdsi_eval.Init.TXEscapeCkdiv = laneByteClk_kHz/15620; HAL_DSI_Init(&(hdsi_eval), &(dsiPllInit)); Clockratio = laneByteClk_kHz/LcdClock; /* Timing parameters for all Video modes * Set Timing parameters of LTDC */ /* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */ VSA = OTM8009A_800X480_VSYNC; /* 12 */ VBP = OTM8009A_800X480_VBP; /* 12 */ VFP = OTM8009A_800X480_VFP; /* 12 */ HSA = OTM8009A_800X480_HSYNC; /* 120 */ HBP = OTM8009A_800X480_HBP; /* 120 */ HFP = OTM8009A_800X480_HFP; /* 120 */ HACT = OTM8009A_800X480_WIDTH; /* 800 */ VACT = OTM8009A_800X480_HEIGHT; /* 480 */ hdsivideo_handle.VirtualChannelID = LCD_OTM8009A_ID; hdsivideo_handle.ColorCoding = LCD_DSI_PIXEL_DATA_FMT_RBG888; hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH; hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH; hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH; hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */ hdsivideo_handle.NullPacketSize = 0xFFF; hdsivideo_handle.NumberOfChunks = 0; hdsivideo_handle.PacketSize = HACT; /* Value depending on display orientation choice portrait/landscape */ hdsivideo_handle.HorizontalSyncActive = HSA*Clockratio; hdsivideo_handle.HorizontalBackPorch = HBP*Clockratio; hdsivideo_handle.HorizontalLine = (HACT + HSA + HBP + HFP)*Clockratio; /* Value depending on display orientation choice portrait/landscape */ hdsivideo_handle.VerticalSyncActive = VSA; hdsivideo_handle.VerticalBackPorch = VBP; hdsivideo_handle.VerticalFrontPorch = VFP; hdsivideo_handle.VerticalActive = VACT; /* Value depending on display orientation choice portrait/landscape */ /* Enable or disable sending LP command while streaming is active in video mode */ hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */ /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */ /* Only useful when sending LP packets is allowed while streaming is active in video mode */ hdsivideo_handle.LPLargestPacketSize = 64; /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */ /* Only useful when sending LP packets is allowed while streaming is active in video mode */ hdsivideo_handle.LPVACTLargestPacketSize = 64; /* Specify for each region of the video frame, if the transmission of command in LP mode is allowed in this region */ /* while streaming is active in video mode */ hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE; /* Allow sending LP commands during HFP period */ hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_ENABLE; /* Allow sending LP commands during HBP period */ hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE; /* Allow sending LP commands during VACT period */ hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE; /* Allow sending LP commands during VFP period */ hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE; /* Allow sending LP commands during VBP period */ hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */ /* Configure DSI Video mode timings with settings set above */ HAL_DSI_ConfigVideoMode(&(hdsi_eval), &(hdsivideo_handle)); /* Enable the DSI host and wrapper : but LTDC is not started yet at this stage */ HAL_DSI_Start(&(hdsi_eval)); /*************************End DSI Initialization*******************************/ /************************LTDC Initialization***********************************/ /* Timing Configuration */ hltdc_eval.Init.HorizontalSync = (HSA - 1); hltdc_eval.Init.AccumulatedHBP = (HSA + HBP - 1); hltdc_eval.Init.AccumulatedActiveW = (HACT + HSA + HBP - 1); hltdc_eval.Init.TotalWidth = (HACT + HSA + HBP + HFP - 1); /* Initialize the LCD pixel width and pixel height */ hltdc_eval.LayerCfg->ImageWidth = HACT; hltdc_eval.LayerCfg->ImageHeight = VACT; /* LCD clock configuration */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.857 MHz */ /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.857 MHz / 2 = 27.429 MHz */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; PeriphClkInitStruct.PLLSAI.PLLSAIN = 384; PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_4; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); /* Background value */ hltdc_eval.Init.Backcolor.Blue = 0; hltdc_eval.Init.Backcolor.Green = 0; hltdc_eval.Init.Backcolor.Red = 0; hltdc_eval.Init.PCPolarity = LTDC_PCPOLARITY_IPC; hltdc_eval.Instance = LTDC; /* Get LTDC Configuration from DSI Configuration */ HAL_LTDC_StructInitFromVideoConfig(&(hltdc_eval), &(hdsivideo_handle)); /* Initialize the LTDC */ HAL_LTDC_Init(&hltdc_eval); #if !defined(DATA_IN_ExtSDRAM) /* Initialize the SDRAM */ BSP_SDRAM_Init(); #endif /* DATA_IN_ExtSDRAM */ /* Initialize the font */ BSP_LCD_SetFont(&LCD_DEFAULT_FONT); /************************End LTDC Initialization*******************************/ /***********************OTM8009A Initialization********************************/ /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver) * depending on configuration set in 'hdsivideo_handle'. */ OTM8009A_Init(hdsivideo_handle.ColorCoding, LCD_ORIENTATION_LANDSCAPE); /***********************End OTM8009A Initialization****************************/ return LCD_OK; }