refactor: DMA2D and LTDC conversion to HAL/LL (#3036)

Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
Malte Langermann
2023-10-23 18:58:02 +10:00
committed by GitHub
co-authored by Peter Feerick
parent d0ae5bd85c
commit 1af8b78256
24 changed files with 488 additions and 745 deletions
+95 -293
View File
@@ -19,13 +19,16 @@
* GNU General Public License for more details.
*/
#include "stm32_hal_ll.h"
#include "stm32_hal.h"
#include "opentx_types.h"
#include "dma2d.h"
#include "hal.h"
#include "delays_driver.h"
#include "lcd.h"
#include <lvgl/lvgl.h>
#include "stm32f4xx_dma2d.h"
#include "stm32f4xx_ltdc.h"
#if defined(RADIO_T18)
#define HBP 43
#define VBP 12
@@ -46,7 +49,11 @@
#define VFP 2
#endif
static LTDC_HandleTypeDef hltdc;
static void* initialFrameBuffer = nullptr;
#if defined(LCD_VERTICAL_INVERT)
typedef uint16_t pixel_t;
static pixel_t _LCD_BUF_1[DISPLAY_BUFFER_SIZE] __SDRAM;
static pixel_t _LCD_BUF_2[DISPLAY_BUFFER_SIZE] __SDRAM;
@@ -177,17 +184,18 @@ static void startLcdRefresh(lv_disp_drv_t *disp_drv, uint16_t *buffer,
inline void LCD_NRST_LOW()
{
LCD_GPIO_NRST->BSRRH = LCD_GPIO_PIN_NRST;
LL_GPIO_ResetOutputPin(LCD_GPIO_NRST, LCD_GPIO_PIN_NRST);
}
inline void LCD_NRST_HIGH()
{
LCD_GPIO_NRST->BSRRL = LCD_GPIO_PIN_NRST;
LL_GPIO_SetOutputPin(LCD_GPIO_NRST, LCD_GPIO_PIN_NRST);
}
static void LCD_AF_GPIOConfig()
{
GPIO_InitTypeDef GPIO_InitStructure;
LL_GPIO_InitTypeDef GPIO_InitStructure;
LL_GPIO_StructInit(&GPIO_InitStructure);
/* GPIOs Configuration */
/*
@@ -207,66 +215,41 @@ static void LCD_AF_GPIOConfig()
| 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);
GPIO_InitStructure.Pin = LL_GPIO_PIN_12 | LL_GPIO_PIN_13 | LL_GPIO_PIN_14;
GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStructure.Pull = LL_GPIO_PULL_NO;
GPIO_InitStructure.Alternate = LL_GPIO_AF_14; // AF LTDC
LL_GPIO_Init(GPIOI, &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.Pin = LL_GPIO_PIN_2 | LL_GPIO_PIN_3 | LL_GPIO_PIN_4 | LL_GPIO_PIN_5 | LL_GPIO_PIN_6
| LL_GPIO_PIN_9 | LL_GPIO_PIN_10 | LL_GPIO_PIN_11 | LL_GPIO_PIN_15;
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);
LL_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.Pin = LL_GPIO_PIN_0 | LL_GPIO_PIN_1 | LL_GPIO_PIN_2 | LL_GPIO_PIN_3 | LL_GPIO_PIN_4
| LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_7;
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);
LL_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);
LL_GPIO_InitTypeDef GPIO_InitStructure;
LL_GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.Pin = LCD_GPIO_PIN_NRST;
GPIO_InitStructure.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStructure.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStructure.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(LCD_GPIO_NRST, &GPIO_InitStructure);
}
static void lcdReset(void)
@@ -287,7 +270,7 @@ static void lcdReset(void)
void LCD_Init_LTDC()
{
LTDC_InitTypeDef LTDC_InitStruct;
hltdc.Instance = LTDC;
/* Configure PLLSAI prescalers for LCD */
/* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 MHz */
@@ -297,66 +280,60 @@ void LCD_Init_LTDC()
/* alternatively LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64/8 = 8 MHz */
//second pam is for audio
//third pam is for LCD
RCC_PLLSAIConfig(192, 6, 3);
RCC_PeriphCLKInitTypeDef clkConfig;
clkConfig.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
clkConfig.PLLSAI.PLLSAIN = 192;
clkConfig.PLLSAI.PLLSAIR = 3;
clkConfig.PLLSAIDivQ = 6;
#if defined(RADIO_TX16S)
RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8);
clkConfig.PLLSAIDivR = RCC_PLLSAIDIVR_8;
#else
RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div4);
clkConfig.PLLSAIDivR = RCC_PLLSAIDIVR_4;
#endif
/* Enable PLLSAI Clock */
RCC_PLLSAICmd(ENABLE);
/* Wait for PLLSAI activation */
while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET)
{
}
HAL_RCCEx_PeriphCLKConfig(&clkConfig);
/* LTDC Configuration *********************************************************/
/* Polarity configuration */
/* Initialize the horizontal synchronization polarity as active low */
LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
/* Initialize the vertical synchronization polarity as active low */
LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
/* Initialize the data enable polarity as active low */
LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
/* Initialize the pixel clock polarity as input pixel clock */
LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC;
hltdc.Init.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;
hltdc.Init.Backcolor.Red = 0;
hltdc.Init.Backcolor.Green = 0;
hltdc.Init.Backcolor.Blue = 0;
/* Configure horizontal synchronization width */
LTDC_InitStruct.LTDC_HorizontalSync = HSW;
hltdc.Init.HorizontalSync = HSW;
/* Configure vertical synchronization height */
LTDC_InitStruct.LTDC_VerticalSync = VSW;
hltdc.Init.VerticalSync = VSW;
/* Configure accumulated horizontal back porch */
LTDC_InitStruct.LTDC_AccumulatedHBP = HBP;
hltdc.Init.AccumulatedHBP = HBP;
/* Configure accumulated vertical back porch */
LTDC_InitStruct.LTDC_AccumulatedVBP = VBP;
hltdc.Init.AccumulatedVBP = VBP;
/* Configure accumulated active width */
LTDC_InitStruct.LTDC_AccumulatedActiveW = LCD_PHYS_W + HBP;
hltdc.Init.AccumulatedActiveW = LCD_PHYS_W + HBP;
/* Configure accumulated active height */
LTDC_InitStruct.LTDC_AccumulatedActiveH = LCD_PHYS_H + VBP;
hltdc.Init.AccumulatedActiveH = LCD_PHYS_H + VBP;
/* Configure total width */
LTDC_InitStruct.LTDC_TotalWidth = LCD_PHYS_W + HBP + HFP;
hltdc.Init.TotalWidth = LCD_PHYS_W + HBP + HFP;
/* Configure total height */
LTDC_InitStruct.LTDC_TotalHeigh = LCD_PHYS_H + VBP + VFP;
hltdc.Init.TotalHeigh = LCD_PHYS_H + VBP + VFP;
LTDC_Init(&LTDC_InitStruct);
HAL_LTDC_Init(&hltdc);
// Configure IRQ (line)
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = LTDC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LTDC_IRQ_PRIO;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init( &NVIC_InitStructure );
NVIC_SetPriority(LTDC_IRQn, LTDC_IRQ_PRIO);
NVIC_EnableIRQ(LTDC_IRQn);
// Trigger on last line
LTDC_LIPConfig(LCD_PHYS_H);
LTDC_ITConfig(LTDC_IER_LIE, ENABLE);
HAL_LTDC_ProgramLineEvent(&hltdc, LCD_PHYS_H);
__HAL_LTDC_ENABLE_IT(&hltdc, LTDC_IT_LI);
#if 0
DMA2D_ITConfig(DMA2D_CR_TCIE, ENABLE);
@@ -372,66 +349,49 @@ void LCD_Init_LTDC()
void LCD_LayerInit()
{
LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct;
auto& layer = hltdc.LayerCfg[0];
/* 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_PHYS_W + HBP);
LTDC_Layer_InitStruct.LTDC_VerticalStart = VBP + 1;;
LTDC_Layer_InitStruct.LTDC_VerticalStop = (LCD_PHYS_H + VBP);
/* In this case all the active display area is used to display a picture */
layer.WindowX0 = 0;
layer.WindowX1 = LCD_PHYS_W;
layer.WindowY0 = 0;
layer.WindowY1 = LCD_PHYS_H;
/* Pixel Format configuration*/
LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
layer.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
/* Alpha constant (255 totally opaque) */
LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255;
layer.Alpha = 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;
layer.Backcolor.Blue = 0;
layer.Backcolor.Green = 0;
layer.Backcolor.Red = 0;
layer.Alpha0 = 0;
/* Configure blending factors */
LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA;
LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA;
layer.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
layer.BlendingFactor2 = LTDC_BLENDING_FACTOR2_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_PHYS_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_PHYS_W * 2);
/* Configure the number of lines */
LTDC_Layer_InitStruct.LTDC_CFBLineNumber = LCD_PHYS_H;
layer.ImageWidth = LCD_PHYS_W;
layer.ImageHeight = LCD_PHYS_H;
/* Start Address configuration : the LCD Frame buffer is defined on SDRAM w/ Offset */
#if defined(LCD_VERTICAL_INVERT)
uint32_t layer_address = (uint32_t)_LCD_BUF_1;
intptr_t layer_address = (intptr_t)_LCD_BUF_1;
#else
uint32_t layer_address = (uint32_t)lcdFront->getData();
intptr_t layer_address = (intptr_t)initialFrameBuffer;
#endif
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = layer_address;
layer.FBStartAdress = layer_address;
/* Initialize LTDC layer 1 */
LTDC_LayerInit(LTDC_Layer1, &LTDC_Layer_InitStruct);
HAL_LTDC_ConfigLayer(&hltdc, &hltdc.LayerCfg[0], 0);
}
/* LTDC configuration reload */
LTDC_ReloadConfig(LTDC_IMReload);
// Enable layer and reload
LTDC_LayerCmd(LTDC_Layer1, ENABLE);
LTDC_ReloadConfig(LTDC_IMReload);
extern "C"
void lcdSetInitalFrameBuffer(void* fbAddress)
{
initialFrameBuffer = fbAddress;
}
void LCD_Init(void)
@@ -450,6 +410,7 @@ void LCD_Init(void)
LCD_Init_LTDC();
}
extern "C"
void lcdInit()
{
#if defined(LCD_VERTICAL_INVERT)
@@ -463,175 +424,16 @@ void lcdInit()
LCD_LayerInit();
// Enable LCD display
LTDC_Cmd(ENABLE);
__HAL_LTDC_ENABLE(&hltdc);
lcdSetFlushCb(startLcdRefresh);
}
void DMAWait()
{
while(DMA2D->CR & DMA2D_CR_START);
}
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)
{
DMAWait();
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();
}
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)
{
DMAWait();
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();
}
// same as DMACopyAlphaBitmap(), but with an 8 bit mask for each pixel (used by fonts)
void DMACopyAlphaMask(uint16_t *dest, uint16_t destw, uint16_t desth,
uint16_t x, uint16_t y, const uint8_t *src, uint16_t srcw,
uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w,
uint16_t h, uint16_t bg_color)
{
DMAWait();
DMA2D_DeInit();
DMA2D_InitTypeDef DMA2D_InitStruct;
DMA2D_InitStruct.DMA2D_Mode = DMA2D_M2M_BLEND;
DMA2D_InitStruct.DMA2D_CMode = CM_RGB565;
DMA2D_InitStruct.DMA2D_OutputMemoryAdd = CONVERT_PTR_UINT(dest + y*destw + x);
DMA2D_InitStruct.DMA2D_OutputBlue = 0;
DMA2D_InitStruct.DMA2D_OutputGreen = 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_A8; // 8 bit inputs every time
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_MODE = NO_MODIF_ALPHA_VALUE;
DMA2D_FG_InitStruct.DMA2D_FGPFC_ALPHA_VALUE = 0;
DMA2D_FG_InitStruct.DMA2D_FGC_RED = GET_RED(bg_color); // 8 bit red
DMA2D_FG_InitStruct.DMA2D_FGC_GREEN = GET_GREEN(bg_color); // 8 bit green
DMA2D_FG_InitStruct.DMA2D_FGC_BLUE = GET_BLUE(bg_color); // 8 bit blue
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();
}
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();
}
extern "C" void LTDC_IRQHandler(void)
{
// clear interrupt flag
LTDC->ICR = LTDC_ICR_CLIF;
__HAL_LTDC_CLEAR_FLAG(&hltdc, LTDC_FLAG_LI);
_frame_addr_reloaded = 1;
}