原理图中用到哪些引脚了,那些引脚就需要做初始化,具体初始化代码如下,初始化时别忘了初始化引脚对应的时钟:
复制代码
/*
*********************************************************************************************************
* 函 数 名: LCD429_AF_GPIOConfig
* 功能说明: 配置GPIO用于 LTDC.
* 形 参: 无
* 返 回 值: 无
*********************************************************************************************************
*/
static void LCD429_AF_GPIOConfig(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* Enable GPIOI, GPIOJ, GPIOK AHB Clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI | RCC_AHB1Periph_GPIOJ |
RCC_AHB1Periph_GPIOK, ENABLE);
/* GPIOs Configuration */
/*
+------------------------+-----------------------+----------------------------+
+ LCD pins assignment +
+------------------------+-----------------------+----------------------------+
| LCD429_TFT R0 <-> PI.15 | LCD429_TFT G0 <-> PJ.07 | LCD429_TFT B0 <-> PJ.12 |
| LCD429_TFT R1 <-> PJ.00 | LCD429_TFT G1 <-> PJ.08 | LCD429_TFT B1 <-> PJ.13 |
| LCD429_TFT R2 <-> PJ.01 | LCD429_TFT G2 <-> PJ.09 | LCD429_TFT B2 <-> PJ.14 |
| LCD429_TFT R3 <-> PJ.02 | LCD429_TFT G3 <-> PJ.10 | LCD429_TFT B3 <-> PJ.15 |
| LCD429_TFT R4 <-> PJ.03 | LCD429_TFT G4 <-> PJ.11 | LCD429_TFT B4 <-> PK.03 |
| LCD429_TFT R5 <-> PJ.04 | LCD429_TFT G5 <-> PK.00 | LCD429_TFT B5 <-> PK.04 |
| LCD429_TFT R6 <-> PJ.05 | LCD429_TFT G6 <-> PK.01 | LCD429_TFT B6 <-> PK.05 |
| LCD429_TFT R7 <-> PJ.06 | LCD429_TFT G7 <-> PK.02 | LCD429_TFT B7 <-> PK.06 |
-------------------------------------------------------------------------------
| LCD429_TFT HSYNC <-> PI.12 | LCDTFT VSYNC <-> PI.13 |
| LCD429_TFT CLK <-> PI.14 | LCD429_TFT DE <-> PK.07 |
-----------------------------------------------------
*/
/* 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_PinAFConfig(GPIOI, GPIO_PinSource15, GPIO_AF_LTDC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
//GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOI, &GPIO_InitStruct);
/* GPIOJ configuration */
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource0, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource1, GPIO_AF_LTDC);
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_PinSource7, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource8, 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_PinSource12, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource13, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource14, GPIO_AF_LTDC);
GPIO_PinAFConfig(GPIOJ, GPIO_PinSource15, GPIO_AF_LTDC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 |
GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOJ, &GPIO_InitStruct);
/* GPIOI 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_PinAFConfig(GPIOK, GPIO_PinSource7, GPIO_AF_LTDC);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
GPIO_Pin_4 | GPIO_Pin_5 | 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(GPIOK, &GPIO_InitStruct);
}
4. STM32F429/439的图层是由背景层,图层1和图层2组成,这里配置的是背景层的颜色值,分别配置了R,G,B三原色的数值,范围都是0-255。
5. 信号极性配置,在上面提到的帖子中已经讲解(LTDC时序配置的帖子:http://bbs.armfly.com/read.php?tid=18528),这里不再赘述。
6. 六种显示面板的LTDC输出时钟和时序参数配置,六种面板的识别是在bsp_touch.c文件中实现的。大家自己配置时用不到这个,仅需提供一组时序参数和输出时钟即可,除非项目中需要切换不同显示屏。
7. 这里是7寸面板的LTDC时钟输出配置和时序参数配置,配置方法在上面提到的帖子中已经讲解(LTDC时序配置的帖子:http://bbs.armfly.com/read.php?tid=18528),这里不再赘述,其它面板的设置方法是一样的。时序参数的几个变量Width, Height, HSYNC_W,VSYNC_W, HBP, HFP, VBP, VFP被定义成了全局变量,因为文件LCDConf_Lin_Template.c还要用到。
8. 全局变量g_LcdWidth和g_LcdHeight在文件bsp_tft_lcd.c文件定义。如果大家自己移植时用不到文件bsp_tft_lcd.c的话,需要自行定义这两个全局变量(另外,此文件里面的背光设置函数也要自行实现),因为这两个变量要被文件LCDConf_Lin_Template.c所调用。
9. 等待LTDC输出时钟配置完成。
10. 通过函数LTDC_Init完成时序配置。 |