/** ****************************************************************************** * File Name : LTDC.c * Description : This file provides code for the configuration * of the LTDC instances. ****************************************************************************** * This notice applies to any and all portions of this file * that are not between comment pairs USER CODE BEGIN and * USER CODE END. Other portions of this file, whether * inserted by the user or by software development tools * are owned by their respective copyright owners. * * Copyright (c) 2018 STMicroelectronics International N.V. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted, provided that the following conditions are met: * * 1. Redistribution of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of other * contributors to this software may be used to endorse or promote products * derived from this software without specific written permission. * 4. This software, including modifications and/or derivative works of this * software, must execute solely and exclusively on microcontroller or * microprocessor devices manufactured by or for STMicroelectronics. * 5. Redistribution and use of this software other than as permitted under * this license is void and will automatically terminate your rights under * this license. * * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "ltdc.h" #include "gpio.h" #include #include #include "arm_math.h" #include "stm32756g_eval_lcd.h" uint16_t LAYER_1[320*240] = {0}; uint16_t LAYER_2[320*240] = {0}; #define POLY_X(Z) ((int32_t)((Points + Z)->X)) #define POLY_Y(Z) ((int32_t)((Points + Z)->Y)) extern const uint16_t Font17_Table[]; static DMA2D_HandleTypeDef hDma2dHandler; static LCD_DrawPropTypeDef DrawProp[MAX_LAYER_NUMBER]; static uint32_t ActiveLayer = 1; volatile uint32_t RenderingLayer = 0; static void TransferComplete(DMA2D_HandleTypeDef *hdma2d); static void TransferError(DMA2D_HandleTypeDef *hdma2d); static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c); static void LCD_DrawRusChar(uint16_t Xpos, uint16_t Ypos, const uint16_t *c); //static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3); static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex); static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode); volatile uint32_t DMA2D_TransferOk = 1; volatile bool RefreshScreen = false; volatile bool RefreshNums = false; volatile uint32_t TimerRefreshLCD = 0; sFONT *CurrentFont; LTDC_HandleTypeDef hLtdcHandler; uint32_t RGB565_TO_RGB888(uint16_t rgb565) { uint32_t r8, g8, b8; uint32_t rgb888 = 0xff000000; r8 = (uint32_t) (((float32_t) R5(rgb565) * 8.22580645f) + 0.5f); g8 = (uint32_t) (((float32_t) G6(rgb565) * 4.047619f) + 0.5f); b8 = (uint32_t) (((float32_t) B5(rgb565) * 8.22580645f) + 0.5f); if(r8 > 255) r8 = 255; if(g8 > 255) g8 = 255; if(b8 > 255) b8 = 255; rgb888 |= ((r8 << 16) | (g8 << 8) | b8); return rgb888; } void LTDC_Reset(void) { HAL_GPIO_WritePin(RESET_GPIO_Port, RESET_Pin, GPIO_PIN_SET); HAL_Delay(100); HAL_GPIO_WritePin(RESET_GPIO_Port, RESET_Pin, GPIO_PIN_RESET); HAL_Delay(100); HAL_GPIO_WritePin(RESET_GPIO_Port, RESET_Pin, GPIO_PIN_SET); HAL_Delay(100); } /* LTDC init function */ void MX_LTDC_Init(void) { LTDC_LayerCfgTypeDef pLayerCfg; LTDC_LayerCfgTypeDef pLayerCfg1; __IO uint32_t tickstart; // SET_BIT(RCC->CR, RCC_CR_PLLSAION); // HAL_Delay(100); LTDC_Reset(); __HAL_RCC_PLLSAI_ENABLE(); tickstart = HAL_GetTick(); while(__HAL_RCC_PLLSAI_GET_FLAG() == RESET) { if((HAL_GetTick() - tickstart) >= PLLSAI_TIMEOUT_VALUE) { Error_Handler(); } } hLtdcHandler.Instance = LTDC; hLtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL; hLtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL; hLtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AH; hLtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC; hLtdcHandler.Init.HorizontalSync = 38; hLtdcHandler.Init.VerticalSync = 4; hLtdcHandler.Init.AccumulatedHBP = 68; hLtdcHandler.Init.AccumulatedVBP = 18; hLtdcHandler.Init.AccumulatedActiveW = 388; hLtdcHandler.Init.AccumulatedActiveH = 262; hLtdcHandler.Init.TotalWidth = 408; hLtdcHandler.Init.TotalHeigh = 263; hLtdcHandler.Init.Backcolor.Blue = 0; hLtdcHandler.Init.Backcolor.Green = 0; hLtdcHandler.Init.Backcolor.Red = 0; if (HAL_LTDC_Init(&hLtdcHandler) != HAL_OK) { Error_Handler(); } pLayerCfg.WindowX0 = 0; pLayerCfg.WindowX1 = 320; pLayerCfg.WindowY0 = 0; pLayerCfg.WindowY1 = 240; pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; pLayerCfg.Alpha = 255; pLayerCfg.Alpha0 = 0; pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; pLayerCfg.FBStartAdress = (uint32_t) &LAYER_1[0]; pLayerCfg.ImageWidth = 320; pLayerCfg.ImageHeight = 240; pLayerCfg.Backcolor.Blue = 0; pLayerCfg.Backcolor.Green = 0; pLayerCfg.Backcolor.Red = 0; if(HAL_LTDC_ConfigLayer(&hLtdcHandler, &pLayerCfg, 0) != HAL_OK) { Error_Handler(); } pLayerCfg1.WindowX0 = 0; pLayerCfg1.WindowX1 = 320; pLayerCfg1.WindowY0 = 0; pLayerCfg1.WindowY1 = 240; pLayerCfg1.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; pLayerCfg1.Alpha = 255; pLayerCfg1.Alpha0 = 0; pLayerCfg1.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; pLayerCfg1.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; pLayerCfg1.FBStartAdress = (uint32_t) &LAYER_2[0]; pLayerCfg1.ImageWidth = 320; pLayerCfg1.ImageHeight = 240; pLayerCfg1.Backcolor.Blue = 0; pLayerCfg1.Backcolor.Green = 0; pLayerCfg1.Backcolor.Red = 0; if(HAL_LTDC_ConfigLayer(&hLtdcHandler, &pLayerCfg1, 1) != HAL_OK) { Error_Handler(); } //HAL_LTDC_EnableCLUT(&hLtdcHandler, 0); //HAL_LTDC_EnableCLUT(&hLtdcHandler, 1); ActiveLayer = 1; RenderingLayer = 0; BSP_LCD_DisplayOff(); BSP_LCD_SelectLayer(0); BSP_LCD_Clear(0xFF000000); BSP_LCD_SelectLayer(1); BSP_LCD_Clear(0xFF000000); BSP_LCD_SetLayerVisible(RenderingLayer, DISABLE); BSP_LCD_SetLayerVisible(ActiveLayer, DISABLE); HAL_LTDC_Reload(&hLtdcHandler, LTDC_RELOAD_IMMEDIATE); DrawProp[0].BackColor = LCD_COLOR_BLACK; DrawProp[0].pFont = &Font17; DrawProp[0].TextColor = LCD_COLOR_WHITE; DrawProp[1].BackColor = LCD_COLOR_BLACK; DrawProp[1].pFont = &Font17; DrawProp[1].TextColor = LCD_COLOR_WHITE; CurrentFont = &Font17; BSP_LCD_DisplayOn(); HAL_GPIO_WritePin(DISP_ON_GPIO_Port, DISP_ON_Pin, GPIO_PIN_SET); // BACKLIGHT IS OFF RefreshScreen = true; HAL_LTDC_ProgramLineEvent(&hLtdcHandler, 255); while(RefreshScreen); BSP_LCD_SetLayerVisible(RenderingLayer, ENABLE); } void BSP_LCD_DisplayOn(void) { //__HAL_LTDC_ENABLE(&hLtdcHandler); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_SET); // DISPLAY_ON } /** * @brief Disables the display. * @retval None */ void BSP_LCD_DisplayOff(void) { //__HAL_LTDC_DISABLE(&hLtdcHandler); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_10, GPIO_PIN_RESET); // DISPLAY_OFF } void HAL_LTDC_MspInit(LTDC_HandleTypeDef* ltdcHandle) { GPIO_InitTypeDef GPIO_InitStruct; if(ltdcHandle->Instance == LTDC) { __HAL_RCC_LTDC_CLK_ENABLE(); /* LTDC GPIO Configuration PA3 ------> LTDC_B5 PA4 ------> LTDC_VSYNC PA6 ------> LTDC_G2 PA11 ------> LTDC_R4 PA12 ------> LTDC_R5 PB0 ------> LTDC_R3 PB1 ------> LTDC_R6 PB8 ------> LTDC_B6 PB9 ------> LTDC_B7 PB10 ------> LTDC_G4 PB11 ------> LTDC_G5 PC6 ------> LTDC_HSYNC PC7 ------> LTDC_G6 PD3 ------> LTDC_G7 PF10 ------> LTDC_DE PG6 ------> LTDC_R7 PG7 ------> LTDC_CLK PG10 ------> LTDC_G3 PG11 ------> LTDC_B3 PG12 ------> LTDC_B4 */ GPIO_InitStruct.Pin = GPIO_PIN_10; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_6 | GPIO_PIN_11 |GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF9_LTDC; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_8 | GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_11; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF9_LTDC; HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); HAL_NVIC_SetPriority(LTDC_IRQn, 6, 0); HAL_NVIC_EnableIRQ(LTDC_IRQn); } } void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef* ltdcHandle) { if(ltdcHandle->Instance==LTDC) { __HAL_RCC_LTDC_CLK_DISABLE(); HAL_GPIO_DeInit(GPIOF, GPIO_PIN_10); HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_6|GPIO_PIN_11|GPIO_PIN_12); HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_8|GPIO_PIN_9); HAL_GPIO_DeInit(GPIOG, GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); HAL_GPIO_DeInit(GPIOC, GPIO_PIN_6|GPIO_PIN_7); HAL_GPIO_DeInit(GPIOD, GPIO_PIN_3); HAL_NVIC_DisableIRQ(LTDC_IRQn); } } uint32_t BSP_LCD_GetXSize(void) { return hLtdcHandler.LayerCfg[ActiveLayer].ImageWidth; } /** * @brief Gets the LCD Y size. * @retval Used LCD Y size */ uint32_t BSP_LCD_GetYSize(void) { return hLtdcHandler.LayerCfg[ActiveLayer].ImageHeight; } /** * @brief Set the LCD X size. * @param imageWidthPixels : image width in pixels unit * @retval None */ void BSP_LCD_SetXSize(uint32_t imageWidthPixels) { hLtdcHandler.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels; } /** * @brief Set the LCD Y size. * @param imageHeightPixels : image height in lines unit * @retval None */ void BSP_LCD_SetYSize(uint32_t imageHeightPixels) { hLtdcHandler.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels; } void BSP_LCD_SelectLayer(uint32_t LayerIndex) { ActiveLayer = LayerIndex; } /** * @brief Sets an LCD Layer visible * @param LayerIndex: Visible Layer * @param State: New state of the specified layer * This parameter can be one of the following values: * @arg ENABLE * @arg DISABLE * @retval None */ void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State) { if(State == ENABLE) __HAL_LTDC_LAYER_ENABLE(&hLtdcHandler, LayerIndex); else __HAL_LTDC_LAYER_DISABLE(&hLtdcHandler, LayerIndex); __HAL_LTDC_RELOAD_CONFIG(&hLtdcHandler); } /** * @brief Sets an LCD Layer visible without reloading. * @param LayerIndex: Visible Layer * @param State: New state of the specified layer * This parameter can be one of the following values: * @arg ENABLE * @arg DISABLE * @retval None */ void BSP_LCD_SetLayerVisible_NoReload(uint32_t LayerIndex, FunctionalState State) { if(State == ENABLE) __HAL_LTDC_LAYER_ENABLE(&hLtdcHandler, LayerIndex); else __HAL_LTDC_LAYER_DISABLE(&hLtdcHandler, LayerIndex); } /** * @brief Configures the transparency. * @param LayerIndex: Layer foreground or background. * @param Transparency: Transparency * This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF * @retval None */ void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency) { HAL_LTDC_SetAlpha(&hLtdcHandler, Transparency, LayerIndex); } /** * @brief Configures the transparency without reloading. * @param LayerIndex: Layer foreground or background. * @param Transparency: Transparency * This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF * @retval None */ void BSP_LCD_SetTransparency_NoReload(uint32_t LayerIndex, uint8_t Transparency) { HAL_LTDC_SetAlpha_NoReload(&hLtdcHandler, Transparency, LayerIndex); } /** * @brief Sets an LCD layer frame buffer address. * @param LayerIndex: Layer foreground or background * @param Address: New LCD frame buffer value * @retval None */ void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address) { HAL_LTDC_SetAddress(&hLtdcHandler, Address, LayerIndex); } /** * @brief Sets an LCD layer frame buffer address without reloading. * @param LayerIndex: Layer foreground or background * @param Address: New LCD frame buffer value * @retval None */ void BSP_LCD_SetLayerAddress_NoReload(uint32_t LayerIndex, uint32_t Address) { HAL_LTDC_SetAddress_NoReload(&hLtdcHandler, Address, LayerIndex); } /** * @brief Sets display window. * @param LayerIndex: Layer index * @param Xpos: LCD X position * @param Ypos: LCD Y position * @param Width: LCD window width * @param Height: LCD window height * @retval None */ void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) { HAL_LTDC_SetWindowSize(&hLtdcHandler, Width, Height, LayerIndex);/* Reconfigure the layer size */ HAL_LTDC_SetWindowPosition(&hLtdcHandler, Xpos, Ypos, LayerIndex);/* Reconfigure the layer position */ } /** * @brief Sets display window without reloading. * @param LayerIndex: Layer index * @param Xpos: LCD X position * @param Ypos: LCD Y position * @param Width: LCD window width * @param Height: LCD window height * @retval None */ void BSP_LCD_SetLayerWindow_NoReload(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) { HAL_LTDC_SetWindowSize_NoReload(&hLtdcHandler, Width, Height, LayerIndex);/* Reconfigure the layer size */ HAL_LTDC_SetWindowPosition_NoReload(&hLtdcHandler, Xpos, Ypos, LayerIndex); /* Reconfigure the layer position */ } /** * @brief Configures and sets the color keying. * @param LayerIndex: Layer foreground or background * @param RGBValue: Color reference * @retval None */ void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue) { /* Configure and Enable the color Keying for LCD Layer */ HAL_LTDC_ConfigColorKeying(&hLtdcHandler, RGBValue, LayerIndex); HAL_LTDC_EnableColorKeying(&hLtdcHandler, LayerIndex); } /** * @brief Configures and sets the color keying without reloading. * @param LayerIndex: Layer foreground or background * @param RGBValue: Color reference * @retval None */ void BSP_LCD_SetColorKeying_NoReload(uint32_t LayerIndex, uint32_t RGBValue) { /* Configure and Enable the color Keying for LCD Layer */ HAL_LTDC_ConfigColorKeying_NoReload(&hLtdcHandler, RGBValue, LayerIndex); HAL_LTDC_EnableColorKeying_NoReload(&hLtdcHandler, LayerIndex); } /** * @brief Disables the color keying. * @param LayerIndex: Layer foreground or background * @retval None */ void BSP_LCD_ResetColorKeying(uint32_t LayerIndex) { /* Disable the color Keying for LCD Layer */ HAL_LTDC_DisableColorKeying(&hLtdcHandler, LayerIndex); } /** * @brief Disables the color keying without reloading. * @param LayerIndex: Layer foreground or background * @retval None */ void BSP_LCD_ResetColorKeying_NoReload(uint32_t LayerIndex) { /* Disable the color Keying for LCD Layer */ HAL_LTDC_DisableColorKeying_NoReload(&hLtdcHandler, LayerIndex); } /** BSP_LCD_Reload(LCD_RELOAD_VERTICAL_BLANKING); * @brief Disables the color keying without reloading. * @param ReloadType: can be one of the following values * - LCD_RELOAD_IMMEDIATE * - LCD_RELOAD_VERTICAL_BLANKING * @retval None */ void BSP_LCD_Reload(uint32_t ReloadType) { HAL_LTDC_Reload (&hLtdcHandler, ReloadType); } /** * @brief Sets the LCD text color. * @param Color: Text color code ARGB(8-8-8-8) * @retval None */ void LCD_SetColors(uint32_t ColorUp, uint32_t ColorDn) { DrawProp[ActiveLayer].TextColor = ColorUp; DrawProp[ActiveLayer].BackColor = ColorDn; } void BSP_LCD_SetTextColor(uint32_t Color) { DrawProp[ActiveLayer].TextColor = Color; } /** * @brief Gets the LCD text color. * @retval Used text color. */ uint32_t BSP_LCD_GetTextColor(void) { return DrawProp[ActiveLayer].TextColor; } /** * @brief Sets the LCD background color. * @param Color: Layer background color code ARGB(8-8-8-8) * @retval None */ void BSP_LCD_SetBackColor(uint32_t Color) { DrawProp[ActiveLayer].BackColor = Color; } /** * @brief Gets the LCD background color. * @retval Used background colour */ uint32_t BSP_LCD_GetBackColor(void) { return DrawProp[ActiveLayer].BackColor; } /** * @brief Sets the LCD text font. * @param fonts: Layer font to be used * @retval None */ void BSP_LCD_SetFont(sFONT *fonts) { DrawProp[ActiveLayer].pFont = fonts; CurrentFont = fonts; } /** * @brief Gets the LCD text font. * @retval Used layer font */ sFONT *BSP_LCD_GetFont(void) { return DrawProp[ActiveLayer].pFont; } /** * @brief Reads an LCD pixel. * @param Xpos: X position * @param Ypos: Y position * @retval RGB pixel color */ uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos) { uint32_t ret = 0; if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888) { /* Read data value from SDRAM memory */ ret = *(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))); } else if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888) { /* Read data value from SDRAM memory */ ret = (*(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF); } else if((hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \ (hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \ (hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88)) { /* Read data value from SDRAM memory */ ret = *(__IO uint16_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); } else { /* Read data value from SDRAM memory */ ret = *(__IO uint8_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); } return ret; } /** * @brief Clears the hole LCD. * @param Color: Color of the background * @retval None */ void BSP_LCD_Clear(uint32_t Color) { LL_FillBuffer(ActiveLayer, (uint32_t *)(hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color); } /** * @brief Clears the selected line. * @param Line: Line to be cleared * @retval None */ void BSP_LCD_ClearStringLine(uint32_t Line) { uint32_t color_backup = DrawProp[ActiveLayer].TextColor; DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor; /* Draw rectangle with background color */ BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height); DrawProp[ActiveLayer].TextColor = color_backup; BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); } /** * @brief Displays one character. * @param Xpos: Start column address * @param Ypos: Line where to display the character shape. * @param Ascii: Character ascii code * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E * @retval None */ void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii) { DrawChar( Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii - ' ') * DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)] ); } /** * @brief Displays characters on the LCD. * @param Xpos: X position (in pixel) * @param Ypos: Y position (in pixel) * @param Text: Pointer to string to display on LCD * @param Mode: Display mode * This parameter can be one of the following values: * @arg CENTER_MODE * @arg RIGHT_MODE * @arg LEFT_MODE * @retval None */ void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, char *Text, Text_AlignModeTypdef Mode) { uint16_t ref_column = 1, i = 0, ll = 0; uint32_t size = 0; uint8_t *ptr; ptr = (uint8_t *) Text; /* Get the text size */ while (*ptr++) size++ ; /* Characters number per line */ // xsize = (BSP_LCD_GetXSize() / DrawProp[ActiveLayer].pFont->Width); switch (Mode) { case CENTER_MODE: { ll = DrawProp[ActiveLayer].pFont->Width * size; ref_column = Xpos - (ll >> 1); //if((ref_column + ll > 319) || (ref_column > 319)) // ref_column = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2; break; } case LEFT_MODE: { ref_column = Xpos; break; } case RIGHT_MODE: { ll = DrawProp[ActiveLayer].pFont->Width * size; ref_column = Xpos - ll; // ref_column = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width); break; } default: { ref_column = Xpos; break; } } /* Check that the Start column is located in the screen */ if ((ref_column < 1) || (ref_column >= 0x8000)) { ref_column = 1; } /* Send the string character by character on LCD */ while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width)) { /* Display one character on LCD */ BSP_LCD_DisplayChar(ref_column, Ypos, *Text); /* Decrement the column position by 16 */ ref_column += DrawProp[ActiveLayer].pFont->Width; /* Point on the next character */ Text++; i++; } } /** * @brief Displays a maximum of 60 characters on the LCD. * @param Line: Line where to display the character shape * @param ptr: Pointer to string to display on LCD * @retval None */ void BSP_LCD_DisplayStringAtLine(uint16_t Line, char *ptr) { BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE); } /** * @brief Draws an horizontal line. * @param Xpos: X position * @param Ypos: Y position * @param Length: Line length * @retval None */ void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint32_t Xaddress = 0; /* Get the line address */ if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) { /* RGB565 format */ Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos); } else { /* ARGB8888 format */ Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); } /* Write line */ LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor); } /** * @brief Draws a vertical line. * @param Xpos: X position * @param Ypos: Y position * @param Length: Line length * @retval None */ void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint32_t Xaddress = 0; /* Get the line address */ if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) { /* RGB565 format */ Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos); } else { /* ARGB8888 format */ Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); } /* Write line */ LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor); } void BSP_LCD_DrawVLineThick(uint16_t Xpos, uint16_t Ypos, uint16_t Length, uint16_t Thick) { uint32_t Xaddress = 0; uint32_t thickness = (uint32_t) Thick; uint32_t lx = 0, rx = 0; uint32_t x = (uint32_t) Xpos; uint32_t dx = (uint32_t) Thick; if(thickness == 0) thickness = 1; if(thickness > 2) { lx = rx = thickness >> 1; // rx = thickness - lx - 1; if(lx > x) lx = x; if((x + rx) >= 320) rx = 319 - x; dx = ((x + rx) - (x - lx)) + 1; x -= lx; } /* Get the line address */ if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) { /* RGB565 format */ Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + x); } else { /* ARGB8888 format */ Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + x); } /* Write line */ LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, dx, Length, /*(BSP_LCD_GetXSize() - 1)*/x + rx, DrawProp[ActiveLayer].TextColor); } /** * @brief Draws an uni-line (between two points). * @param x1: Point 1 X position * @param y1: Point 1 Y position * @param x2: Point 2 X position * @param y2: Point 2 Y position * @retval None */ void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0, curpixel = 0; deltax = ABS(x2 - x1); /* The difference between the x's */ deltay = ABS(y2 - y1); /* The difference between the y's */ x = x1; /* Start x off at the first pixel */ y = y1; /* Start y off at the first pixel */ if (x2 >= x1) /* The x-values are increasing */ { xinc1 = 1; xinc2 = 1; } else /* The x-values are decreasing */ { xinc1 = -1; xinc2 = -1; } if (y2 >= y1) /* The y-values are increasing */ { yinc1 = 1; yinc2 = 1; } else /* The y-values are decreasing */ { yinc1 = -1; yinc2 = -1; } if (deltax >= deltay) /* There is at least one x-value for every y-value */ { xinc1 = 0; /* Don't change the x when numerator >= denominator */ yinc2 = 0; /* Don't change the y for every iteration */ den = deltax; num = deltax / 2; num_add = deltay; num_pixels = deltax; /* There are more x-values than y-values */ } else /* There is at least one y-value for every x-value */ { xinc2 = 0; /* Don't change the x for every iteration */ yinc1 = 0; /* Don't change the y when numerator >= denominator */ den = deltay; num = deltay / 2; num_add = deltax; num_pixels = deltay; /* There are more y-values than x-values */ } for (curpixel = 0; curpixel <= num_pixels; curpixel++) { BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor); /* Draw the current pixel */ num += num_add; /* Increase the numerator by the top of the fraction */ if (num >= den) /* Check if numerator >= denominator */ { num -= den; /* Calculate the new numerator value */ x += xinc1; /* Change the x as appropriate */ y += yinc1; /* Change the y as appropriate */ } x += xinc2; /* Change the x as appropriate */ y += yinc2; /* Change the y as appropriate */ } } /** * @brief Draws a rectangle. * @param Xpos: X position * @param Ypos: Y position * @param Width: Rectangle width * @param Height: Rectangle height * @retval None */ void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) { BSP_LCD_DrawHLine(Xpos, Ypos, Width); BSP_LCD_DrawVLine(Xpos, Ypos, Height); BSP_LCD_DrawHLine(Xpos, (Ypos + Height), Width); BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height + 1); } /** * @brief Draws a circle. * @param Xpos: X position * @param Ypos: Y position * @param Radius: Circle radius * @retval None */ void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) { int32_t decision; /* Decision Variable */ uint32_t current_x; /* Current X Value */ uint32_t current_y; /* Current Y Value */ decision = 3 - (Radius << 1); current_x = 0; current_y = Radius; while (current_x <= current_y) { BSP_LCD_DrawPixel((Xpos + current_x), (Ypos - current_y), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos - current_x), (Ypos - current_y), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos + current_y), (Ypos - current_x), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos - current_y), (Ypos - current_x), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos + current_x), (Ypos + current_y), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos - current_x), (Ypos + current_y), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos + current_y), (Ypos + current_x), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos - current_y), (Ypos + current_x), DrawProp[ActiveLayer].TextColor); if (decision < 0) { decision += (current_x << 2) + 6; } else { decision += ((current_x - current_y) << 2) + 10; current_y--; } current_x++; } } /** * @brief Draws an poly-line (between many points). * @param Points: Pointer to the points array * @param PointCount: Number of points * @retval None */ void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount) { int16_t x = 0, y = 0; if(PointCount < 2) { return; } BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); while(--PointCount) { x = Points->X; y = Points->Y; Points++; BSP_LCD_DrawLine(x, y, Points->X, Points->Y); } } /** * @brief Draws an ellipse on LCD. * @param Xpos: X position * @param Ypos: Y position * @param XRadius: Ellipse X radius * @param YRadius: Ellipse Y radius * @retval None */ void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius) { int x = 0, y = -YRadius, err = 2-2*XRadius, e2; float k = 0, rad1 = 0, rad2 = 0; rad1 = XRadius; rad2 = YRadius; k = (float)(rad2/rad1); do { BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor); e2 = err; if (e2 <= x) { err += ++x*2+1; if (-y == x && e2 <= y) e2 = 0; } if (e2 > y) err += ++y*2+1; } while (y <= 0); } /** * @brief Draws a pixel on LCD. * @param Xpos: X position * @param Ypos: Y position * @param RGB_Code: Pixel color in ARGB mode (8-8-8-8) * @retval None */ void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code) { /* Write data value to all SDRAM memory */ if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) { /* RGB565 format */ *(__IO uint16_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))) = COLOR24TO16(RGB_Code); } else { /* ARGB8888 format */ *(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code; } } /** * @brief Draws a bitmap picture loaded in the internal Flash in ARGB888 format (32 bits per pixel). * @param Xpos: Bmp X position in the LCD * @param Ypos: Bmp Y position in the LCD * @param pbmp: Pointer to Bmp picture address in the internal Flash * @retval None */ void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp) { uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; uint32_t address; uint32_t input_color_mode = 0; /* Get bitmap data address offset */ index = pbmp[10] + (pbmp[11] << 8) + (pbmp[12] << 16) + (pbmp[13] << 24); /* Read bitmap width */ width = pbmp[18] + (pbmp[19] << 8) + (pbmp[20] << 16) + (pbmp[21] << 24); /* Read bitmap height */ height = pbmp[22] + (pbmp[23] << 8) + (pbmp[24] << 16) + (pbmp[25] << 24); /* Read bit/pixel */ bit_pixel = pbmp[28] + (pbmp[29] << 8); /* Set the address */ address = hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4)); /* Get the layer pixel format */ if ((bit_pixel/8) == 4) { input_color_mode = CM_ARGB8888; } else if ((bit_pixel/8) == 2) { input_color_mode = CM_RGB565; } else { input_color_mode = CM_RGB888; } /* Bypass the bitmap header */ pbmp += (index + (width * (height - 1) * (bit_pixel/8))); /* Convert picture to ARGB8888 pixel format */ for(index=0; index < height; index++) { /* Pixel format conversion */ LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)address, width, input_color_mode); /* Increment the source and destination buffers */ address+= (BSP_LCD_GetXSize()*4); pbmp -= width*(bit_pixel/8); } } /** * @brief Draws a full rectangle. * @param Xpos: X position * @param Ypos: Y position * @param Width: Rectangle width * @param Height: Rectangle height * @retval None */ void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) { uint32_t x_address = 0; /* Set the text color */ BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); /* Get the rectangle start address */ if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) { /* RGB565 format */ x_address = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos); } else { /* ARGB8888 format */ x_address = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); } /* Fill the rectangle */ LL_FillBuffer(ActiveLayer, (uint32_t *)x_address, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor); } /** * @brief Draws a full circle. * @param Xpos: X position * @param Ypos: Y position * @param Radius: Circle radius * @retval None */ void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) { int32_t decision; /* Decision Variable */ uint32_t current_x; /* Current X Value */ uint32_t current_y; /* Current Y Value */ decision = 3 - (Radius << 1); current_x = 0; current_y = Radius; BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); while (current_x <= current_y) { if(current_y > 0) { BSP_LCD_DrawHLine(Xpos - current_y, Ypos + current_x, 2*current_y); BSP_LCD_DrawHLine(Xpos - current_y, Ypos - current_x, 2*current_y); } if(current_x > 0) { BSP_LCD_DrawHLine(Xpos - current_x, Ypos - current_y, 2*current_x); BSP_LCD_DrawHLine(Xpos - current_x, Ypos + current_y, 2*current_x); } if (decision < 0) { decision += (current_x << 2) + 6; } else { decision += ((current_x - current_y) << 2) + 10; current_y--; } current_x++; } BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); BSP_LCD_DrawCircle(Xpos, Ypos, Radius); } /** * @brief Draws a full poly-line (between many points). * @param Points: Pointer to the points array * @param PointCount: Number of points * @retval None */ void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount) { int16_t X = 0, Y = 0, X2 = 0, Y2 = 0, X_center = 0, Y_center = 0, X_first = 0, Y_first = 0, pixelX = 0, pixelY = 0, counter = 0; uint16_t image_left = 0, image_right = 0, image_top = 0, image_bottom = 0; image_left = image_right = Points->X; image_top= image_bottom = Points->Y; for(counter = 1; counter < PointCount; counter++) { pixelX = POLY_X(counter); if(pixelX < image_left) { image_left = pixelX; } if(pixelX > image_right) { image_right = pixelX; } pixelY = POLY_Y(counter); if(pixelY < image_top) { image_top = pixelY; } if(pixelY > image_bottom) { image_bottom = pixelY; } } if(PointCount < 2) { return; } X_center = (image_left + image_right)/2; Y_center = (image_bottom + image_top)/2; X_first = Points->X; Y_first = Points->Y; while(--PointCount) { X = Points->X; Y = Points->Y; Points++; X2 = Points->X; Y2 = Points->Y; FillTriangle(X, X2, X_center, Y, Y2, Y_center); FillTriangle(X, X_center, X2, Y, Y_center, Y2); FillTriangle(X_center, X2, X, Y_center, Y2, Y); } FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center); FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2); FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first); } /** * @brief Draws a full ellipse. * @param Xpos: X position * @param Ypos: Y position * @param XRadius: Ellipse X radius * @param YRadius: Ellipse Y radius * @retval None */ void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius) { int x = 0, y = -YRadius, err = 2-2*XRadius, e2; float k = 0, rad1 = 0, rad2 = 0; rad1 = XRadius; rad2 = YRadius; k = (float)(rad2/rad1); do { BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos+y), (2*(uint16_t)(x/k) + 1)); BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos-y), (2*(uint16_t)(x/k) + 1)); e2 = err; if (e2 <= x) { err += ++x*2+1; if (-y == x && e2 <= y) e2 = 0; } if (e2 > y) err += ++y*2+1; } while (y <= 0); } void LCD_DisplayString(uint16_t X, uint16_t Line, char *ptr) { BSP_LCD_SetFont(&Font15); BSP_LCD_DisplayStringAt(X, Line, ptr, LEFT_MODE); /*uint16_t refcolumn = 320 - X - 1; while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= 12)) { LCD_DisplayChar(Line, refcolumn, *ptr); refcolumn -= 12; ptr++; }*/ } void LCD_DisplayStringC(uint16_t X, uint16_t Y, char *ptr) { BSP_LCD_SetFont(&Font15); BSP_LCD_DisplayStringAt(X, Y, ptr, CENTER_MODE); /*uint16_t refcolumn; uint32_t len = 0; len = strlen(ptr); refcolumn = 320 - (X - ((len*12) >> 1)) - 1; while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= 12)) { LCD_DisplayChar(Y, refcolumn, *ptr); refcolumn -= 12; ptr++; }*/ } void LCD_DisplayStringR(uint16_t X, uint16_t Y, char *ptr) { BSP_LCD_SetFont(&Font15); BSP_LCD_DisplayStringAt(X, Y, ptr, RIGHT_MODE); /*uint16_t refcolumn; uint32_t len = 0; len = strlen(ptr); refcolumn = 320 - (X - len*12) - 1; while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= 12)) { LCD_DisplayChar(Y, refcolumn, *ptr); refcolumn -= 12; ptr++; }*/ } /******************************************************************************* Static Functions *******************************************************************************/ void LCD_DisplayChar(uint16_t Line, uint16_t Column, uint8_t Ascii) { Ascii -= 32; LCD_DrawRusChar(Line, Column, &Font17_Table[Ascii * 17]); } /* void LCD_DisplayChar(uint16_t Column, uint16_t Line, uint8_t Ascii) { Ascii -= 32; LCD_DrawRusChar(Column, Line, &Font17_Table[Ascii * 17]); } */ static void LCD_DrawRusChar(uint16_t Xpos, uint16_t Ypos, const uint16_t *c) { uint32_t index = 0, counter = 0, xpos = 0; uint32_t Xaddress = 0; uint16_t chr, b; xpos = Xpos * (320 << 1); Xaddress += (320 - Ypos - 1); for(index = 0; index < 17; index++) { chr = SWAP_BITS(c[index]); for(counter = 0; counter < 12; counter++) { b = 1 << counter; if(!(chr & b)) *(__IO uint16_t *) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (Xaddress << 1) + xpos) = COLOR24TO16(DrawProp[ActiveLayer].BackColor); else *(__IO uint16_t *) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (Xaddress << 1) + xpos) = COLOR24TO16(DrawProp[ActiveLayer].TextColor); Xaddress++; } Xaddress += (320 - 12); } } /** * @brief Draws a character on LCD. * @param Xpos: Line where to display the character shape * @param Ypos: Start column address * @param c: Pointer to the character data * @retval None */ static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c) { uint32_t i = 0, j = 0; uint16_t height, width; uint8_t offset; uint8_t *pchar; uint32_t line; //uint16_t b; height = DrawProp[ActiveLayer].pFont->Height; width = DrawProp[ActiveLayer].pFont->Width; offset = 8 *((width + 7)/8) - width ; for(i = 0; i < height; i++) { pchar = ((uint8_t *)c + (width + 7)/8 * i); switch(((width + 7)/8)) { case 1: line = pchar[0]; break; case 2: line = (pchar[0]<< 8) | pchar[1]; break; case 3: default: line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; break; } for (j = 0; j < width; j++) { if(line & (1 << (width- j + offset- 1))) { BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor); } else { BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor); } } Ypos++; } } uint16_t SWAP_BITS(uint16_t a) { uint16_t i, j, out = 0; for(i = 0, j = 15; i < 16; i++, j--) if(a & (1 << i)) out |= (1 << j); return out; } /** * @brief Fills a triangle (between 3 points). * @param x1: Point 1 X position * @param y1: Point 1 Y position * @param x2: Point 2 X position * @param y2: Point 2 Y position * @param x3: Point 3 X position * @param y3: Point 3 Y position * @retval None */ void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3) { int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0, curpixel = 0; deltax = ABS(x2 - x1); /* The difference between the x's */ deltay = ABS(y2 - y1); /* The difference between the y's */ x = x1; /* Start x off at the first pixel */ y = y1; /* Start y off at the first pixel */ if (x2 >= x1) /* The x-values are increasing */ { xinc1 = 1; xinc2 = 1; } else /* The x-values are decreasing */ { xinc1 = -1; xinc2 = -1; } if (y2 >= y1) /* The y-values are increasing */ { yinc1 = 1; yinc2 = 1; } else /* The y-values are decreasing */ { yinc1 = -1; yinc2 = -1; } if (deltax >= deltay) /* There is at least one x-value for every y-value */ { xinc1 = 0; /* Don't change the x when numerator >= denominator */ yinc2 = 0; /* Don't change the y for every iteration */ den = deltax; num = deltax / 2; num_add = deltay; num_pixels = deltax; /* There are more x-values than y-values */ } else /* There is at least one y-value for every x-value */ { xinc2 = 0; /* Don't change the x for every iteration */ yinc1 = 0; /* Don't change the y when numerator >= denominator */ den = deltay; num = deltay / 2; num_add = deltax; num_pixels = deltay; /* There are more y-values than x-values */ } for (curpixel = 0; curpixel <= num_pixels; curpixel++) { BSP_LCD_DrawLine(x, y, x3, y3); num += num_add; /* Increase the numerator by the top of the fraction */ if (num >= den) /* Check if numerator >= denominator */ { num -= den; /* Calculate the new numerator value */ x += xinc1; /* Change the x as appropriate */ y += yinc1; /* Change the y as appropriate */ } x += xinc2; /* Change the x as appropriate */ y += yinc2; /* Change the y as appropriate */ } } /** * @brief Fills a buffer. * @param LayerIndex: Layer index * @param pDst: Pointer to destination buffer * @param xSize: Buffer width * @param ySize: Buffer height * @param OffLine: Offset * @param ColorIndex: Color index * @retval None */ static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex) { /* Register to memory mode with ARGB8888 as color Mode */ hDma2dHandler.Init.Mode = DMA2D_R2M; if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) hDma2dHandler.Init.ColorMode = DMA2D_RGB565; else hDma2dHandler.Init.ColorMode = DMA2D_ARGB8888; hDma2dHandler.Init.OutputOffset = OffLine; hDma2dHandler.Instance = DMA2D; if(HAL_DMA2D_Init(&hDma2dHandler) == HAL_OK) { if(HAL_DMA2D_ConfigLayer(&hDma2dHandler, LayerIndex) == HAL_OK) { if (HAL_DMA2D_Start(&hDma2dHandler, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK) { HAL_DMA2D_PollForTransfer(&hDma2dHandler, 30); } } } } /** * @brief Converts a line to an ARGB8888 pixel format. * @param pSrc: Pointer to source buffer * @param pDst: Output color * @param xSize: Buffer width * @param ColorMode: Input color mode * @retval None */ static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode) { /* Configure the DMA2D Mode, Color Mode and output offset */ hDma2dHandler.Init.Mode = DMA2D_M2M_PFC; hDma2dHandler.Init.ColorMode = DMA2D_ARGB8888; hDma2dHandler.Init.OutputOffset = 0; /* Foreground Configuration */ hDma2dHandler.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hDma2dHandler.LayerCfg[1].InputAlpha = 0xFF; hDma2dHandler.LayerCfg[1].InputColorMode = ColorMode; hDma2dHandler.LayerCfg[1].InputOffset = 0; hDma2dHandler.Instance = DMA2D; /* DMA2D Initialization */ if(HAL_DMA2D_Init(&hDma2dHandler) == HAL_OK) { if(HAL_DMA2D_ConfigLayer(&hDma2dHandler, 1) == HAL_OK) { if (HAL_DMA2D_Start(&hDma2dHandler, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK) { /* Polling For DMA transfer */ HAL_DMA2D_PollForTransfer(&hDma2dHandler, 30); } } } } void DrawImage(const GUI_BITMAP * pBM, uint16_t x0, uint16_t y0) { //HAL_StatusTypeDef hal_status = HAL_OK; uint32_t Xaddress = 0; uint8_t * p; uint16_t xSize = pBM->XSize; uint16_t ySize = pBM->YSize; //uint16_t BytesPerLine = pBM->BytesPerLine; p = (uint8_t *) pBM->pData; Xaddress = hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + ((320 * y0 + x0) << 1); hDma2dHandler.Init.Mode = DMA2D_M2M; hDma2dHandler.Init.ColorMode = DMA2D_RGB565; hDma2dHandler.Init.OutputOffset = 320 - xSize; /* DMA2D Callbacks Configuration */ hDma2dHandler.XferCpltCallback = TransferComplete; hDma2dHandler.XferErrorCallback = TransferError; /* Foreground layer Configuration : layer 1 */ hDma2dHandler.LayerCfg[ActiveLayer].AlphaMode = DMA2D_NO_MODIF_ALPHA; hDma2dHandler.LayerCfg[ActiveLayer].InputAlpha = 255; /* Alpha fully opaque */ hDma2dHandler.LayerCfg[ActiveLayer].InputColorMode = DMA2D_INPUT_RGB565; /* Layer 1 input format is ARGB8888 (32 bpp) */ hDma2dHandler.LayerCfg[ActiveLayer].InputOffset = 0; /* No offset in input */ hDma2dHandler.Instance = DMA2D; /* DMA2D Initialization */ HAL_DMA2D_Init(&hDma2dHandler); HAL_DMA2D_ConfigLayer(&hDma2dHandler, ActiveLayer); DMA2D_TransferOk = 0; HAL_DMA2D_Start(&hDma2dHandler, (uint32_t) p, Xaddress, xSize, ySize); HAL_DMA2D_PollForTransfer(&hDma2dHandler, 30); //SCB_CleanInvalidateDCache(); } static void TransferComplete(DMA2D_HandleTypeDef *hdma2d) { DMA2D_TransferOk = 1; } static void TransferError(DMA2D_HandleTypeDef *hdma2d) { } void LCD_Refresh(void) { ActiveLayer ^= 1; RenderingLayer ^= 1; BSP_LCD_SetLayerVisible_NoReload(ActiveLayer, DISABLE); BSP_LCD_SetLayerVisible_NoReload(RenderingLayer, ENABLE); HAL_LTDC_Reload(&hLtdcHandler, LTDC_RELOAD_IMMEDIATE); //BSP_LCD_Reload(LCD_RELOAD_VERTICAL_BLANKING); } void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc) { if(RefreshScreen) { LCD_Refresh(); RefreshScreen = false; } } /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/