STM32F4 LTDC学习
阅读原文时间:2023年07月09日阅读:4

很久没有写东西了,也很久没看文档了吼吼,觉得有点无聊,找来F4看看,主要看F429。督促自己多看多记录。

首先配置同步时序先看参考手册

下面看一个实际例子,一块439的开发板

设置:

LTDC_InitStruct.LTDC_HorizontalSync = ;
/* */
LTDC_InitStruct.LTDC_VerticalSync = ;
/* */
LTDC_InitStruct.LTDC_AccumulatedHBP = ;
/* */
LTDC_InitStruct.LTDC_AccumulatedVBP = ;
/* */
LTDC_InitStruct.LTDC_AccumulatedActiveW = ;
/* */
LTDC_InitStruct.LTDC_AccumulatedActiveH = ;
/* */
LTDC_InitStruct.LTDC_TotalWidth = ;
/* */
LTDC_InitStruct.LTDC_TotalHeigh = ;

LTDC_Init(&LTDC_InitStruct);

配置时序

注意每个参数定义,之前是累加

看下完整的初始化代码

void LCD_Init(void)
{
LTDC_InitTypeDef LTDC_InitStruct;
LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct;
LTDC_Layer_TypeDef LTDC_Layerx;

/* IO¿Ú³õʼ»¯ */
LCD_GPIOInit();

LCD_DisplayOff();
/* ʹÄÜLCDʱÖÓ */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE);
/* ʹÄÜDMAʧ×Ù*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE);

/* ˮƽͬ²½ÐźÅ---µÍµçƽÓÐЧ */
LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL;
/* ´¹Ö±Í¬²½ÐźÅ---µÍµçƽÓÐЧ */
LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL;
/* Êý¾ÝʹÄÜÐźÅ---µÍµçƽÓÐЧ */
LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL;
/* ÏñËØʱÖÓÅäÖÃ--- */
LTDC_InitStruct.LTDC_PCPolarity = LTDC_DEPolarity_AL;
/* LCD±³¹âÉèÖà */
LTDC_InitStruct.LTDC_BackgroundRedValue = ;
LTDC_InitStruct.LTDC_BackgroundGreenValue = ;
LTDC_InitStruct.LTDC_BackgroundBlueValue = ;
/*
****************************************************************************
*PLLSAI_VCO = HSE*PLLSAI_N / PLL_M = 8 * 192 / 8 = 192MHz
*PLLLCDCLK = PLLSAI_VCO / PLLSAI_R = 192 / 3 = 64 Mhz
*LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64 / 8 = 8 Mhz
****************************************************************************
*/
RCC_PLLSAIConfig(, , );
RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div4);
/* ʹÄÜPLLSAIʱÖÓ */
RCC_PLLSAICmd(ENABLE);
/* µÈ´ýPLLSAIʱÖÓ */
while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET){}
/* */
LTDC_InitStruct.LTDC_HorizontalSync = ;
/* */
LTDC_InitStruct.LTDC_VerticalSync = ;
/* */
LTDC_InitStruct.LTDC_AccumulatedHBP = ;
/* */
LTDC_InitStruct.LTDC_AccumulatedVBP = ;
/* */
LTDC_InitStruct.LTDC_AccumulatedActiveW = ;
/* */
LTDC_InitStruct.LTDC_AccumulatedActiveH = ;
/* */
LTDC_InitStruct.LTDC_TotalWidth = ;
/* */
LTDC_InitStruct.LTDC_TotalHeigh = ;

LTDC_Init(&LTDC_InitStruct);

LTDC_Layer_InitStruct.LTDC_HorizontalStart = ;
LTDC_Layer_InitStruct.LTDC_HorizontalStop = ( + - );
LTDC_Layer_InitStruct.LTDC_VarticalStart = ;
LTDC_Layer_InitStruct.LTDC_VerticalStop = ( + - );

/* Pixel Format configuration*/
LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
/* Alpha constant (255 totally opaque) */
LTDC_Layer_InitStruct.LTDC_ConstantAlpha = ;
/* Default Color configuration (configure A,R,G,B component values) */
LTDC_Layer_InitStruct.LTDC_DefaultColorBlue = ;
LTDC_Layer_InitStruct.LTDC_DefaultColorGreen = ;
LTDC_Layer_InitStruct.LTDC_DefaultColorRed = ;
LTDC_Layer_InitStruct.LTDC_DefaultColorAlpha = ;
/* 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_PIXEL_WIDTH
number of bytes per pixel = 2 (pixel_format : RGB565)
*/
LTDC_Layer_InitStruct.LTDC_CFBLineLength = (( * ) + );
/* 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 = ( * );
/* configure the number of lines */
LTDC_Layer_InitStruct.LTDC_CFBLineNumber = ;

/* Input Address configuration */
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FRAME_BUFFER;

LTDC_LayerInit(LTDC_Layer1, &LTDC_Layer_InitStruct);

/* Configure Layer2 */
LTDC_Layer_InitStruct.LTDC_CFBStartAdress = LCD_FRAME_BUFFER + BUFFER_OFFSET;
LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA;
LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA;
LTDC_LayerInit(LTDC_Layer2, &LTDC_Layer_InitStruct);

LTDC_ReloadConfig(LTDC_IMReload);

/* Enable foreground & background Layers */
LTDC_LayerCmd(LTDC_Layer1, ENABLE);
// LTDC_LayerCmd(LTDC_Layer2, ENABLE);
LTDC_ReloadConfig(LTDC_IMReload);

LCD_DisplayOn();
}

LCD_Init

LTDC_DefaultColorBlue就是背景色

每个Layer支持窗口(Window)操作,所谓Window,就是指该层的图像只有在Window区域内有效,而Window区域外则用该层的DefaultColor填充。如下图:

填色直接写内存

int main (void)
{
uint32_t i, j;
uint16_t *addr = (uint16_t *)LCD_FRAME_BUFFER;

SDRAM_Init();
LCD_Init();
j = ;
while () {

 for (i = ; i < 0x2000000;i++);  
 for (i = ; i <  \* ; i++)  
 {  
   addr\[i\] =  << j;  
 }  
 j++;  
 if (j > )j = ;  

}
}

LCD display RGB

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章