/* * Copyright (C) OpenTX * * Based on code named * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include "opentx.h" #if defined(RADIO_T18) #define HBP 43 #define VBP 12 #define HSW 2 #define VSW 4 #define HFP 8 #define VFP 8 #else #define HBP 42 #define VBP 12 #define HSW 2 #define VSW 10 #define HFP 3 #define VFP 2 #endif #define LCD_FIRST_LAYER 0 #define LCD_SECOND_LAYER 1 uint8_t LCD_FIRST_FRAME_BUFFER[DISPLAY_BUFFER_SIZE * sizeof(pixel_t)] __SDRAM; uint8_t LCD_SECOND_FRAME_BUFFER[DISPLAY_BUFFER_SIZE * sizeof(pixel_t)] __SDRAM; uint8_t LCD_BACKUP_FRAME_BUFFER[DISPLAY_BUFFER_SIZE * sizeof(pixel_t)] __SDRAM; uint8_t LCD_SCRATCH_FRAME_BUFFER[DISPLAY_BUFFER_SIZE * sizeof(pixel_t)] __SDRAM; uint8_t currentLayer = LCD_FIRST_LAYER; BitmapBuffer lcdBuffer1(BMP_RGB565, LCD_W, LCD_H, (uint16_t *)LCD_FIRST_FRAME_BUFFER); BitmapBuffer lcdBuffer2(BMP_RGB565, LCD_W, LCD_H, (uint16_t *)LCD_SECOND_FRAME_BUFFER); BitmapBuffer * lcd = &lcdBuffer1; inline void LCD_NRST_LOW() { LCD_GPIO_NRST->BSRRH = LCD_GPIO_PIN_NRST; } inline void LCD_NRST_HIGH() { LCD_GPIO_NRST->BSRRL = LCD_GPIO_PIN_NRST; } inline bool coordsWithinScreen(coord_t x, coord_t y, coord_t w, coord_t h) { return x >= 0 && y >= 0 && x + w <= LCD_W && y + h <= LCD_H; } static void LCD_AF_GPIOConfig() { GPIO_InitTypeDef GPIO_InitStructure; /* GPIOs Configuration */ /* +------------------------+-----------------------+----------------------------+ + LCD pins assignment + +------------------------+-----------------------+---------------------------- | | LCD_TFT G2 <-> PJ.09 | | | LCD_TFT R3 <-> PJ.02 | LCD_TFT G3 <-> PJ.10 | LCD_TFT B3 <-> PJ.15 | | LCD_TFT R4 <-> PJ.03 | LCD_TFT G4 <-> PJ.11 | LCD_TFT B4 <-> PK.03 | | LCD_TFT R5 <-> PJ.04 | LCD_TFT G5 <-> PK.00 | LCD_TFT B5 <-> PK.04 | | LCD_TFT R6 <-> PJ.05 | LCD_TFT G6 <-> PK.01 | LCD_TFT B6 <-> PK.05 | | LCD_TFT R7 <-> PJ.06 | LCD_TFT G7 <-> PK.02 | LCD_TFT B7 <-> PK.06 | ------------------------------------------------------------------------------- | LCD_TFT HSYNC <-> PI.12 | LCDTFT VSYNC <-> PI.13 | | LCD_TFT CLK <-> PI.14 | LCD_TFT DE <-> PK.07 /// ----------------------------------------------------- | LCD_CS <-> PI.10 |LCD_SCK<->PI.11 ----------------------------------------------------- */ // GPIOI configuration GPIO_PinAFConfig(GPIOI, GPIO_PinSource12, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource13, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOI, GPIO_PinSource14, GPIO_AF_LTDC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14; GPIO_InitStructure.GPIO_Speed =GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType =GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_NOPULL; GPIO_Init(GPIOI, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOK, GPIO_PinSource7, GPIO_AF_LTDC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOK, &GPIO_InitStructure); // GPIOJ configuration GPIO_PinAFConfig(GPIOJ, GPIO_PinSource2, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOJ, GPIO_PinSource3, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOJ, GPIO_PinSource4, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOJ, GPIO_PinSource5, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOJ, GPIO_PinSource6, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOJ, GPIO_PinSource9, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOJ, GPIO_PinSource10, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOJ, GPIO_PinSource11, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOJ, GPIO_PinSource15, GPIO_AF_LTDC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | \ GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_15; GPIO_Init(GPIOJ, &GPIO_InitStructure); // GPIOK configuration GPIO_PinAFConfig(GPIOK, GPIO_PinSource0, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOK, GPIO_PinSource1, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOK, GPIO_PinSource2, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOK, GPIO_PinSource3, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOK, GPIO_PinSource4, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOK, GPIO_PinSource5, GPIO_AF_LTDC); GPIO_PinAFConfig(GPIOK, GPIO_PinSource6, GPIO_AF_LTDC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOK, &GPIO_InitStructure); } static void LCD_NRSTConfig(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = LCD_GPIO_PIN_NRST; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(LCD_GPIO_NRST, &GPIO_InitStructure); } static void lcdReset(void) { #if defined(RADIO_T18) // T18 screen has issues if NRST is ever brought low NRST_HIGH(); #else LCD_NRST_HIGH(); delay_ms(1); LCD_NRST_LOW(); // RESET(); delay_ms(20); LCD_NRST_HIGH(); delay_ms(30); #endif } void LCD_Init_LTDC() { LTDC_InitTypeDef LTDC_InitStruct; /* Configure PLLSAI prescalers for LCD */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLL_LTDC = 192/3 = 64 Mhz */ /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64/4 = 16 Mhz */ //second pam is for audio //third pam is for LCD RCC_PLLSAIConfig(192, 6, 3); RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div4); /* Enable PLLSAI Clock */ RCC_PLLSAICmd(ENABLE); /* Wait for PLLSAI activation */ while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET) { } /* LTDC Configuration *********************************************************/ /* Polarity configuration */ /* Initialize the horizontal synchronization polarity as active low */ LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL; /* Initialize the vertical synchronization polarity as active low */ LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL; /* Initialize the data enable polarity as active low */ LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL; /* Initialize the pixel clock polarity as input pixel clock */ LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC; /* Configure R,G,B component values for LCD background color */ LTDC_InitStruct.LTDC_BackgroundRedValue = 0; LTDC_InitStruct.LTDC_BackgroundGreenValue = 0; LTDC_InitStruct.LTDC_BackgroundBlueValue = 0; /* Configure horizontal synchronization width */ LTDC_InitStruct.LTDC_HorizontalSync = HSW; /* Configure vertical synchronization height */ LTDC_InitStruct.LTDC_VerticalSync = VSW; /* Configure accumulated horizontal back porch */ LTDC_InitStruct.LTDC_AccumulatedHBP = HBP; /* Configure accumulated vertical back porch */ LTDC_InitStruct.LTDC_AccumulatedVBP = VBP; /* Configure accumulated active width */ LTDC_InitStruct.LTDC_AccumulatedActiveW = LCD_W + HBP; /* Configure accumulated active height */ LTDC_InitStruct.LTDC_AccumulatedActiveH = LCD_H + VBP; /* Configure total width */ LTDC_InitStruct.LTDC_TotalWidth = LCD_W + HBP + HFP; /* Configure total height */ LTDC_InitStruct.LTDC_TotalHeigh = LCD_H + VBP + VFP; // init ltdc LTDC_Init(<DC_InitStruct); #if 0 LTDC_ITConfig(LTDC_IER_LIE, ENABLE); NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = LTDC_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LTDC_IRQ_PRIO; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /* Not used as 4 bits are used for the pr e-emption priority. */; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( &NVIC_InitStructure ); DMA2D_ITConfig(DMA2D_CR_TCIE, ENABLE); NVIC_InitStructure.NVIC_IRQChannel = DMA2D_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = DMA_SCREEN_IRQ_PRIO; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /* Not used as 4 bits are used for the pr e-emption priority. */; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( &NVIC_InitStructure ); DMA2D->IFCR = (unsigned long)DMA2D_IFSR_CTCIF; #endif } void LCD_LayerInit() { LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct; /* Windowing configuration */ /* In this case all the active display area is used to display a picture then : Horizontal start = horizontal synchronization + Horizontal back porch = 30 Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1 Vertical start = vertical synchronization + vertical back porch = 4 Vertical stop = Vertical start + window height -1 = 4 + 320 -1 */ LTDC_Layer_InitStruct.LTDC_HorizontalStart = HBP + 1; LTDC_Layer_InitStruct.LTDC_HorizontalStop = (LCD_W + HBP); LTDC_Layer_InitStruct.LTDC_VerticalStart = VBP + 1;; LTDC_Layer_InitStruct.LTDC_VerticalStop = (LCD_H + VBP); /* Pixel Format configuration*/ LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565; /* Alpha constant (255 totally opaque) */ LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255; /* Default Color configuration (configure A,R,G,B component values) */ LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorRed = 0; LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = 0; /* Configure blending factors */ LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA; LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA; /* the length of one line of pixels in bytes + 3 then : Line Lenth = Active high width x number of bytes per pixel + 3 Active high width = LCD_W number of bytes per pixel = 2 (pixel_format : RGB565) */ LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((LCD_W * 2) + 3); /* the pitch is the increment from the start of one line of pixels to the start of the next line in bytes, then : Pitch = Active high width x number of bytes per pixel */ LTDC_Layer_InitStruct.LTDC_CFBPitch = (LCD_W * 2); /* Configure the number of lines */ LTDC_Layer_InitStruct.LTDC_CFBLineNumber = LCD_H; /* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */ LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (uint32_t)LCD_FIRST_FRAME_BUFFER; /* Initialize LTDC layer 1 */ LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct); /* Configure Layer 2 */ LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA; LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA; /* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */ LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (uint32_t)LCD_SECOND_FRAME_BUFFER; /* Initialize LTDC layer 2 */ LTDC_LayerInit(LTDC_Layer2, <DC_Layer_InitStruct); /* LTDC configuration reload */ LTDC_ReloadConfig(LTDC_IMReload); LTDC_LayerCmd(LTDC_Layer1, ENABLE); LTDC_LayerCmd(LTDC_Layer2, ENABLE); LTDC_ReloadConfig(LTDC_IMReload); /* dithering activation */ LTDC_DitherCmd(ENABLE); } void LCD_Init(void) { /* Reset the LCD --------------------------------------------------------*/ LCD_NRSTConfig(); lcdReset(); /* Configure the LCD Control pins */ LCD_AF_GPIOConfig(); LCD_Init_LTDC(); } void LCD_SetLayer(uint32_t layer) { if (layer == LCD_FIRST_LAYER) { lcd = &lcdBuffer1; } else { lcd = &lcdBuffer2; } currentLayer = layer; } /** * @brief Configure the transparency. * @param transparency: specifies the transparency, * This parameter must range from 0x00 to 0xFF. * @retval None */ void LCD_SetTransparency(uint8_t transparency) { if (currentLayer == LCD_FIRST_LAYER) { LTDC_LayerAlpha(LTDC_Layer1, transparency); } else { LTDC_LayerAlpha(LTDC_Layer2, transparency); } LTDC_ReloadConfig(LTDC_IMReload); } void lcdInit() { /* Initialize the LCD */ LCD_Init(); LCD_LayerInit(); /* Enable LCD display */ LTDC_Cmd(ENABLE); /* Set Background layer */ LCD_SetLayer(LCD_FIRST_LAYER); // lcdClear(); LCD_SetTransparency(0); /* Set Foreground layer */ LCD_SetLayer(LCD_SECOND_LAYER); lcd->clear(); LCD_SetTransparency(255); } void DMAFillRect(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color) { #if defined(LCD_VERTICAL_INVERT) x = destw - (x + w); y = desth - (y + h); #endif DMA2D_DeInit(); DMA2D_InitTypeDef DMA2D_InitStruct; DMA2D_InitStruct.DMA2D_Mode = DMA2D_R2M; DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; DMA2D_InitStruct.DMA2D_OutputGreen = (0x07E0 & color) >> 5; DMA2D_InitStruct.DMA2D_OutputBlue = 0x001F & color; DMA2D_InitStruct.DMA2D_OutputRed = (0xF800 & color) >> 11; DMA2D_InitStruct.DMA2D_OutputAlpha = 0x0F; DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest) + 2*(destw*y + x); DMA2D_InitStruct.DMA2D_OutputOffset = (destw - w); DMA2D_InitStruct.DMA2D_NumberOfLine = h; DMA2D_InitStruct.DMA2D_PixelPerLine = w; DMA2D_Init(&DMA2D_InitStruct); /* Start Transfer */ DMA2D_StartTransfer(); /* Wait for CTC Flag activation */ while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET); } void DMACopyBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h) { #if defined(LCD_VERTICAL_INVERT) x = destw - (x + w); y = desth - (y + h); srcx = srcw - (srcx + w); srcy = srch - (srcy + h); #endif DMA2D_DeInit(); DMA2D_InitTypeDef DMA2D_InitStruct; DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M; DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest + y*destw + x); DMA2D_InitStruct.DMA2D_OutputGreen = 0; DMA2D_InitStruct.DMA2D_OutputBlue = 0; DMA2D_InitStruct.DMA2D_OutputRed = 0; DMA2D_InitStruct.DMA2D_OutputAlpha = 0; DMA2D_InitStruct.DMA2D_OutputOffset = destw - w; DMA2D_InitStruct.DMA2D_NumberOfLine = h; DMA2D_InitStruct.DMA2D_PixelPerLine = w; DMA2D_Init(&DMA2D_InitStruct); DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct; DMA2D_FG_StructInit(&DMA2D_FG_InitStruct); DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src + srcy*srcw + srcx); DMA2D_FG_InitStruct.DMA2D_FGO = srcw - w; DMA2D_FG_InitStruct.DMA2D_FGCM = CM_RGB565; DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE; DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0; DMA2D_FGConfig(&DMA2D_FG_InitStruct); /* Start Transfer */ DMA2D_StartTransfer(); /* Wait for CTC Flag activation */ while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET); } void DMACopyAlphaBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h) { #if defined(LCD_VERTICAL_INVERT) x = destw - (x + w); y = desth - (y + h); srcx = srcw - (srcx + w); srcy = srch - (srcy + h); #endif TRACE("------"); DMA2D_DeInit(); DMA2D_InitTypeDef DMA2D_InitStruct; DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_BLEND; DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest + y*destw + x); DMA2D_InitStruct.DMA2D_OutputGreen = 0; DMA2D_InitStruct.DMA2D_OutputBlue = 0; DMA2D_InitStruct.DMA2D_OutputRed = 0; DMA2D_InitStruct.DMA2D_OutputAlpha = 0; DMA2D_InitStruct.DMA2D_OutputOffset = destw - w; DMA2D_InitStruct.DMA2D_NumberOfLine = h; DMA2D_InitStruct.DMA2D_PixelPerLine = w; DMA2D_Init(&DMA2D_InitStruct); DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct; DMA2D_FG_StructInit(&DMA2D_FG_InitStruct); DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src + srcy*srcw + srcx); DMA2D_FG_InitStruct.DMA2D_FGO = srcw - w; DMA2D_FG_InitStruct.DMA2D_FGCM = CM_ARGB4444; DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE; DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0; DMA2D_FGConfig(&DMA2D_FG_InitStruct); DMA2D_BG_InitTypeDef DMA2D_BG_InitStruct; DMA2D_BG_StructInit(&DMA2D_BG_InitStruct); DMA2D_BG_InitStruct.DMA2D_BGMA = CONVERT_PTR_UINT(dest + y*destw + x); DMA2D_BG_InitStruct.DMA2D_BGO = destw - w; DMA2D_BG_InitStruct.DMA2D_BGCM = CM_RGB565; DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE; DMA2D_BG_InitStruct.DMA2D_BGPFC_ALPHA_VALUE = 0; DMA2D_BGConfig(&DMA2D_BG_InitStruct); /* Start Transfer */ DMA2D_StartTransfer(); /* Wait for CTC Flag activation */ while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET); } void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format) { DMA2D_DeInit(); DMA2D_InitTypeDef DMA2D_InitStruct; DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_PFC; DMA2D_InitStruct.DMA2D_CMode = format; DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest); DMA2D_InitStruct.DMA2D_OutputGreen = 0; DMA2D_InitStruct.DMA2D_OutputBlue = 0; DMA2D_InitStruct.DMA2D_OutputRed = 0; DMA2D_InitStruct.DMA2D_OutputAlpha = 0; DMA2D_InitStruct.DMA2D_OutputOffset = 0; DMA2D_InitStruct.DMA2D_NumberOfLine = h; DMA2D_InitStruct.DMA2D_PixelPerLine = w; DMA2D_Init(&DMA2D_InitStruct); DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct; DMA2D_FG_StructInit(&DMA2D_FG_InitStruct); DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src); DMA2D_FG_InitStruct.DMA2D_FGO = 0; DMA2D_FG_InitStruct.DMA2D_FGCM = CM_ARGB8888; DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = REPLACE_ALPHA_VALUE; DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0; DMA2D_FGConfig(&DMA2D_FG_InitStruct); /* Start Transfer */ DMA2D_StartTransfer(); /* Wait for CTC Flag activation */ while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET); } void lcdCopy(void * dest, void * src) { DMA2D_DeInit(); DMA2D_InitTypeDef DMA2D_InitStruct; DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M; DMA2D_InitStruct.DMA2D_CMode = DMA2D_RGB565; DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest); DMA2D_InitStruct.DMA2D_OutputGreen = 0; DMA2D_InitStruct.DMA2D_OutputBlue = 0; DMA2D_InitStruct.DMA2D_OutputRed = 0; DMA2D_InitStruct.DMA2D_OutputAlpha = 0; DMA2D_InitStruct.DMA2D_OutputOffset = 0; DMA2D_InitStruct.DMA2D_NumberOfLine = LCD_H; DMA2D_InitStruct.DMA2D_PixelPerLine = LCD_W; DMA2D_Init(&DMA2D_InitStruct); DMA2D_FG_InitTypeDef DMA2D_FG_InitStruct; DMA2D_FG_StructInit(&DMA2D_FG_InitStruct); DMA2D_FG_InitStruct.DMA2D_FGMA = CONVERT_PTR_UINT(src); DMA2D_FG_InitStruct.DMA2D_FGO = 0; DMA2D_FG_InitStruct.DMA2D_FGCM = CM_RGB565; DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE; DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0; DMA2D_FGConfig(&DMA2D_FG_InitStruct); /* Start Transfer */ DMA2D_StartTransfer(); /* Wait for CTC Flag activation */ while (DMA2D_GetFlagStatus(DMA2D_FLAG_TC) == RESET); } void lcdStoreBackupBuffer() { lcdCopy(LCD_BACKUP_FRAME_BUFFER, lcd->getData()); } int lcdRestoreBackupBuffer() { lcdCopy(lcd->getData(), LCD_BACKUP_FRAME_BUFFER); return 1; } uint16_t* lcdGetBackupBuffer() { return (uint16_t*)LCD_BACKUP_FRAME_BUFFER; } uint16_t* lcdGetScratchBuffer() { return (uint16_t*)LCD_SCRATCH_FRAME_BUFFER; } void lcdRefresh() { if (currentLayer == LCD_FIRST_LAYER) { LTDC_LayerAlpha(LTDC_Layer1, 255); LTDC_LayerAlpha(LTDC_Layer2, 0); } else { LTDC_LayerAlpha(LTDC_Layer1, 0); LTDC_LayerAlpha(LTDC_Layer2, 255); } LTDC_ReloadConfig(LTDC_IMReload); } void lcdNextLayer() { if (currentLayer == LCD_FIRST_LAYER) { LCD_SetLayer(LCD_SECOND_LAYER); } else { LCD_SetLayer(LCD_FIRST_LAYER); } }