回复【15楼】l692519765:
---------------------------------
我找到的LTDC部分初始化,来自于最新版STemWin
[mw_shl_code=c,true]static void LCD_LL_Init(uint32_t LayerIndex)
{
uint32_t xSize, ySize, BytesPerLine, BitsPerPixel, i;
uint32_t Color;
static uint32_t Is_Initialized;
LTDC_InitTypeDef LTDC_InitStruct;
LTDC_Layer_InitTypeDef LTDC_Layer_Init;
LTDC_CLUT_InitTypeDef LTDC_CLUT_InitStruct;
if (LayerIndex >= GUI_NUM_LAYERS)
{
return;
}
if (Is_Initialized == 0)
{
Is_Initialized = 1;
/* Clock configuration */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2D, ENABLE);
/* Enable the LTDC Clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_LTDC, ENABLE);
/* 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 = 0;
LTDC_InitStruct.LTDC_BackgroundGreenValue = 0;
LTDC_InitStruct.LTDC_BackgroundBlueValue = 0;
/* Configure PLLSAI prescalers for LCD */
RCC_PLLSAIConfig(192, 7, 3);
RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8);
/* Enable PLLSAI Clock */
RCC_PLLSAICmd(ENABLE);
/* Wait for PLLSAI activation */
while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET)
{
}
xSize = LCD_GetXSizeEx(LayerIndex);
ySize = LCD_GetYSizeEx(LayerIndex);
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 = xSize + HBP;
/* Configure accumulated active height */
LTDC_InitStruct.LTDC_AccumulatedActiveH = ySize + VBP;
/* Configure total width */
LTDC_InitStruct.LTDC_TotalWidth = xSize + HBP + HFP;
/* Configure total height */
LTDC_InitStruct.LTDC_TotalHeigh = ySize + VBP + VFP;
LTDC_Init(<DC_InitStruct);
LTDC_ITConfig(LTDC_IT_LI, ENABLE);
NVIC_SetPriority(LTDC_IRQn, 0);
NVIC_EnableIRQ(LTDC_IRQn);
}
xSize = LCD_GetXSizeEx(LayerIndex);
ySize = LCD_GetYSizeEx(LayerIndex);
BytesPerLine = GetBytesPerLine(LayerIndex, xSize);
LTDC_Layer_Init.LTDC_HorizontalStart = HBP + 1;
LTDC_Layer_Init.LTDC_HorizontalStop = (xSize + HBP);
LTDC_Layer_Init.LTDC_VerticalStart = VBP + 1;
LTDC_Layer_Init.LTDC_VerticalStop = (ySize + VBP);
LTDC_Layer_Init.LTDC_PixelFormat = GetPixelformat(LayerIndex);
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;
#if (GUI_NUM_LAYERS > 1)
LTDC_Layer_Init.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA;
LTDC_Layer_Init.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA;
#else
LTDC_Layer_Init.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA;
LTDC_Layer_Init.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA;
#endif
LTDC_Layer_Init.LTDC_CFBLineLength = BytesPerLine + 3;
LTDC_Layer_Init.LTDC_CFBPitch = BytesPerLine;
LTDC_Layer_Init.LTDC_CFBLineNumber = ySize;
LTDC_Layer_Init.LTDC_CFBStartAdress = layer_address[LayerIndex];
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[LayerIndex] == 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);
}[/mw_shl_code]
怎么看也不是SPI接口啊 |