LTDC驱动遇到问题,求助
LTDC的层初始化代码void f_LTDC_LayerInit(uint8_t LayerIndex){
LTDC_Layer_InitTypeDef LTDC_Layer_Init;
// LTDC_CLUT_InitTypeDefLTDC_CLUT_InitStruct;
LTDC_Layer_Init.LTDC_HorizontalStart = TFT_HBP ;
LTDC_Layer_Init.LTDC_HorizontalStop = TFT_PHYW + TFT_HBP -1;
LTDC_Layer_Init.LTDC_VerticalStart = TFT_VBP ;
LTDC_Layer_Init.LTDC_VerticalStop = TFT_PHYH + TFT_VBP -1;
LTDC_Layer_Init.LTDC_PixelFormat = LTDC_Pixelformat_RGB565;
LTDC_Layer_Init.LTDC_ConstantAlpha = 255;
LTDC_Layer_Init.LTDC_DefaultColorBlue = 0;
LTDC_Layer_Init.LTDC_DefaultColorGreen = 0;
LTDC_Layer_Init.LTDC_DefaultColorRed = 0;
LTDC_Layer_Init.LTDC_DefaultColorAlpha = 0;
LTDC_Layer_Init.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA;
LTDC_Layer_Init.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA;
/* the length of one line of pixels in bytes + 3 then :
5.Line Lenth = Active high width x number of bytes per pixel + 3
6.Active high width = 240
7.number of bytes per pixel = 2 (pixel_format : RGB565)
8.*/
LTDC_Layer_Init.LTDC_CFBLineLength = (TFT_PHYW*2) +3;//old=3 //1224
/*the pitch is the increment from the start of one line of pixels to the
12.start of the next line in bytes, then :
13.Pitch = Active high width x number of bytes per pixel
14.*/
LTDC_Layer_Init.LTDC_CFBPitch = TFT_PHYW*2;
/* configure the number of lines */
LTDC_Layer_Init.LTDC_CFBLineNumber = TFT_PHYH;
/* Input Address configuration */
LTDC_Layer_Init.LTDC_CFBStartAdress = SDRAM_BASE;
LTDC_LayerInit((LayerIndex == 0 ? LTDC_Layer1 : LTDC_Layer2), <DC_Layer_Init);
///*Enable LUT on demand */
//BitsPerPixel = LCD_GetBitsPerPixelEx(LayerIndex);
//if (BitsPerPixel <= 8)
//{
// /* Enable usage of LUT for all modes with <= 8bpp */
// LTDC_CLUTCmd((LayerIndex == 0 ? LTDC_Layer1 : LTDC_Layer2), ENABLE);
//}
//else
//{
// /*Optional CLUT initialization for AL88 mode (16bpp) */
// if (apColorConvAPI == GUICC_88666I)
// {
// LTDC_CLUTCmd((LayerIndex == 0 ? LTDC_Layer1 : LTDC_Layer2), ENABLE);
// for (i = 0; i < 256; i++)
// {
// Color = LCD_API_ColorConv_8666.pfIndex2Color(i);
// LTDC_CLUT_InitStruct.LTDC_BlueValue =((Color >> 16) & 0xff);
// LTDC_CLUT_InitStruct.LTDC_GreenValue=((Color >>8) & 0xff);
// LTDC_CLUT_InitStruct.LTDC_RedValue = (Color & 0xff);
// LTDC_CLUT_InitStruct.LTDC_CLUTAdress=i << 24;
// LTDC_CLUTInit((LayerIndex == 0 ? LTDC_Layer1 : LTDC_Layer2), <DC_CLUT_InitStruct);
// }
// }
//}
/*Enable layer */
LTDC_LayerCmd((LayerIndex == 0 ? LTDC_Layer1 : LTDC_Layer2), ENABLE);
/* Reload configuration */
LTDC_ReloadConfig(LTDC_VBReload);
/* dithering activation */
//LTDC_DitherCmd(ENABLE);
//LTDC_ReloadConfig(LTDC_IMReload);
LTDC_Cmd(ENABLE);
}
static void LCD_AF_GPIOConfig(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable GPIOI, GPIOJ, GPIOK AHB Clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG | \
RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI ,ENABLE);
/* GPIOs Configuration */
/*
+------------------------+-----------------------+----------------------------+
+ LCD pins assignment +
+------------------------+-----------------------+----------------------------+
| | | |
| | | |
| |LCD_TFT G2 <-> PA.06 | |
|LCD_TFT R3 <-> PB.00|LCD_TFT G3 <-> PG.10 |LCD_TFT B3 <-> PG.11 |
|LCD_TFT R4 <-> PA.11|LCD_TFT G4 <-> PB.10 |LCD_TFT B4 <-> PG.12 |
|LCD_TFT R5 <-> PA.12|LCD_TFT G5 <-> PB.11 |LCD_TFT B5 <-> PA.03 |
|LCD_TFT R6 <-> PB.01|LCD_TFT G6 <-> PC.07 |LCD_TFT B6 <-> PB.08 |
|LCD_TFT R7 <-> PG.06|LCD_TFT G7 <-> PD.03 |LCD_TFT B7 <-> PB.09 |
-------------------------------------------------------------------------------
|LCD_TFT HSYNC <-> PC.06| LCDTFT VSYNC <->PA.04 |
|LCD_TFT CLK <-> PG.07| LCD_TFT DE <->PF.10 |
-----------------------------------------------------
*/
/* GPIOI configuration */
//GPIO A
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_LTDC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_3 | GPIO_Pin_6 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
//GPIO C
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_LTDC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStruct);
//GPIO F
GPIO_PinAFConfig(GPIOF, GPIO_PinSource10, GPIO_AF_LTDC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOF, &GPIO_InitStruct);
//GPIO G
GPIO_PinAFConfig(GPIOG, GPIO_PinSource6, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource7, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource10, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource11, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOG, GPIO_PinSource12, GPIO_AF_LTDC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOG, &GPIO_InitStruct);
//GPIO B
GPIO_PinAFConfig(GPIOB, GPIO_PinSource0, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_LTDC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStruct);
//GPIO D
GPIO_PinAFConfig(GPIOD, GPIO_PinSource3, GPIO_AF_LTDC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3 ;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStruct);
} void f_LTDC_Init(void)
{
LTDC_InitTypeDef LTDC_InitStruct;
/* Enable the LTDC Clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE);
/* Configure PLLSAI prescalers for LCD */
// RCC_PLLSAIConfig(200, 4, 3); //OK pclk run in 23MHz
// RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div4);//0127,old=2分频
//以下两行是野火的程序中的配置
RCC_PLLSAIConfig(200, 4, 3);
RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div2);
/* Enable PLLSAI Clock */
RCC_PLLSAICmd(ENABLE);
/* Wait for PLLSAI activation */
while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET)
{
}
/* Enable the DMA2D Clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE);
/* Configure the LCD Control pins */
LCD_AF_GPIOConfig();
/* 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 = 255;
LTDC_InitStruct.LTDC_BackgroundGreenValue = 0;
LTDC_InitStruct.LTDC_BackgroundBlueValue = 0;
LTDC_InitStruct.LTDC_HorizontalSync = TFT_HSW-1;
/* Configure vertical synchronization height */
LTDC_InitStruct.LTDC_VerticalSync = TFT_VSW-1;
/* Configure accumulated horizontal back porch */
LTDC_InitStruct.LTDC_AccumulatedHBP = TFT_HBP-1;
/* Configure accumulated vertical back porch */
LTDC_InitStruct.LTDC_AccumulatedVBP = TFT_VBP-1;
/* Configure accumulated active width */
LTDC_InitStruct.LTDC_AccumulatedActiveW = TFT_PHYW + TFT_HBP -1;//old后-1,845
/* Configure accumulated active height */
LTDC_InitStruct.LTDC_AccumulatedActiveH = TFT_PHYH + TFT_VBP -1;//old后-1
/* Configure total width */
LTDC_InitStruct.LTDC_TotalWidth = TFT_PHYW + TFT_HBP + TFT_HFP -1;
/* Configure total height */
LTDC_InitStruct.LTDC_TotalHeigh = TFT_PHYH + TFT_VBP + TFT_VFP -1;
LTDC_Init(<DC_InitStruct);
// LTDC_ITConfig(LTDC_IT_LI, ENABLE);
// NVIC_SetPriority(LTDC_IRQn, 0);
// NVIC_EnableIRQ(LTDC_IRQn);
} 除了代码还是代码:)
页:
[1]