你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【STM32N6570-DK评测】测试LCD显示

[复制链接]
TLLED 发布时间:2025-2-18 15:02



一、硬件部分
1.1、LCD显示屏硬件接口部分电路
lcd.png





1.2、LTDC显示内部框图
LTDC可驱动24位的RGB显示屏,内部有两个显示层
002.png



二、配置LTDC

2.1、屏幕的参数设置
003.png


2.2、层参数设置
004.png



2.3、LTDC引脚设置
005.png



三、程序部分

3.1、在项目中添加LCD驱动程序
使用官方BSP中的LCD驱动程序
stm32n6570_discovery_lcd.c

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32n6570_discovery_lcd.c
  4.   * @author  MCD Application Team
  5.   * @brief   This file includes the driver for Liquid Crystal Display (LCD) module
  6.   *          mounted on STM32N6570_DK board.
  7.   ******************************************************************************
  8.   * @attention
  9.   *
  10.   * Copyright (c) 2022 STMicroelectronics.
  11.   * All rights reserved.
  12.   *
  13.   * This software is licensed under terms that can be found in the LICENSE file
  14.   * in the root directory of this software component.
  15.   * If no LICENSE file comes with this software, it is provided AS-IS.
  16.   *
  17.   ******************************************************************************
  18.   @verbatim
  19.   How To use this driver:
  20.   --------------------------
  21.    - This driver is used to drive directly a LCD TFT using the LTDC controller.
  22.    - This driver uses the adequate timing and setting for the RK050HR18 LCD component

  23.   Driver description:
  24.   ---------------------
  25.    + Initialization steps:
  26.      o Initialize the LCD in default mode using the BSP_LCD_Init() function with the
  27.        following settings:
  28.         - Pixelformat : LCD_PIXEL_FORMAT_RGB888
  29.         - Orientation : LCD_ORIENTATION_LANDSCAPE.
  30.         - Width       : LCD_DEFAULT_WIDTH (800)
  31.         - Height      : LCD_DEFAULT_HEIGHT(480)
  32.        The default LTDC layer configured is layer 0.
  33.        BSP_LCD_Init() includes LTDC, LTDC Layer and clock configurations by calling:
  34.         - MX_LTDC_ClockConfig()
  35.         - MX_LTDC_Init()
  36.         - MX_LTDC_ConfigLayer()

  37.      o Initialize the LCD with required parameters using the BSP_LCD_InitEx() function.

  38.      o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function.
  39.      o Enable the LCD display using the BSP_LCD_DisplayOn() function.
  40.      o Disable the LCD display using the BSP_LCD_DisplayOff() function.
  41.      o Write a pixel to the LCD memory using the BSP_LCD_WritePixel() function.
  42.      o Read a pixel from the LCD memory using the BSP_LCD_ReadPixel() function.
  43.      o Draw an horizontal line using the BSP_LCD_DrawHLine() function.
  44.      o Draw a vertical line using the BSP_LCD_DrawVLine() function.
  45.      o Draw a bitmap image using the BSP_LCD_DrawBitmap() function.

  46.    + Options
  47.      o Configure the LTDC reload mode by calling BSP_LCD_Reload(). By default, the
  48.        reload mode is set to BSP_LCD_RELOAD_IMMEDIATE then LTDC is reloaded immediately.
  49.        To control the reload mode:
  50.          - Call BSP_LCD_Reload() with ReloadType parameter set to BSP_LCD_RELOAD_NONE
  51.          - Configure LTDC (color keying, transparency ..)
  52.          - Call BSP_LCD_Reload() with ReloadType parameter set to BSP_LCD_RELOAD_IMMEDIATE
  53.            for immediate reload or BSP_LCD_RELOAD_VERTICAL_BLANKING for LTDC reload
  54.            in the next vertical blanking
  55.      o Configure LTDC layers using BSP_LCD_ConfigLayer()
  56.      o Control layer visibility using BSP_LCD_SetLayerVisible()
  57.      o Configure and enable the color keying functionality using the
  58.        BSP_LCD_SetColorKeying() function.
  59.      o Disable the color keying functionality using the BSP_LCD_ResetColorKeying() function.
  60.      o Modify on the fly the transparency and/or the frame buffer address
  61.        using the following functions:
  62.        - BSP_LCD_SetTransparency()
  63.        - BSP_LCD_SetLayerAddress()

  64.    + Display on LCD
  65.      o To draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
  66.        on LCD and display text, utility basic_gui.c/.h must be called. Once the LCD is initialized,
  67.        user should call GUI_SetFuncDriver() API to link board LCD drivers to BASIC GUI LCD drivers.
  68.        The basic gui services, defined in basic_gui utility, are ready for use.

  69.   Note:
  70.   --------
  71.     Regarding the "Instance" parameter, needed for all functions, it is used to select
  72.     an LCD instance. On the STM32N6570 Discovery board, there's one instance. Then, this
  73.     parameter should be 0.

  74.   @endverbatim
  75.   ******************************************************************************
  76.   */

  77. /* Includes ------------------------------------------------------------------*/
  78. #include "stm32n6570_discovery_lcd.h"

  79. /** @addtogroup BSP
  80.   * @{
  81.   */

  82. /** @addtogroup STM32N6570_DK
  83.   * @{
  84.   */

  85. /** @defgroup STM32N6570_DK_LCD LCD
  86.   * @{
  87.   */

  88. /** @defgroup STM32N6570_DK_LCD_Private_Variables LCD Private Variables
  89.   * @{
  90.   */

  91. /**
  92.   * @}
  93.   */

  94. /** @defgroup STM32N6570_DK_LCD_Private_TypesDefinitions LCD Private TypesDefinitions
  95.   * @{
  96.   */
  97. const LCD_UTILS_Drv_t LCD_Driver =
  98. {
  99.   BSP_LCD_DrawBitmap,
  100.   BSP_LCD_FillRGBRect,
  101.   BSP_LCD_DrawHLine,
  102.   BSP_LCD_DrawVLine,
  103.   BSP_LCD_FillRect,
  104.   BSP_LCD_ReadPixel,
  105.   BSP_LCD_WritePixel,
  106.   BSP_LCD_GetXSize,
  107.   BSP_LCD_GetYSize,
  108.   BSP_LCD_SetActiveLayer,
  109.   BSP_LCD_GetPixelFormat
  110. };

  111. /**
  112.   * @}
  113.   */

  114. /** @defgroup STM32N6570_DK_LCD_Exported_Variables LCD Exported Variables
  115.   * @{
  116.   */
  117. DMA2D_HandleTypeDef hlcd_dma2d;
  118. LTDC_HandleTypeDef  hlcd_ltdc;
  119. BSP_LCD_Ctx_t       Lcd_Ctx[LCD_INSTANCES_NBR];
  120. /**
  121.   * @}
  122.   */

  123. /** @defgroup STM32N6570_DK_LCD_Private_FunctionPrototypes LCD Private FunctionPrototypes
  124.   * @{
  125.   */

  126. static void LTDC_MspInit(LTDC_HandleTypeDef *hltdc);
  127. static void LTDC_MspDeInit(LTDC_HandleTypeDef *hltdc);
  128. static void DMA2D_MspInit(DMA2D_HandleTypeDef *hdma2d);
  129. static void DMA2D_MspDeInit(DMA2D_HandleTypeDef *hdma2d);
  130. static void LL_FillBuffer(uint32_t Instance, uint32_t *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t Color);
  131. static void LL_ConvertLineToRGB(uint32_t Instance, uint32_t *pSrc, uint32_t *pDst, uint32_t xSize, uint32_t ColorMode);
  132. /**
  133.   * @}
  134.   */
  135. /** @defgroup STM32N6570_DK_LCD_Private_Macros  Private Macros
  136.   * @{
  137.   */
  138. #define CONVERTRGB5652ARGB8888(Color)((((((((Color) >> (11U)) & 0x1FU) * 527U) + 23U) >> (6U)) << (16U)) |\
  139.                                      (((((((Color) >> (5U)) & 0x3FU) * 259U) + 33U) >> (6U)) << (8U)) |\
  140.                                      (((((Color) & 0x1FU) * 527U) + 23U) >> (6U)) | (0xFF000000U))

  141. #define CONVERTARGB44442ARGB8888(Color)((((((Color) >> 12U) & 0xFU) * 17U) << 24U) |\
  142.                                         (((((Color) >>  8U) & 0xFU) * 17U) << 16U) |\
  143.                                         (((((Color) >>  4U) & 0xFU) * 17U) << 8U) |\
  144.                                         (((((Color) >>  0U) & 0xFU) * 17U) << 0U))

  145. #define CONVERTRGB8882ARGB8888(Color)((Color) | 0xFF000000U)

  146. #define CONVERTARGB88882RGB888(Color)((Color) & 0x00FFFFFFU)

  147. /**
  148.   * @}
  149.   */

  150. /** @defgroup STM32N6570_DK_LCD_Exported_Functions LCD Exported Functions
  151.   * @{
  152.   */
  153. /**
  154.   * @brief  Initializes the LCD in default mode.
  155.   * @param  Instance    LCD Instance
  156.   * @param  Orientation LCD_ORIENTATION_LANDSCAPE
  157.   * @retval BSP status
  158.   */

  159. int32_t BSP_LCD_Init(uint32_t Instance, uint32_t Orientation)
  160. {
  161.   return BSP_LCD_InitEx(Instance, Orientation, LCD_PIXEL_FORMAT_RGB565, LCD_DEFAULT_WIDTH, LCD_DEFAULT_HEIGHT);
  162. }

  163. /**
  164.   * @brief  Initializes the LCD.
  165.   * @param  Instance    LCD Instance
  166.   * @param  Orientation LCD_ORIENTATION_LANDSCAPE
  167.   * @param  PixelFormat LCD_PIXEL_FORMAT_RGB565, LCD_PIXEL_FORMAT_ARGB4444, LCD_PIXEL_FORMAT_ARGB8888
  168.   *                     or LCD_PIXEL_FORMAT_RGB888
  169.   * @param  Width       Display width
  170.   * @param  Height      Display height
  171.   * @retval BSP status
  172.   */
  173. int32_t BSP_LCD_InitEx(uint32_t Instance, uint32_t Orientation, uint32_t PixelFormat, uint32_t Width, uint32_t Height)
  174. {
  175.   int32_t ret = BSP_ERROR_NONE;
  176.   uint32_t ltdc_pixel_format;
  177.   MX_LTDC_LayerConfig_t config = {0};

  178.   if ((Orientation > LCD_ORIENTATION_LANDSCAPE) || (Instance >= LCD_INSTANCES_NBR) || \
  179.      ((PixelFormat != LCD_PIXEL_FORMAT_RGB565) && (PixelFormat != LCD_PIXEL_FORMAT_RGB888) && \
  180.       (PixelFormat != LCD_PIXEL_FORMAT_ARGB8888) &&  (PixelFormat != LCD_PIXEL_FORMAT_ARGB4444)))
  181.   {
  182.     ret = BSP_ERROR_WRONG_PARAM;
  183.   }
  184.   else
  185.   {
  186.     if (PixelFormat == LCD_PIXEL_FORMAT_RGB565)
  187.     {
  188.       ltdc_pixel_format = LTDC_PIXEL_FORMAT_RGB565;
  189.       Lcd_Ctx[Instance].BppFactor = 2U;
  190.     }
  191.     else if  (PixelFormat == LCD_PIXEL_FORMAT_RGB888)
  192.     {
  193.       ltdc_pixel_format = LTDC_PIXEL_FORMAT_RGB888;
  194.       Lcd_Ctx[Instance].BppFactor = 3U;
  195.     }
  196.     else if  (PixelFormat == LCD_PIXEL_FORMAT_ARGB4444)
  197.     {
  198.       ltdc_pixel_format = LTDC_PIXEL_FORMAT_ARGB4444;
  199.       Lcd_Ctx[Instance].BppFactor = 2U;
  200.     }
  201.     else /* LCD_PIXEL_FORMAT_ARGB8888 */
  202.     {
  203.       ltdc_pixel_format = LTDC_PIXEL_FORMAT_ARGB8888;
  204.       Lcd_Ctx[Instance].BppFactor = 4U;
  205.     }

  206.     /* Store pixel format, xsize and ysize information */
  207.     Lcd_Ctx[Instance].PixelFormat = PixelFormat;
  208.     Lcd_Ctx[Instance].XSize  = Width;
  209.     Lcd_Ctx[Instance].YSize  = Height;

  210.     /* Initializes peripherals instance value */
  211.     hlcd_ltdc.Instance = LTDC;
  212.     hlcd_dma2d.Instance = DMA2D;

  213.     /* MSP initialization */
  214. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  215.     /* Register the LTDC MSP Callbacks */
  216.     if (Lcd_Ctx[Instance].IsMspCallbacksValid == 0U)
  217.     {
  218.       if (BSP_LCD_RegisterDefaultMspCallbacks(0) != BSP_ERROR_NONE)
  219.       {
  220.         return BSP_ERROR_PERIPH_FAILURE;
  221.       }
  222.     }
  223. #else
  224.     LTDC_MspInit(&hlcd_ltdc);
  225. #endif /* (USE_HAL_LTDC_REGISTER_CALLBACKS == 1) */

  226.     DMA2D_MspInit(&hlcd_dma2d);

  227.     if (MX_LTDC_ClockConfig(&hlcd_ltdc) != HAL_OK)
  228.     {
  229.       ret = BSP_ERROR_PERIPH_FAILURE;
  230.     }
  231.     else
  232.     {
  233.       if (MX_LTDC_Init(&hlcd_ltdc, Width, Height) != HAL_OK)
  234.       {
  235.         ret = BSP_ERROR_PERIPH_FAILURE;
  236.       }
  237.     }

  238.     if (ret == BSP_ERROR_NONE)
  239.     {
  240. #if defined(DATA_IN_ExtRAM)
  241.       /* Before configuring LTDC layer, ensure XSPI RAM is initialized */
  242.       /* Initialize the XSPI RAM */
  243.       if (BSP_XSPI_RAM_Init(0) != BSP_ERROR_NONE)
  244.       {
  245.         ret = BSP_ERROR_NO_INIT;
  246.       }
  247.       else if (BSP_XSPI_RAM_EnableMemoryMappedMode(0) != BSP_ERROR_NONE)
  248.       {
  249.         ret = BSP_ERROR_PERIPH_FAILURE;
  250.       }
  251.       else
  252.       {
  253. #endif /* DATA_IN_ExtRAM */
  254.         /* Configure default LTDC Layer 0. This configuration can be override by calling
  255.         BSP_LCD_ConfigLayer() at application level */
  256.         config.X0          = 0;
  257.         config.X1          = Width;
  258.         config.Y0          = 0;
  259.         config.Y1          = Height;
  260.         config.PixelFormat = ltdc_pixel_format;
  261.         config.Address     = LCD_LAYER_0_ADDRESS;

  262.         if (MX_LTDC_ConfigLayer(&hlcd_ltdc, 0, &config) != HAL_OK)
  263.         {
  264.           ret = BSP_ERROR_PERIPH_FAILURE;
  265.         }

  266.         /* By default the reload is activated and executed immediately */
  267.         Lcd_Ctx[Instance].ReloadEnable = 1U;
  268. #if defined(DATA_IN_ExtRAM)
  269.       }
  270. #endif /* DATA_IN_ExtRAM */
  271.     }
  272.   }

  273.   return ret;
  274. }

  275. /**
  276.   * @brief  De-Initializes the LCD resources.
  277.   * @param  Instance    LCD Instance
  278.   * @retval BSP status
  279.   */
  280. int32_t BSP_LCD_DeInit(uint32_t Instance)
  281. {
  282.   int32_t ret = BSP_ERROR_NONE;

  283.   if(Instance >= LCD_INSTANCES_NBR)
  284.   {
  285.     ret = BSP_ERROR_WRONG_PARAM;
  286.   }
  287.   else
  288.   {
  289. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 0)
  290.     LTDC_MspDeInit(&hlcd_ltdc);
  291. #endif /* (USE_HAL_LTDC_REGISTER_CALLBACKS == 0) */

  292.     (void)HAL_LTDC_DeInit(&hlcd_ltdc);
  293.     if(HAL_DMA2D_DeInit(&hlcd_dma2d) != HAL_OK)
  294.     {
  295.       ret = BSP_ERROR_PERIPH_FAILURE;
  296.     }
  297.     else
  298.     {
  299.       DMA2D_MspDeInit(&hlcd_dma2d);
  300.       Lcd_Ctx[Instance].IsMspCallbacksValid = 0;
  301.     }
  302.   }

  303.   return ret;
  304. }

  305. /**
  306.   * @brief  Initializes the LTDC.
  307.   * @param  hltdc  LTDC handle
  308.   * @param  Width  LTDC width
  309.   * @param  Height LTDC height
  310.   * @retval HAL status
  311.   */
  312. __weak HAL_StatusTypeDef MX_LTDC_Init(LTDC_HandleTypeDef *hltdc, uint32_t Width, uint32_t Height)
  313. {
  314.   hltdc->Instance = LTDC;
  315.   hltdc->Init.HSPolarity = LTDC_HSPOLARITY_AL;
  316.   hltdc->Init.VSPolarity = LTDC_VSPOLARITY_AL;
  317.   hltdc->Init.DEPolarity = LTDC_DEPOLARITY_AL;
  318.   hltdc->Init.PCPolarity = LTDC_PCPOLARITY_IPC;

  319.   hltdc->Init.HorizontalSync     = (uint32_t)RK050HR18_HSYNC - 1U;
  320.   hltdc->Init.AccumulatedHBP     = (uint32_t)RK050HR18_HSYNC + (uint32_t)RK050HR18_HBP - 1U;
  321.   hltdc->Init.AccumulatedActiveW = (uint32_t)RK050HR18_HSYNC + Width + (uint32_t)RK050HR18_HBP -1U;
  322.   hltdc->Init.TotalWidth         = (uint32_t)RK050HR18_HSYNC + Width + (uint32_t)RK050HR18_HBP + RK050HR18_HFP - 1U;
  323.   hltdc->Init.VerticalSync       = (uint32_t)RK050HR18_VSYNC - 1U;
  324.   hltdc->Init.AccumulatedVBP     = (uint32_t)RK050HR18_VSYNC + (uint32_t)RK050HR18_VBP - 1U;
  325.   hltdc->Init.AccumulatedActiveH = (uint32_t)RK050HR18_VSYNC + Height + (uint32_t)RK050HR18_VBP -1U;
  326.   hltdc->Init.TotalHeigh         = (uint32_t)RK050HR18_VSYNC + Height + (uint32_t)RK050HR18_VBP + RK050HR18_VFP - 1U;

  327.   hltdc->Init.Backcolor.Blue  = 0x0;
  328.   hltdc->Init.Backcolor.Green = 0x0;
  329.   hltdc->Init.Backcolor.Red   = 0x0;

  330.   return HAL_LTDC_Init(hltdc);
  331. }

  332. /**
  333.   * @brief  MX LTDC layer configuration.
  334.   * @param  hltdc      LTDC handle
  335.   * @param  LayerIndex Layer 0 or 1
  336.   * @param  Config     Layer configuration
  337.   * @retval HAL status
  338.   */
  339. __weak HAL_StatusTypeDef MX_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, uint32_t LayerIndex, MX_LTDC_LayerConfig_t *Config)
  340. {
  341.   LTDC_LayerCfgTypeDef pLayerCfg ={0};

  342.   pLayerCfg.WindowX0 = Config->X0;
  343.   pLayerCfg.WindowX1 = Config->X1;
  344.   pLayerCfg.WindowY0 = Config->Y0;
  345.   pLayerCfg.WindowY1 = Config->Y1;
  346.   pLayerCfg.PixelFormat = Config->PixelFormat;
  347.   pLayerCfg.Alpha = LTDC_LxCACR_CONSTA;
  348.   pLayerCfg.Alpha0 = 0;
  349.   pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
  350.   pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
  351.   pLayerCfg.FBStartAdress = Config->Address;
  352.   pLayerCfg.ImageWidth = (Config->X1 - Config->X0);
  353.   pLayerCfg.ImageHeight = (Config->Y1 - Config->Y0);
  354.   pLayerCfg.Backcolor.Blue = 0;
  355.   pLayerCfg.Backcolor.Green = 0;
  356.   pLayerCfg.Backcolor.Red = 0;
  357.   return HAL_LTDC_ConfigLayer(hltdc, &pLayerCfg, LayerIndex);
  358. }

  359. /**
  360.   * @brief  LTDC Clock Config for LCD DPI display.
  361.   * @param  hltdc  LTDC Handle
  362.   *         Being __weak it can be overwritten by the application
  363.   * @retval HAL_status
  364.   */
  365. __weak HAL_StatusTypeDef MX_LTDC_ClockConfig(LTDC_HandleTypeDef *hltdc)
  366. {
  367.   /* Prevent unused argument(s) compilation warning */
  368.   UNUSED(hltdc);

  369.   HAL_StatusTypeDef   status =  HAL_OK;
  370.   RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct = {0};

  371.   /* LCD clock configuration */
  372.   /* Typical PCLK is 25 MHz so the PLL4 is configured to provide this clock */
  373.   /* LTDC - PLL4 */
  374.   /* Configure LTDC clock to IC16 with PLL4  */

  375.   /* LCD clock configuration */
  376.   /* Typical PCLK is 25 MHz so the PLL4 is configured to provide this clock */
  377.   /* LCD clock configuration */
  378.   /* PLL3_VCO Input = HSE_VALUE/PLLM = 48 Mhz / 192 = 0.25 */
  379.   /* PLL3_VCO Output = PLL3_VCO Input * PLLN = 0.25 Mhz * 100 = 25 */
  380.   /* PLLLCDCLK = PLL3_VCO Output/(PLLP1 * PLLP2) = 25/1 = 25Mhz */
  381.   /* LTDC clock frequency = PLLLCDCLK = 25 Mhz */

  382.   RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
  383.   RCC_PeriphCLKInitStruct.LtdcClockSelection = RCC_LTDCCLKSOURCE_IC16;
  384.   RCC_PeriphCLKInitStruct.ICSelection[RCC_IC16].ClockSelection = RCC_ICCLKSOURCE_PLL4;
  385.   RCC_PeriphCLKInitStruct.ICSelection[RCC_IC16].ClockDivider = 2;
  386.   if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct) != HAL_OK)
  387.   {
  388.     status = HAL_ERROR;
  389.   }

  390.   return status;
  391. }

  392. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  393. /**
  394.   * @brief Default BSP LCD Msp Callbacks
  395.   * @param Instance BSP LCD Instance
  396.   * @retval BSP status
  397.   */
  398. int32_t BSP_LCD_RegisterDefaultMspCallbacks (uint32_t Instance)
  399. {
  400.   int32_t ret = BSP_ERROR_NONE;

  401.   if(Instance >= LCD_INSTANCES_NBR)
  402.   {
  403.     ret = BSP_ERROR_WRONG_PARAM;
  404.   }
  405.   else
  406.   {
  407.     if(HAL_LTDC_RegisterCallback(&hlcd_ltdc, HAL_LTDC_MSPINIT_CB_ID, LTDC_MspInit) != HAL_OK)
  408.     {
  409.       ret = BSP_ERROR_PERIPH_FAILURE;
  410.     }
  411.     else
  412.     {
  413.       if(HAL_LTDC_RegisterCallback(&hlcd_ltdc, HAL_LTDC_MSPDEINIT_CB_ID, LTDC_MspDeInit) != HAL_OK)
  414.       {
  415.         ret = BSP_ERROR_PERIPH_FAILURE;
  416.       }
  417.     }

  418.     Lcd_Ctx[Instance].IsMspCallbacksValid = 1;
  419.   }

  420.   return ret;
  421. }

  422. /**
  423.   * @brief BSP LCD Msp Callback registering
  424.   * @param Instance    LCD Instance
  425.   * @param CallBacks   pointer to LCD MspInit/MspDeInit functions
  426.   * @retval BSP status
  427.   */
  428. int32_t BSP_LCD_RegisterMspCallbacks (uint32_t Instance, BSP_LCD_Cb_t *CallBacks)
  429. {
  430.   int32_t ret = BSP_ERROR_NONE;

  431.   if(Instance >= LCD_INSTANCES_NBR)
  432.   {
  433.     ret = BSP_ERROR_WRONG_PARAM;
  434.   }
  435.   else
  436.   {
  437.     if(HAL_LTDC_RegisterCallback(&hlcd_ltdc, HAL_LTDC_MSPINIT_CB_ID, CallBacks->pMspLtdcInitCb) != HAL_OK)
  438.     {
  439.       ret = BSP_ERROR_PERIPH_FAILURE;
  440.     }
  441.     else
  442.     {
  443.       if(HAL_LTDC_RegisterCallback(&hlcd_ltdc, HAL_LTDC_MSPDEINIT_CB_ID, CallBacks->pMspLtdcDeInitCb) != HAL_OK)
  444.       {
  445.         ret = BSP_ERROR_PERIPH_FAILURE;
  446.       }
  447.     }

  448.     Lcd_Ctx[Instance].IsMspCallbacksValid = 1;
  449.   }

  450.   return ret;
  451. }
  452. #endif /*(USE_HAL_LTDC_REGISTER_CALLBACKS == 1) */

  453. /**
  454.   * @brief  LTDC layer configuration.
  455.   * @param  Instance   LCD instance
  456.   * @param  LayerIndex Layer 0 or 1
  457.   * @param  Config     Layer configuration
  458.   * @retval HAL status
  459.   */
  460. int32_t BSP_LCD_ConfigLayer(uint32_t Instance, uint32_t LayerIndex, BSP_LCD_LayerConfig_t *Config)
  461. {
  462.   int32_t ret = BSP_ERROR_NONE;
  463.   if(Instance >= LCD_INSTANCES_NBR)
  464.   {
  465.     ret = BSP_ERROR_WRONG_PARAM;
  466.   }
  467.   else
  468.   {
  469.     if (Config->PixelFormat ==  LCD_PIXEL_FORMAT_RGB565)
  470.     {
  471.       Config->PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
  472.     }
  473.     else if (Config->PixelFormat ==  LCD_PIXEL_FORMAT_ARGB4444)
  474.     {
  475.       Config->PixelFormat = LTDC_PIXEL_FORMAT_ARGB4444;
  476.     }
  477.     else if (Config->PixelFormat ==  LCD_PIXEL_FORMAT_ARGB8888)
  478.     {
  479.       Config->PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
  480.     }
  481.     else
  482.     {
  483.       Config->PixelFormat = LTDC_PIXEL_FORMAT_RGB888;
  484.     }
  485.     if (MX_LTDC_ConfigLayer(&hlcd_ltdc, LayerIndex, Config) != HAL_OK)
  486.     {
  487.       ret = BSP_ERROR_PERIPH_FAILURE;
  488.     }
  489.   }
  490.   return ret;
  491. }

  492. /**
  493.   * @brief  Gets the LCD Active LCD Pixel Format.
  494.   * @param  Instance    LCD Instance
  495.   * @param  PixelFormat Active LCD Pixel Format
  496.   * @retval BSP status
  497.   */
  498. int32_t BSP_LCD_GetPixelFormat(uint32_t Instance, uint32_t *PixelFormat)
  499. {
  500.   int32_t ret = BSP_ERROR_NONE;

  501.   if(Instance >= LCD_INSTANCES_NBR)
  502.   {
  503.     ret = BSP_ERROR_WRONG_PARAM;
  504.   }
  505.   else
  506.   {
  507.     /* Only RGB565 format is supported */
  508.     *PixelFormat =  Lcd_Ctx[Instance].PixelFormat;
  509.   }

  510.   return ret;
  511. }

  512. /**
  513.   * @brief  Set the LCD Active Layer.
  514.   * @param  Instance    LCD Instance
  515.   * @param  LayerIndex  LCD layer index
  516.   * @retval BSP status
  517.   */
  518. int32_t BSP_LCD_SetActiveLayer(uint32_t Instance, uint32_t LayerIndex)
  519. {
  520.   int32_t ret = BSP_ERROR_NONE;
  521.   LTDC_LayerCfgTypeDef *pLayerCfg;

  522.   if(Instance >= LCD_INSTANCES_NBR)
  523.   {
  524.     ret = BSP_ERROR_WRONG_PARAM;
  525.   }
  526.   else
  527.   {
  528.     pLayerCfg = &hlcd_ltdc.LayerCfg[LayerIndex];

  529.     Lcd_Ctx[Instance].ActiveLayer = LayerIndex;
  530.     Lcd_Ctx[Instance].XSize = pLayerCfg->ImageWidth;
  531.     Lcd_Ctx[Instance].YSize = pLayerCfg->ImageHeight;

  532.     if (pLayerCfg->PixelFormat ==  LTDC_PIXEL_FORMAT_RGB565)
  533.     {
  534.       Lcd_Ctx[Instance].BppFactor = 2;
  535.       Lcd_Ctx[Instance].PixelFormat = LCD_PIXEL_FORMAT_RGB565;
  536.     }
  537.     else if (pLayerCfg->PixelFormat ==  LTDC_PIXEL_FORMAT_ARGB4444)
  538.     {
  539.       Lcd_Ctx[Instance].BppFactor = 2;
  540.       Lcd_Ctx[Instance].PixelFormat = LCD_PIXEL_FORMAT_ARGB4444;
  541.     }
  542.     else if (pLayerCfg->PixelFormat ==  LTDC_PIXEL_FORMAT_RGB888)
  543.     {
  544.       Lcd_Ctx[Instance].BppFactor = 3;
  545.       Lcd_Ctx[Instance].PixelFormat = LCD_PIXEL_FORMAT_RGB888;
  546.     }
  547.     else
  548.     {
  549.       Lcd_Ctx[Instance].BppFactor = 4;
  550.       Lcd_Ctx[Instance].PixelFormat = LCD_PIXEL_FORMAT_ARGB8888;
  551.     }
  552.   }

  553.   return ret;
  554. }

  555. /**
  556.   * @brief  Control the LTDC reload
  557.   * @param  Instance    LCD Instance
  558.   * @param  ReloadType can be one of the following values
  559.   *         - BSP_LCD_RELOAD_NONE
  560.   *         - BSP_LCD_RELOAD_IMMEDIATE
  561.   *         - BSP_LCD_RELOAD_VERTICAL_BLANKING
  562.   * @retval BSP status
  563.   */
  564. int32_t BSP_LCD_Reload(uint32_t Instance, uint32_t ReloadType)
  565. {
  566.   int32_t ret = BSP_ERROR_NONE;

  567.   if(Instance >= LCD_INSTANCES_NBR)
  568.   {
  569.     ret = BSP_ERROR_WRONG_PARAM;
  570.   }
  571.   else if(ReloadType == BSP_LCD_RELOAD_NONE)
  572.   {
  573.     Lcd_Ctx[Instance].ReloadEnable = 0U;
  574.   }
  575.   else if(HAL_LTDC_Reload(&hlcd_ltdc, ReloadType) != HAL_OK)
  576.   {
  577.     ret = BSP_ERROR_PERIPH_FAILURE;
  578.   }
  579.   else
  580.   {
  581.     Lcd_Ctx[Instance].ReloadEnable = 1U;
  582.   }

  583.   return ret;
  584. }

  585. /**
  586.   * @brief  Sets an LCD Layer visible
  587.   * @param  Instance    LCD Instance
  588.   * @param  LayerIndex  Visible Layer
  589.   * @param  State  New state of the specified layer
  590.   *          This parameter can be one of the following values:
  591.   *            @arg  ENABLE
  592.   *            @arg  DISABLE
  593.   * @retval BSP status
  594.   */
  595. int32_t BSP_LCD_SetLayerVisible(uint32_t Instance, uint32_t LayerIndex, FunctionalState State)
  596. {
  597.   int32_t ret = BSP_ERROR_NONE;

  598.   if(Instance >= LCD_INSTANCES_NBR)
  599.   {
  600.     ret = BSP_ERROR_WRONG_PARAM;
  601.   }
  602.   else
  603.   {
  604.     if(State == ENABLE)
  605.     {
  606.       __HAL_LTDC_LAYER_ENABLE(&hlcd_ltdc, LayerIndex);
  607.     }
  608.     else
  609.     {
  610.       __HAL_LTDC_LAYER_DISABLE(&hlcd_ltdc, LayerIndex);
  611.     }

  612.     if(Lcd_Ctx[Instance].ReloadEnable == 1U)
  613.     {
  614.       __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG(&hlcd_ltdc);
  615.     }
  616.   }

  617.   return ret;
  618. }

  619. /**
  620.   * @brief  Configures the transparency.
  621.   * @param  Instance      LCD Instance
  622.   * @param  LayerIndex    Layer foreground or background.
  623.   * @param  Transparency  Transparency
  624.   *           This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
  625.   * @retval BSP status
  626.   */
  627. int32_t BSP_LCD_SetTransparency(uint32_t Instance, uint32_t LayerIndex, uint8_t Transparency)
  628. {
  629.   int32_t ret = BSP_ERROR_NONE;

  630.   if(Instance >= LCD_INSTANCES_NBR)
  631.   {
  632.     ret = BSP_ERROR_WRONG_PARAM;
  633.   }
  634.   else
  635.   {
  636.     if(Lcd_Ctx[Instance].ReloadEnable == 1U)
  637.     {
  638.       (void)HAL_LTDC_SetAlpha(&hlcd_ltdc, Transparency, LayerIndex);
  639.     }
  640.     else
  641.     {
  642.       (void)HAL_LTDC_SetAlpha_NoReload(&hlcd_ltdc, Transparency, LayerIndex);
  643.     }
  644.   }

  645.   return ret;
  646. }

  647. /**
  648.   * @brief  Sets an LCD layer frame buffer address.
  649.   * @param  Instance    LCD Instance
  650.   * @param  LayerIndex  Layer foreground or background
  651.   * @param  Address     New LCD frame buffer value
  652.   * @retval BSP status
  653.   */
  654. int32_t BSP_LCD_SetLayerAddress(uint32_t Instance, uint32_t LayerIndex, uint32_t Address)
  655. {
  656.   int32_t ret = BSP_ERROR_NONE;

  657.   if(Instance >= LCD_INSTANCES_NBR)
  658.   {
  659.     ret = BSP_ERROR_WRONG_PARAM;
  660.   }
  661.   else
  662.   {
  663.     if(Lcd_Ctx[Instance].ReloadEnable == 1U)
  664.     {
  665.       (void)HAL_LTDC_SetAddress(&hlcd_ltdc, Address, LayerIndex);
  666.     }
  667.     else
  668.     {
  669.       (void)HAL_LTDC_SetAddress_NoReload(&hlcd_ltdc, Address, LayerIndex);
  670.     }
  671.   }

  672.   return ret;
  673. }

  674. /**
  675.   * @brief  Sets display window.
  676.   * @param  Instance    LCD Instance
  677.   * @param  LayerIndex  Layer index
  678.   * @param  Xpos   LCD X position
  679.   * @param  Ypos   LCD Y position
  680.   * @param  Width  LCD window width
  681.   * @param  Height LCD window height
  682.   * @retval BSP status
  683.   */
  684. int32_t BSP_LCD_SetLayerWindow(uint32_t Instance, uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
  685. {
  686.   int32_t ret = BSP_ERROR_NONE;

  687.   if(Instance >= LCD_INSTANCES_NBR)
  688.   {
  689.     ret = BSP_ERROR_WRONG_PARAM;
  690.   }
  691.   else
  692.   {
  693.     if(Lcd_Ctx[Instance].ReloadEnable == 1U)
  694.     {
  695.       /* Reconfigure the layer size  and position */
  696.       (void)HAL_LTDC_SetWindowSize(&hlcd_ltdc, Width, Height, LayerIndex);
  697.       (void)HAL_LTDC_SetWindowPosition(&hlcd_ltdc, Xpos, Ypos, LayerIndex);
  698.     }
  699.     else
  700.     {
  701.       /* Reconfigure the layer size and position */
  702.       (void)HAL_LTDC_SetWindowSize_NoReload(&hlcd_ltdc, Width, Height, LayerIndex);
  703.       (void)HAL_LTDC_SetWindowPosition_NoReload(&hlcd_ltdc, Xpos, Ypos, LayerIndex);
  704.     }

  705.     Lcd_Ctx[Instance].XSize = Width;
  706.     Lcd_Ctx[Instance].YSize = Height;
  707.   }

  708.   return ret;
  709. }

  710. /**
  711.   * @brief  Configures and sets the color keying.
  712.   * @param  Instance    LCD Instance
  713.   * @param  LayerIndex  Layer foreground or background
  714.   * @param  Color       Color reference
  715.   * @retval BSP status
  716.   */
  717. int32_t BSP_LCD_SetColorKeying(uint32_t Instance, uint32_t LayerIndex, uint32_t Color)
  718. {
  719.   int32_t ret = BSP_ERROR_NONE;

  720.   if(Instance >= LCD_INSTANCES_NBR)
  721.   {
  722.     ret = BSP_ERROR_WRONG_PARAM;
  723.   }
  724.   else
  725.   {
  726.     (void)HAL_LTDC_ConfigColorKeying(&hlcd_ltdc, Color, LayerIndex);
  727.     if(Lcd_Ctx[Instance].ReloadEnable == 1U)
  728.     {
  729.       /* Configure and Enable the color Keying for LCD Layer */

  730.       (void)HAL_LTDC_EnableColorKeying(&hlcd_ltdc, LayerIndex);
  731.     }
  732.     else
  733.     {
  734.       /* Configure and Enable the color Keying for LCD Layer */
  735.       (void)HAL_LTDC_EnableColorKeying_NoReload(&hlcd_ltdc, LayerIndex);
  736.     }
  737.   }

  738.   return ret;
  739. }

  740. /**
  741.   * @brief  Disables the color keying.
  742.   * @param  Instance    LCD Instance
  743.   * @param  LayerIndex Layer foreground or background
  744.   * @retval BSP status
  745.   */
  746. int32_t BSP_LCD_ResetColorKeying(uint32_t Instance, uint32_t LayerIndex)
  747. {
  748.   int32_t ret = BSP_ERROR_NONE;

  749.   if(Instance >= LCD_INSTANCES_NBR)
  750.   {
  751.     ret = BSP_ERROR_WRONG_PARAM;
  752.   }
  753.   else
  754.   {
  755.     if(Lcd_Ctx[Instance].ReloadEnable == 1U)
  756.     {
  757.       /* Disable the color Keying for LCD Layer */
  758.       (void)HAL_LTDC_DisableColorKeying(&hlcd_ltdc, LayerIndex);
  759.     }
  760.     else
  761.     {
  762.       /* Disable the color Keying for LCD Layer */
  763.       (void)HAL_LTDC_DisableColorKeying_NoReload(&hlcd_ltdc, LayerIndex);
  764.     }
  765.   }

  766.   return ret;
  767. }

  768. /**
  769.   * @brief  Gets the LCD X size.
  770.   * @param  Instance  LCD Instance
  771.   * @param  XSize     LCD width
  772.   * @retval BSP status
  773.   */
  774. int32_t BSP_LCD_GetXSize(uint32_t Instance, uint32_t *XSize)
  775. {
  776.   int32_t ret = BSP_ERROR_NONE;

  777.   if(Instance >= LCD_INSTANCES_NBR)
  778.   {
  779.     ret = BSP_ERROR_WRONG_PARAM;
  780.   }
  781.   else
  782.   {
  783.     *XSize = Lcd_Ctx[Instance].XSize;
  784.   }

  785.   return ret;
  786. }

  787. /**
  788.   * @brief  Gets the LCD Y size.
  789.   * @param  Instance  LCD Instance
  790.   * @param  YSize     LCD Height
  791.   * @retval BSP status
  792.   */
  793. int32_t BSP_LCD_GetYSize(uint32_t Instance, uint32_t *YSize)
  794. {
  795.   int32_t ret = BSP_ERROR_NONE;

  796.   if(Instance >= LCD_INSTANCES_NBR)
  797.   {
  798.     ret = BSP_ERROR_WRONG_PARAM;
  799.   }
  800.   else
  801.   {
  802.     *YSize = Lcd_Ctx[Instance].YSize;
  803.   }

  804.   return ret;
  805. }

  806. /**
  807.   * @brief  Switch On the display.
  808.   * @param  Instance    LCD Instance
  809.   * @retval BSP status
  810.   */
  811. int32_t BSP_LCD_DisplayOn(uint32_t Instance)
  812. {
  813.   int32_t ret = BSP_ERROR_NONE;
  814.   GPIO_InitTypeDef gpio_init_structure = {0};

  815.   if(Instance >= LCD_INSTANCES_NBR)
  816.   {
  817.     ret = BSP_ERROR_WRONG_PARAM;
  818.   }
  819.   else
  820.   {
  821.     __HAL_LTDC_ENABLE(&hlcd_ltdc);
  822.     gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
  823.     gpio_init_structure.Pull = GPIO_PULLUP;
  824.     gpio_init_structure.Pin  = LCD_DISP_EN_PIN;
  825.     HAL_GPIO_Init(LCD_DISP_EN_GPIO_PORT, &gpio_init_structure);

  826.     /* Assert LCD_DISP_EN pin */
  827.     HAL_GPIO_WritePin(LCD_DISP_EN_GPIO_PORT,LCD_DISP_EN_PIN, GPIO_PIN_SET);
  828.   }

  829.   return ret;
  830. }

  831. /**
  832.   * @brief  Switch Off the display.
  833.   * @param  Instance    LCD Instance
  834.   * @retval BSP status
  835.   */
  836. int32_t BSP_LCD_DisplayOff(uint32_t Instance)
  837. {
  838.   int32_t ret = BSP_ERROR_NONE;
  839.   GPIO_InitTypeDef gpio_init_structure = {0};

  840.   if(Instance >= LCD_INSTANCES_NBR)
  841.   {
  842.     ret = BSP_ERROR_WRONG_PARAM;
  843.   }
  844.   else
  845.   {
  846.     gpio_init_structure.Mode      = GPIO_MODE_OUTPUT_PP;
  847.     gpio_init_structure.Pull      = GPIO_NOPULL;
  848.     gpio_init_structure.Speed     = GPIO_SPEED_FREQ_MEDIUM;
  849.     gpio_init_structure.Pin       = LCD_DISP_EN_PIN;
  850.     HAL_GPIO_Init(LCD_DISP_EN_GPIO_PORT, &gpio_init_structure);

  851.     HAL_GPIO_WritePin(LCD_DISP_EN_GPIO_PORT,LCD_DISP_EN_PIN, GPIO_PIN_RESET);

  852.     __HAL_LTDC_DISABLE(&hlcd_ltdc);

  853.   }

  854.   return ret;
  855. }

  856. /**
  857.   * @brief  Draws a bitmap picture loaded in the internal Flash in currently active layer.
  858.   * @param  Instance LCD Instance
  859.   * @param  Xpos Bmp X position in the LCD
  860.   * @param  Ypos Bmp Y position in the LCD
  861.   * @param  pBmp Pointer to Bmp picture address in the internal Flash.
  862.   * @retval BSP status
  863.   */
  864. int32_t BSP_LCD_DrawBitmap(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint8_t *pBmp)
  865. {
  866.   int32_t ret = BSP_ERROR_NONE;
  867.   uint32_t index;
  868.   uint32_t width;
  869.   uint32_t height;
  870.   uint32_t bit_pixel;
  871.   uint32_t Address;
  872.   uint32_t input_color_mode;
  873.   uint8_t *pbmp;

  874.   /* Get bitmap data address offset */
  875.   index = (uint32_t)pBmp[10] + ((uint32_t)pBmp[11] << 8) + ((uint32_t)pBmp[12] << 16)  + ((uint32_t)pBmp[13] << 24);

  876.   /* Read bitmap width */
  877.   width = (uint32_t)pBmp[18] + ((uint32_t)pBmp[19] << 8) + ((uint32_t)pBmp[20] << 16)  + ((uint32_t)pBmp[21] << 24);

  878.   /* Read bitmap height */
  879.   height = (uint32_t)pBmp[22] + ((uint32_t)pBmp[23] << 8) + ((uint32_t)pBmp[24] << 16)  + ((uint32_t)pBmp[25] << 24);

  880.   /* Read bit/pixel */
  881.   bit_pixel = (uint32_t)pBmp[28] + ((uint32_t)pBmp[29] << 8);

  882.   /* Set the address */
  883.   Address = hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + (((Lcd_Ctx[Instance].XSize*Ypos) + Xpos)*Lcd_Ctx[Instance].BppFactor);

  884.   /* Get the layer pixel format */
  885.   if ((bit_pixel/8U) == 4U)
  886.   {
  887.     input_color_mode = DMA2D_INPUT_ARGB8888;
  888.   }
  889.   else if ((bit_pixel/8U) == 2U)
  890.   {
  891.     input_color_mode = DMA2D_INPUT_RGB565;
  892.   }
  893.   else
  894.   {
  895.     input_color_mode = DMA2D_INPUT_RGB888;
  896.   }

  897.   /* Bypass the bitmap header */
  898.   pbmp = pBmp + (index + (width * (height - 1U) * (bit_pixel/8U)));

  899.   /* Convert picture to ARGB8888 pixel format */
  900.   for(index=0; index < height; index++)
  901.   {
  902.     /* Pixel format conversion */
  903.     LL_ConvertLineToRGB(Instance, (uint32_t *)pbmp, (uint32_t *)Address, width, input_color_mode);

  904.     /* Increment the source and destination buffers */
  905.     Address+=  (Lcd_Ctx[Instance].XSize * Lcd_Ctx[Instance].BppFactor);
  906.     pbmp -= width*(bit_pixel/8U);
  907.   }

  908.   return ret;
  909. }

  910. /**
  911.   * @brief  Draw a horizontal line on LCD.
  912.   * @param  Instance LCD Instance.
  913.   * @param  Xpos X position.
  914.   * @param  Ypos Y position.
  915.   * @param  pData Pointer to RGB line data
  916.   * @param  Width Rectangle width.
  917.   * @param  Height Rectangle Height.
  918.   * @retval BSP status.
  919.   */
  920. int32_t BSP_LCD_FillRGBRect(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint8_t *pData, uint32_t Width, uint32_t Height)
  921. {
  922.   uint32_t i;
  923.   uint8_t *pdata = pData;

  924. #if (USE_DMA2D_TO_FILL_RGB_RECT == 1)
  925.   uint32_t  Xaddress;
  926.   for(i = 0; i < Height; i++)
  927.   {
  928.     /* Get the line address */
  929.     Xaddress = hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + (Lcd_Ctx[Instance].BppFactor*((Lcd_Ctx[Instance].XSize*(Ypos + i)) + Xpos));

  930. #if (USE_BSP_CPU_CACHE_MAINTENANCE == 1)
  931.     SCB_CleanDCache_by_Addr((uint32_t *)pdata, Lcd_Ctx[Instance].BppFactor*Lcd_Ctx[Instance].XSize);
  932. #endif /* USE_BSP_CPU_CACHE_MAINTENANCE */

  933.     /* Write line */
  934.     if(Lcd_Ctx[Instance].PixelFormat == LCD_PIXEL_FORMAT_RGB565)
  935.     {
  936.       LL_ConvertLineToRGB(Instance, (uint32_t *)pdata, (uint32_t *)Xaddress, Width, DMA2D_INPUT_RGB565);
  937.     }
  938.     else if(Lcd_Ctx[Instance].PixelFormat == LCD_PIXEL_FORMAT_ARGB4444)
  939.     {
  940.       LL_ConvertLineToRGB(Instance, (uint32_t *)pdata, (uint32_t *)Xaddress, Width, DMA2D_INPUT_ARGB4444);
  941.     }
  942.     else if(Lcd_Ctx[Instance].PixelFormat == LCD_PIXEL_FORMAT_RGB888)
  943.     {
  944.       LL_ConvertLineToRGB(Instance, (uint32_t *)pdata, (uint32_t *)Xaddress, Width, DMA2D_INPUT_RGB888);
  945.     }
  946.     else
  947.     {
  948.       LL_ConvertLineToRGB(Instance, (uint32_t *)pdata, (uint32_t *)Xaddress, Width, DMA2D_INPUT_ARGB8888);
  949.     }
  950.     pdata += Lcd_Ctx[Instance].BppFactor*Width;
  951.   }
  952. #else
  953.   uint32_t color;
  954.   uint32_t j;
  955.   for(i = 0; i < Height; i++)
  956.   {
  957.     for(j = 0; j < Width; j++)
  958.     {
  959.       color = (uint32_t)((uint32_t)*pdata | ((uint32_t)(*(pdata + 1U)) << 8U) | ((uint32_t)(*(pdata + 2U)) << 16U) | ((uint32_t)(*(pdata + 3U)) << 24U));
  960.       (void)BSP_LCD_WritePixel(Instance, Xpos + j, Ypos + i, color);
  961.       pdata += Lcd_Ctx[Instance].BppFactor;
  962.     }
  963.   }
  964. #endif /* (USE_DMA2D_TO_FILL_RGB_RECT == 1) */

  965.   return BSP_ERROR_NONE;
  966. }

  967. /**
  968.   * @brief  Draws an horizontal line in currently active layer.
  969.   * @param  Instance   LCD Instance
  970.   * @param  Xpos  X position
  971.   * @param  Ypos  Y position
  972.   * @param  Length  Line length
  973.   * @param  Color RGB color
  974.   * @retval BSP status
  975.   */
  976. int32_t BSP_LCD_DrawHLine(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t Length, uint32_t Color)
  977. {
  978.   uint32_t  Xaddress;

  979.   /* Get the line address */
  980.   Xaddress = hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + (Lcd_Ctx[Instance].BppFactor*((Lcd_Ctx[Instance].XSize*Ypos) + Xpos));

  981.   /* Write line */
  982.   LL_FillBuffer(Instance, (uint32_t *)Xaddress, Length, 1, 0, Color);

  983.   return BSP_ERROR_NONE;
  984. }

  985. /**
  986.   * @brief  Draws a vertical line in currently active layer.
  987.   * @param  Instance   LCD Instance
  988.   * @param  Xpos  X position
  989.   * @param  Ypos  Y position
  990.   * @param  Length  Line length
  991.   * @param  Color RGB color
  992.   * @retval BSP status
  993.   */
  994. int32_t BSP_LCD_DrawVLine(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t Length, uint32_t Color)
  995. {
  996.   uint32_t  Xaddress;

  997.   /* Get the line address */
  998.   Xaddress = (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress) + (Lcd_Ctx[Instance].BppFactor*((Lcd_Ctx[Instance].XSize*Ypos) + Xpos));

  999.   /* Write line */
  1000.   LL_FillBuffer(Instance, (uint32_t *)Xaddress, 1, Length, (Lcd_Ctx[Instance].XSize - 1U), Color);

  1001.   return BSP_ERROR_NONE;
  1002. }

  1003. /**
  1004.   * @brief  Draws a full rectangle in currently active layer.
  1005.   * @param  Instance   LCD Instance
  1006.   * @param  Xpos X position
  1007.   * @param  Ypos Y position
  1008.   * @param  Width Rectangle width
  1009.   * @param  Height Rectangle height
  1010.   * @param  Color RGB color
  1011.   * @retval BSP status
  1012.   */
  1013. int32_t BSP_LCD_FillRect(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t Width, uint32_t Height, uint32_t Color)
  1014. {
  1015.   uint32_t  Xaddress;

  1016.   /* Get the rectangle start address */
  1017.   Xaddress = (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress) + (Lcd_Ctx[Instance].BppFactor*((Lcd_Ctx[Instance].XSize*Ypos) + Xpos));

  1018.   /* Fill the rectangle */
  1019.   LL_FillBuffer(Instance, (uint32_t *)Xaddress, Width, Height, (Lcd_Ctx[Instance].XSize - Width), Color);

  1020.   return BSP_ERROR_NONE;
  1021. }

  1022. /**
  1023.   * @brief  Reads a LCD pixel.
  1024.   * @param  Instance    LCD Instance
  1025.   * @param  Xpos X position
  1026.   * @param  Ypos Y position
  1027.   * @param  Color RGB pixel color
  1028.   * @retval BSP status
  1029.   */
  1030. int32_t BSP_LCD_ReadPixel(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t *Color)
  1031. {
  1032.   if(hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  1033.   {
  1034.     /* Read data value from RAM memory */
  1035.     *Color = *(__IO uint32_t*) (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + (4U*((Ypos*Lcd_Ctx[Instance].XSize) + Xpos)));
  1036.   }
  1037.   else if(hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  1038.   {
  1039.     /* Read data value from RAM memory */
  1040.     *Color = *(__IO uint32_t*) (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + (3U*((Ypos*Lcd_Ctx[Instance].XSize) + Xpos)));
  1041.     *Color = CONVERTARGB88882RGB888(*Color);
  1042.   }
  1043.   else /* if((hlcd_ltdc.LayerCfg[layer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) */
  1044.   {
  1045.     /* Read data value from RAM memory */
  1046.     *Color = *(__IO uint16_t*) (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + (2U*((Ypos*Lcd_Ctx[Instance].XSize) + Xpos)));
  1047.   }

  1048.   return BSP_ERROR_NONE;
  1049. }

  1050. /**
  1051.   * @brief  Draws a pixel on LCD.
  1052.   * @param  Instance    LCD Instance
  1053.   * @param  Xpos X position
  1054.   * @param  Ypos Y position
  1055.   * @param  Color Pixel color
  1056.   * @retval BSP status
  1057.   */
  1058. int32_t BSP_LCD_WritePixel(uint32_t Instance, uint32_t Xpos, uint32_t Ypos, uint32_t Color)
  1059. {
  1060.   if(hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  1061.   {
  1062.     /* Write data value to RAM memory */
  1063.     *(__IO uint32_t*) (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + (4U*((Ypos*Lcd_Ctx[Instance].XSize) + Xpos))) = Color;
  1064.   }
  1065.   else if(hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  1066.   {
  1067.     /* Write data value to RAM memory */
  1068.     *(__IO uint8_t*) (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + ((3U*((Ypos*Lcd_Ctx[Instance].XSize) + Xpos))-3U)) = (uint8_t) (Color);
  1069.     *(__IO uint8_t*) (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + ((3U*((Ypos*Lcd_Ctx[Instance].XSize) + Xpos))-2U)) = (uint8_t) (Color>>8U);
  1070.     *(__IO uint8_t*) (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + ((3U*((Ypos*Lcd_Ctx[Instance].XSize) + Xpos))-1U)) = (uint8_t) (Color>>16U);
  1071.   }
  1072.   else
  1073.   {
  1074.     /* Write data value to RAM memory */
  1075.     *(__IO uint16_t*) (hlcd_ltdc.LayerCfg[Lcd_Ctx[Instance].ActiveLayer].FBStartAdress + (2U*((Ypos*Lcd_Ctx[Instance].XSize) + Xpos))) = (uint16_t)Color;
  1076.   }

  1077.   return BSP_ERROR_NONE;
  1078. }

  1079. /**
  1080.   * @}
  1081.   */

  1082. /** @defgroup STM32N6570_DK_LCD_Private_Functions LCD Private Functions
  1083.   * @{
  1084.   */
  1085. /**
  1086.   * @brief  Fills a buffer.
  1087.   * @param  Instance LCD Instance
  1088.   * @param  pDst Pointer to destination buffer
  1089.   * @param  xSize Buffer width
  1090.   * @param  ySize Buffer height
  1091.   * @param  OffLine Offset
  1092.   * @param  Color RGB color
  1093.   */
  1094. static void LL_FillBuffer(uint32_t Instance, uint32_t *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t Color)
  1095. {
  1096.   uint32_t output_color_mode;
  1097.   uint32_t input_color = Color;

  1098.   switch(Lcd_Ctx[Instance].PixelFormat)
  1099.   {
  1100.   case LCD_PIXEL_FORMAT_RGB565:
  1101.     output_color_mode = DMA2D_OUTPUT_RGB565; /* RGB565 */
  1102.     input_color = CONVERTRGB5652ARGB8888(Color);
  1103.     break;
  1104.   case LCD_PIXEL_FORMAT_ARGB4444:
  1105.     output_color_mode = DMA2D_OUTPUT_ARGB4444; /* ARGB4444 */
  1106.     input_color = CONVERTARGB44442ARGB8888(Color);
  1107.     break;
  1108.   case LCD_PIXEL_FORMAT_RGB888:
  1109.     output_color_mode = DMA2D_OUTPUT_RGB888; /* RGB888 */
  1110.     input_color = CONVERTRGB8882ARGB8888(Color);
  1111.     break;
  1112.   default:
  1113.     output_color_mode = DMA2D_OUTPUT_ARGB8888; /* ARGB8888 */
  1114.     break;
  1115.   }

  1116.   /* Register to memory mode with ARGB8888 as color Mode */
  1117.   hlcd_dma2d.Init.Mode         = DMA2D_R2M;
  1118.   hlcd_dma2d.Init.ColorMode    = output_color_mode;
  1119.   hlcd_dma2d.Init.OutputOffset = OffLine;

  1120.   hlcd_dma2d.Instance = DMA2D;

  1121.   /* DMA2D Initialization */
  1122.   if(HAL_DMA2D_Init(&hlcd_dma2d) == HAL_OK)
  1123.   {
  1124.     if (HAL_DMA2D_Start(&hlcd_dma2d, input_color, (uint32_t)pDst, xSize, ySize) == HAL_OK)
  1125.     {
  1126.       /* Polling For DMA transfer */
  1127.       (void)HAL_DMA2D_PollForTransfer(&hlcd_dma2d, 50);
  1128.     }
  1129.   }
  1130. }

  1131. /**
  1132.   * @brief  Converts a line to an RGB pixel format.
  1133.   * @param  Instance LCD Instance
  1134.   * @param  pSrc Pointer to source buffer
  1135.   * @param  pDst Output color
  1136.   * @param  xSize Buffer width
  1137.   * @param  ColorMode Input color mode
  1138.   */
  1139. static void LL_ConvertLineToRGB(uint32_t Instance, uint32_t *pSrc, uint32_t *pDst, uint32_t xSize, uint32_t ColorMode)
  1140. {
  1141.   uint32_t output_color_mode;

  1142.   switch(Lcd_Ctx[Instance].PixelFormat)
  1143.   {
  1144.   case LCD_PIXEL_FORMAT_RGB565:
  1145.     output_color_mode = DMA2D_OUTPUT_RGB565; /* RGB565 */
  1146.     break;
  1147.   case LCD_PIXEL_FORMAT_ARGB4444:
  1148.     output_color_mode = DMA2D_OUTPUT_ARGB4444; /* ARGB4444 */
  1149.     break;
  1150.   case LCD_PIXEL_FORMAT_RGB888:
  1151.     output_color_mode = DMA2D_OUTPUT_RGB888; /* RGB888 */
  1152.     break;
  1153.   default:
  1154.     output_color_mode = DMA2D_OUTPUT_ARGB8888; /* ARGB8888 */
  1155.     break;
  1156.   }

  1157.   /* Configure the DMA2D Mode, Color Mode and output offset */
  1158.   hlcd_dma2d.Init.Mode         = DMA2D_M2M_PFC;
  1159.   hlcd_dma2d.Init.ColorMode    = output_color_mode;
  1160.   hlcd_dma2d.Init.OutputOffset = 0;

  1161.   /* Foreground Configuration */
  1162.   hlcd_dma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
  1163.   hlcd_dma2d.LayerCfg[1].InputAlpha = 0xFF;
  1164.   hlcd_dma2d.LayerCfg[1].InputColorMode = ColorMode;
  1165.   hlcd_dma2d.LayerCfg[1].InputOffset = 0;

  1166.   hlcd_dma2d.Instance = DMA2D;

  1167.   /* DMA2D Initialization */
  1168.   if(HAL_DMA2D_Init(&hlcd_dma2d) == HAL_OK)
  1169.   {
  1170.     if(HAL_DMA2D_ConfigLayer(&hlcd_dma2d, 1) == HAL_OK)
  1171.     {
  1172.       if (HAL_DMA2D_Start(&hlcd_dma2d, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
  1173.       {
  1174.         /* Polling For DMA transfer */
  1175.         (void)HAL_DMA2D_PollForTransfer(&hlcd_dma2d, 50);
  1176.       }
  1177.     }
  1178.   }
  1179. }

  1180. /**
  1181.   * @brief  Initialize the BSP LTDC Msp.
  1182.   * @param  hltdc  LTDC handle
  1183.   * @retval None
  1184.   */
  1185. static void LTDC_MspInit(LTDC_HandleTypeDef *hltdc)
  1186. {
  1187.   GPIO_InitTypeDef  gpio_init_structure = {0};

  1188.   if (hltdc->Instance == LTDC)
  1189.   {
  1190.     __HAL_RCC_LTDC_CLK_ENABLE();

  1191.     __HAL_RCC_LTDC_FORCE_RESET();
  1192.     __HAL_RCC_LTDC_RELEASE_RESET();

  1193.     /* STM32N6570-DK MB1860A RK050HR18 */
  1194.     /* PG0  R0          */
  1195.     /* PD9  R1          */
  1196.     /* PD15 R2          */
  1197.     /* PB4  R3          */ // JTAG
  1198.     /* PH4  R4          */
  1199.     /* PA15 R5          */ // JTAG JTDI
  1200.     /* PG11 R6          */
  1201.     /* PD8  R7          */
  1202.     /* PG12 G0          */
  1203.     /* PG1  G1          */
  1204.     /* PA1  G2          */
  1205.     /* PA0  G3          */
  1206.     /* PB15 G4          */
  1207.     /* PB12 G5          */
  1208.     /* PB11 G6          */
  1209.     /* PG8  G7          */
  1210.     /* P15  B0          */
  1211.     /* PA7  B1          */
  1212.     /* PB2  B2          */
  1213.     /* PG6  B3          */
  1214.     /* PH3  B4          */
  1215.     /* PH6  B5          */
  1216.     /* PA8  B6          */
  1217.     /* PA2  B7          */
  1218.     /*                  */
  1219.     /* PG13 LCD_DE      */
  1220.     /* PQ3  LCD_ONOFF   */
  1221.     /* PB14 LCD_HSYNC   */
  1222.     /* PE11 PCD_VSYNC   */
  1223.     /* PB13 LCD_CLK     */
  1224.     /* PQ4  LCD_INT     */
  1225.     /* PQ6  LCD_BL_CTRL */
  1226.     /* PE1  NRST        */

  1227.     __HAL_RCC_GPIOA_CLK_ENABLE();
  1228.     __HAL_RCC_GPIOB_CLK_ENABLE();
  1229.     __HAL_RCC_GPIOD_CLK_ENABLE();
  1230.     __HAL_RCC_GPIOE_CLK_ENABLE();
  1231.     __HAL_RCC_GPIOG_CLK_ENABLE();
  1232.     __HAL_RCC_GPIOH_CLK_ENABLE();
  1233.     __HAL_RCC_GPIOQ_CLK_ENABLE();

  1234.     gpio_init_structure.Mode      = GPIO_MODE_AF_PP;
  1235.     gpio_init_structure.Pull      = GPIO_NOPULL;
  1236.     gpio_init_structure.Speed     = GPIO_SPEED_FREQ_HIGH;

  1237.     /* G3, G2, B7, B1, B6, R5 */
  1238.     gpio_init_structure.Pin       = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_15;
  1239.     gpio_init_structure.Alternate = GPIO_AF14_LCD;
  1240.     HAL_GPIO_Init(GPIOA, &gpio_init_structure);

  1241.     /* LCD_CLK, LCD_HSYNC B2, R3, G6, G5, G4 */
  1242.     gpio_init_structure.Pin       = GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_15;
  1243.     gpio_init_structure.Alternate = GPIO_AF14_LCD;
  1244.     HAL_GPIO_Init(GPIOB, &gpio_init_structure);

  1245.     /* R7, R1, R2 */
  1246.     gpio_init_structure.Pin       = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_15;
  1247.     gpio_init_structure.Alternate = GPIO_AF14_LCD;
  1248.     HAL_GPIO_Init(GPIOD, &gpio_init_structure);

  1249.     /* LCD_VSYNC */
  1250.     gpio_init_structure.Pin       = GPIO_PIN_11;
  1251.     gpio_init_structure.Alternate = GPIO_AF14_LCD;
  1252.     HAL_GPIO_Init(GPIOE, &gpio_init_structure);

  1253.     /* R0, G1, B3, G7, R6, G0 */
  1254.     gpio_init_structure.Pin       = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_6 | GPIO_PIN_8 | GPIO_PIN_11 | GPIO_PIN_12 ;
  1255.     gpio_init_structure.Alternate = GPIO_AF14_LCD;
  1256.     HAL_GPIO_Init(GPIOG, &gpio_init_structure);

  1257.     /* B4, R4, B5 */
  1258.     gpio_init_structure.Pin       = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_6;
  1259.     gpio_init_structure.Alternate = GPIO_AF14_LCD;
  1260.     HAL_GPIO_Init(GPIOH, &gpio_init_structure);

  1261.     /* NRST */
  1262.     gpio_init_structure.Pin       = GPIO_PIN_1;
  1263.     gpio_init_structure.Mode      = GPIO_MODE_OUTPUT_PP;
  1264.     HAL_GPIO_Init(GPIOE, &gpio_init_structure);

  1265.     /* LCD_ONOFF, LCD_BL_CTRL */
  1266.     gpio_init_structure.Pin       = GPIO_PIN_3 | GPIO_PIN_6;
  1267.     gpio_init_structure.Mode      = GPIO_MODE_OUTPUT_PP;
  1268.     HAL_GPIO_Init(GPIOQ, &gpio_init_structure);

  1269.     /* LCD_DE */
  1270.     gpio_init_structure.Pin       = GPIO_PIN_13;
  1271.     gpio_init_structure.Mode      = GPIO_MODE_OUTPUT_PP;
  1272.     HAL_GPIO_Init(GPIOG, &gpio_init_structure);

  1273.     HAL_GPIO_WritePin(GPIOQ, GPIO_PIN_3, GPIO_PIN_SET); /* LCD On */ /* PQ3  LCD_ONOFF   */
  1274.     HAL_GPIO_WritePin(GPIOG, GPIO_PIN_13, GPIO_PIN_SET); /* Display Enable */ /* PG13 LCD_DE      */
  1275.     HAL_GPIO_WritePin(GPIOQ, GPIO_PIN_6, GPIO_PIN_SET); /* 100% Brightness */ /* PQ6  LCD_BL_CTRL */

  1276.   }
  1277. }

  1278. /**
  1279.   * @brief  De-Initializes the BSP LTDC Msp
  1280.   * @param  hltdc  LTDC handle
  1281.   * @retval None
  1282.   */
  1283. static void LTDC_MspDeInit(LTDC_HandleTypeDef *hltdc)
  1284. {
  1285.   GPIO_InitTypeDef  gpio_init_structure;

  1286.   if(hltdc->Instance == LTDC)
  1287.   {
  1288.     /* LTDC Pins deactivation */
  1289.     /* GPIOA deactivation */
  1290.     gpio_init_structure.Pin       = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_8|GPIO_PIN_11 |GPIO_PIN_12| GPIO_PIN_15 | GPIO_PIN_6 | GPIO_PIN_9|GPIO_PIN_10;
  1291.     HAL_GPIO_DeInit(GPIOA, gpio_init_structure.Pin);

  1292.     /* GPIOB deactivation */
  1293.     gpio_init_structure.Pin       = GPIO_PIN_13 | GPIO_PIN_15 | GPIO_PIN_3 |GPIO_PIN_4 | GPIO_PIN_10| GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_14;
  1294.     HAL_GPIO_DeInit(GPIOB, gpio_init_structure.Pin);

  1295.     /* GPIOE deactivation */
  1296.     gpio_init_structure.Pin       = GPIO_PIN_11 | GPIO_PIN_15;
  1297.     HAL_GPIO_DeInit(GPIOE, gpio_init_structure.Pin);

  1298.     /* GPIOF deactivation */
  1299.     gpio_init_structure.Pin       = GPIO_PIN_0 | GPIO_PIN_10|GPIO_PIN_11 | GPIO_PIN_9 | GPIO_PIN_7 | GPIO_PIN_15;
  1300.     HAL_GPIO_DeInit(GPIOF, gpio_init_structure.Pin);

  1301.     /* GPIOG deactivation */
  1302.     gpio_init_structure.Pin       = GPIO_PIN_0 | GPIO_PIN_1| GPIO_PIN_2 | GPIO_PIN_13|GPIO_PIN_14;
  1303.     HAL_GPIO_DeInit(GPIOG, gpio_init_structure.Pin);

  1304.     /** Force and let in reset state LTDC */
  1305.     __HAL_RCC_LTDC_FORCE_RESET();

  1306.     __HAL_RCC_LTDC_RELEASE_RESET();

  1307.     /** Disable the LTDC */
  1308.     __HAL_RCC_LTDC_CLK_DISABLE();
  1309.   }
  1310. }

  1311. /**
  1312.   * @brief  Initialize the BSP DMA2D Msp.
  1313.   * @param  hdma2d  DMA2D handle
  1314.   * @retval None
  1315.   */
  1316. static void DMA2D_MspInit(DMA2D_HandleTypeDef *hdma2d)
  1317. {
  1318.   if(hdma2d->Instance == DMA2D)
  1319.   {
  1320.     /** Enable the DMA2D clock */
  1321.     __HAL_RCC_DMA2D_CLK_ENABLE();

  1322.     /** Toggle Sw reset of DMA2D IP */
  1323.     __HAL_RCC_DMA2D_FORCE_RESET();
  1324.     __HAL_RCC_DMA2D_RELEASE_RESET();
  1325.   }
  1326. }

  1327. /**
  1328.   * @brief  De-Initializes the BSP DMA2D Msp
  1329.   * @param  hdma2d  DMA2D handle
  1330.   * @retval None
  1331.   */
  1332. static void DMA2D_MspDeInit(DMA2D_HandleTypeDef *hdma2d)
  1333. {
  1334.   if(hdma2d->Instance == DMA2D)
  1335.   {
  1336.     /** Disable IRQ of DMA2D IP */
  1337.     HAL_NVIC_DisableIRQ(DMA2D_IRQn);

  1338.     /** Force and let in reset state DMA2D */
  1339.     __HAL_RCC_DMA2D_FORCE_RESET();
  1340.     __HAL_RCC_DMA2D_RELEASE_RESET();

  1341.     /** Disable the DMA2D */
  1342.     __HAL_RCC_DMA2D_CLK_DISABLE();
  1343.   }
  1344. }

  1345. /**
  1346.   * @}
  1347.   */

  1348. /**
  1349.   * @}
  1350.   */

  1351. /**
  1352.   * @}
  1353.   */

  1354. /**
  1355.   * @}
  1356.   */

复制代码


2.2、main.c
  1. int main(void)
  2. {
  3.   uint32_t x_size;
  4.   uint32_t y_size;
  5.   uint16_t i,j;

  6.   HAL_Init();
  7.   SystemClock_Config();
  8.   
  9.   /* Update the RIF config for the used peripherals */
  10.   RIMC_MasterConfig_t RIMC_master = {0};
  11.   RIMC_master.MasterCID = RIF_CID_1;
  12.   RIMC_master.SecPriv = RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV;
  13.   HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_DCMIPP, &RIMC_master);
  14.   HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_DMA2D, &RIMC_master);
  15.   HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_LTDC1 , &RIMC_master);
  16.   HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_LTDC2 , &RIMC_master);
  17.   HAL_RIF_RIMC_ConfigMasterAttributes(RIF_MASTER_INDEX_VENC  , &RIMC_master);
  18.   HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_DMA2D  , RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
  19.   HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_DCMIPP , RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
  20.   HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_CSI    , RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
  21.   HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_LTDC   , RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
  22.   HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_LTDCL1 , RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);
  23.   HAL_RIF_RISC_SetSlaveSecureAttributes(RIF_RISC_PERIPH_INDEX_LTDCL2 , RIF_ATTRIBUTE_SEC | RIF_ATTRIBUTE_PRIV);

  24.   BSP_LED_Init(LED_GREEN);
  25.   BSP_LED_Init(LED_RED);
  26.   
  27.   #if USE_COM_LOG
  28.   COM_InitTypeDef COM_Init;

  29.   /* Initialize COM init structure */
  30.   COM_Init.BaudRate   = 115200;
  31.   COM_Init.WordLength = COM_WORDLENGTH_8B;
  32.   COM_Init.StopBits   = COM_STOPBITS_1;
  33.   COM_Init.Parity     = COM_PARITY_NONE;
  34.   COM_Init.HwFlowCtl  = COM_HWCONTROL_NONE;

  35.   BSP_COM_Init(COM1, &COM_Init);

  36.   if (BSP_COM_SelectLogPort(COM1) != BSP_ERROR_NONE)
  37.   {
  38.     Error_Handler();
  39.   }
  40. #endif
  41.   
  42.   BSP_LCD_Init(0, LCD_ORIENTATION_LANDSCAPE);
  43.   UTIL_LCD_SetFuncDriver(&LCD_Driver);
  44.   UTIL_LCD_Clear(UTIL_LCD_COLOR_RED);
  45.   UTIL_LCD_SetTextColor(UTIL_LCD_COLOR_RED);
  46.   UTIL_LCD_SetBackColor(UTIL_LCD_COLOR_WHITE);
  47.   UTIL_LCD_SetFont(&Font24);
  48.   
  49.   while (1)
  50.   {
  51.     switch (i)
  52.     {
  53.       case 0:
  54.       {
  55.           UTIL_LCD_Clear(UTIL_LCD_COLOR_WHITE);
  56.           break;
  57.       }
  58.       case 1:
  59.       {
  60.           UTIL_LCD_Clear(UTIL_LCD_COLOR_RED);
  61.           break;
  62.       }
  63.       case 2:
  64.       {
  65.           UTIL_LCD_Clear(UTIL_LCD_COLOR_GREEN);
  66.           break;
  67.       }
  68.       case 3:
  69.       {
  70.           UTIL_LCD_Clear(UTIL_LCD_COLOR_BLUE);
  71.           break;
  72.       }
  73.       case 4:
  74.       {
  75.           UTIL_LCD_Clear(UTIL_LCD_COLOR_MAGENTA);
  76.           break;
  77.       }
  78.       case 5:
  79.       {
  80.           UTIL_LCD_Clear(UTIL_LCD_COLOR_YELLOW);
  81.           break;
  82.       }
  83.     }
  84.    
  85.     if(i==6)
  86.     {
  87.       i=0;
  88.     }
  89.     else
  90.     {
  91.       i++;
  92.     }
  93.     UTIL_LCD_DisplayStringAt(10, 50, (uint8_t *)"STM32N6570 BOARD LCD TEST!", LEFT_MODE);
  94.     BSP_LED_On(LED1);
  95.     HAL_Delay(500);
  96.     BSP_LED_Off(LED1);
  97.     HAL_Delay(500);
  98.   }
  99. }
复制代码




三、结果


下载程序到开发板,运行开发板屏幕显示如下:
lcd.gif




收藏 评论0 发布时间:2025-2-18 15:02

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版