/** * @brief Initializes the LCD. * @param None * @retval None */ void STM32072B_LCD_Init(void) { /* Configure the LCD Control pins ------------------------------------------*/ LCD_CtrlLinesConfig(); /* Configure the LCD_SPI interface -----------------------------------------*/ LCD_SPIConfig(); LCD_Setup(); LCD_SetFont(&LCD_DEFAULT_FONT); }
/** * @brief Setups the LCD. * @param None * @retval None */ void LCD_Setup(void) { /* Configure the LCD Control pins --------------------------------------------*/ LCD_CtrlLinesConfig(); /* Configure the LCD_SPI interface ----------------------------------------------*/ LCD_SPIConfig(); if(LCDType == LCD_ILI9320) { _delay_(5); /* Delay 50 ms */ /* Start Initial Sequence ------------------------------------------------*/ LCD_WriteReg(LCD_REG_229, 0x8000); /* Set the internal vcore voltage */ LCD_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */ LCD_WriteReg(LCD_REG_1, 0x0100); /* set SS and SM bit */ LCD_WriteReg(LCD_REG_2, 0x0700); /* set 1 line inversion */ LCD_WriteReg(LCD_REG_3, 0x1030); /* set GRAM write direction and BGR=1. */ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */ LCD_WriteReg(LCD_REG_8, 0x0202); /* set the back porch and front porch */ LCD_WriteReg(LCD_REG_9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */ /* Power On sequence -----------------------------------------------------*/ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */ LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */ _delay_(5); /* Delay 50 ms */ LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */ _delay_(5); /* Delay 50 ms */ LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */ LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */ _delay_(5); /* Delay 50 ms */ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */ LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */ /* Adjust the Gamma Curve ------------------------------------------------*/ LCD_WriteReg(LCD_REG_48, 0x0006); LCD_WriteReg(LCD_REG_49, 0x0101); LCD_WriteReg(LCD_REG_50, 0x0003); LCD_WriteReg(LCD_REG_53, 0x0106); LCD_WriteReg(LCD_REG_54, 0x0b02); LCD_WriteReg(LCD_REG_55, 0x0302); LCD_WriteReg(LCD_REG_56, 0x0707); LCD_WriteReg(LCD_REG_57, 0x0007); LCD_WriteReg(LCD_REG_60, 0x0600); LCD_WriteReg(LCD_REG_61, 0x020b); /* Set GRAM area ---------------------------------------------------------*/ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */ LCD_WriteReg(LCD_REG_96, 0x2700); /* Gate Scan Line */ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */ LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */ /* Partial Display Control -----------------------------------------------*/ LCD_WriteReg(LCD_REG_128, 0x0000); LCD_WriteReg(LCD_REG_129, 0x0000); LCD_WriteReg(LCD_REG_130, 0x0000); LCD_WriteReg(LCD_REG_131, 0x0000); LCD_WriteReg(LCD_REG_132, 0x0000); LCD_WriteReg(LCD_REG_133, 0x0000); /* Panel Control ---------------------------------------------------------*/ LCD_WriteReg(LCD_REG_144, 0x0010); LCD_WriteReg(LCD_REG_146, 0x0000); LCD_WriteReg(LCD_REG_147, 0x0003); LCD_WriteReg(LCD_REG_149, 0x0110); LCD_WriteReg(LCD_REG_151, 0x0000); LCD_WriteReg(LCD_REG_152, 0x0000); /* Set GRAM write direction and BGR = 1 */ /* I/D=01 (Horizontal : increment, Vertical : decrement) */ /* AM=1 (address is updated in vertical writing direction) */ LCD_WriteReg(LCD_REG_3, 0x1018); LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */ } else if(LCDType == LCD_SPFD5408) { /* Start Initial Sequence --------------------------------------------------*/ LCD_WriteReg(LCD_REG_227, 0x3008); /* Set internal timing */ LCD_WriteReg(LCD_REG_231, 0x0012); /* Set internal timing */ LCD_WriteReg(LCD_REG_239, 0x1231); /* Set internal timing */ LCD_WriteReg(LCD_REG_1, 0x0100); /* Set SS and SM bit */ LCD_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */ LCD_WriteReg(LCD_REG_3, 0x1030); /* Set GRAM write direction and BGR=1. */ LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */ LCD_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */ LCD_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */ LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */ LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */ LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */ LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */ /* Power On sequence -------------------------------------------------------*/ LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */ LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */ _delay_(20); /* Dis-charge capacitor power voltage (200ms) */ LCD_WriteReg(LCD_REG_17, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */ _delay_(5); /* Delay 50 ms */ LCD_WriteReg(LCD_REG_16, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ _delay_(5); /* Delay 50 ms */ LCD_WriteReg(LCD_REG_18, 0x01BD); /* External reference voltage= Vci */ _delay_(5); /* Delay 50 ms */ LCD_WriteReg(LCD_REG_19, 0x1400); /* VDV[4:0] for VCOM amplitude */ LCD_WriteReg(LCD_REG_41, 0x000E); /* VCM[4:0] for VCOMH */ _delay_(5); /* Delay 50 ms */ LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */ LCD_WriteReg(LCD_REG_33, 0x013F); /* GRAM Vertical Address */ /* Adjust the Gamma Curve --------------------------------------------------*/ LCD_WriteReg(LCD_REG_48, 0x0007); LCD_WriteReg(LCD_REG_49, 0x0302); LCD_WriteReg(LCD_REG_50, 0x0105); LCD_WriteReg(LCD_REG_53, 0x0206); LCD_WriteReg(LCD_REG_54, 0x0808); LCD_WriteReg(LCD_REG_55, 0x0206); LCD_WriteReg(LCD_REG_56, 0x0504); LCD_WriteReg(LCD_REG_57, 0x0007); LCD_WriteReg(LCD_REG_60, 0x0105); LCD_WriteReg(LCD_REG_61, 0x0808); /* Set GRAM area -----------------------------------------------------------*/ LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */ LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */ LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */ LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */ LCD_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line */ LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */ LCD_WriteReg(LCD_REG_106, 0x0000); /* Set scrolling line */ /* Partial Display Control -------------------------------------------------*/ LCD_WriteReg(LCD_REG_128, 0x0000); LCD_WriteReg(LCD_REG_129, 0x0000); LCD_WriteReg(LCD_REG_130, 0x0000); LCD_WriteReg(LCD_REG_131, 0x0000); LCD_WriteReg(LCD_REG_132, 0x0000); LCD_WriteReg(LCD_REG_133, 0x0000); /* Panel Control -----------------------------------------------------------*/ LCD_WriteReg(LCD_REG_144, 0x0010); LCD_WriteReg(LCD_REG_146, 0x0000); LCD_WriteReg(LCD_REG_147, 0x0003); LCD_WriteReg(LCD_REG_149, 0x0110); LCD_WriteReg(LCD_REG_151, 0x0000); LCD_WriteReg(LCD_REG_152, 0x0000); /* Set GRAM write direction and BGR = 1 I/D=01 (Horizontal : increment, Vertical : decrement) AM=1 (address is updated in vertical writing direction) */ LCD_WriteReg(LCD_REG_3, 0x1018); LCD_WriteReg(LCD_REG_7, 0x0112); /* 262K color and display ON */ } else if(LCDType == LCD_HX8347D) { /* Driving ability setting */ LCD_WriteReg(LCD_REG_234, 0x00); LCD_WriteReg(LCD_REG_235, 0x20); LCD_WriteReg(LCD_REG_236, 0x0C); LCD_WriteReg(LCD_REG_237, 0xC4); LCD_WriteReg(LCD_REG_232, 0x40); LCD_WriteReg(LCD_REG_233, 0x38); LCD_WriteReg(LCD_REG_241, 0x01); LCD_WriteReg(LCD_REG_242, 0x10); LCD_WriteReg(LCD_REG_39, 0xA3); /* Adjust the Gamma Curve */ LCD_WriteReg(LCD_REG_64, 0x01); LCD_WriteReg(LCD_REG_65, 0x00); LCD_WriteReg(LCD_REG_66, 0x00); LCD_WriteReg(LCD_REG_67, 0x10); LCD_WriteReg(LCD_REG_68, 0x0E); LCD_WriteReg(LCD_REG_69, 0x24); LCD_WriteReg(LCD_REG_70, 0x04); LCD_WriteReg(LCD_REG_71, 0x50); LCD_WriteReg(LCD_REG_72, 0x02); LCD_WriteReg(LCD_REG_73, 0x13); LCD_WriteReg(LCD_REG_74, 0x19); LCD_WriteReg(LCD_REG_75, 0x19); LCD_WriteReg(LCD_REG_76, 0x16); LCD_WriteReg(LCD_REG_80, 0x1B); LCD_WriteReg(LCD_REG_81, 0x31); LCD_WriteReg(LCD_REG_82, 0x2F); LCD_WriteReg(LCD_REG_83, 0x3F); LCD_WriteReg(LCD_REG_84, 0x3F); LCD_WriteReg(LCD_REG_85, 0x3E); LCD_WriteReg(LCD_REG_86, 0x2F); LCD_WriteReg(LCD_REG_87, 0x7B); LCD_WriteReg(LCD_REG_88, 0x09); LCD_WriteReg(LCD_REG_89, 0x06); LCD_WriteReg(LCD_REG_90, 0x06); LCD_WriteReg(LCD_REG_91, 0x0C); LCD_WriteReg(LCD_REG_92, 0x1D); LCD_WriteReg(LCD_REG_93, 0xCC); /* Power voltage setting */ LCD_WriteReg(LCD_REG_27, 0x1B); LCD_WriteReg(LCD_REG_26, 0x01); LCD_WriteReg(LCD_REG_36, 0x2F); LCD_WriteReg(LCD_REG_37, 0x57); /*****VCOM offset ****/ LCD_WriteReg(LCD_REG_35, 0x86); /* Power on setting up flow */ LCD_WriteReg(LCD_REG_24, 0x36); /* Display frame rate = 70Hz RADJ = '0110' */ LCD_WriteReg(LCD_REG_25, 0x01); /* OSC_EN = 1 */ LCD_WriteReg(LCD_REG_28, 0x06); /* AP[2:0] = 111 */ LCD_WriteReg(LCD_REG_29, 0x06); /* AP[2:0] = 111 */ LCD_WriteReg(LCD_REG_31,0x90); /* GAS=1, VOMG=00, PON=1, DK=0, XDK=0, DVDH_TRI=0, STB=0*/ LCD_WriteReg(LCD_REG_39, 1); /* REF = 1 */ _delay_(10); /* 262k/65k color selection */ LCD_WriteReg(LCD_REG_23, 0x05); /* default 0x06 262k color, 0x05 65k color */ /* SET PANEL */ LCD_WriteReg(LCD_REG_54, 0x09); /* SS_PANEL = 1, GS_PANEL = 0,REV_PANEL = 0, BGR_PANEL = 1 */ /* Display ON flow */ LCD_WriteReg(LCD_REG_40, 0x38); /* GON=1, DTE=1, D=10 */ _delay_(60); LCD_WriteReg(LCD_REG_40, 0x3C); /* GON=1, DTE=1, D=11 */ /* Set GRAM Area - Partial Display Control */ LCD_WriteReg(LCD_REG_1, 0x00); /* DP_STB = 0, DP_STB_S = 0, SCROLL = 0, */ LCD_WriteReg(LCD_REG_2, 0x00); /* Column address start 2 */ LCD_WriteReg(LCD_REG_3, 0x00); /* Column address start 1 */ LCD_WriteReg(LCD_REG_4, 0x01); /* Column address end 2 */ LCD_WriteReg(LCD_REG_5, 0x3F); /* Column address end 1 */ LCD_WriteReg(LCD_REG_6, 0x00); /* Row address start 2 */ LCD_WriteReg(LCD_REG_7, 0x00); /* Row address start 2 */ LCD_WriteReg(LCD_REG_8, 0x00); /* Row address end 2 */ LCD_WriteReg(LCD_REG_9, 0xEF); /* Row address end 1 */ LCD_WriteReg(LCD_REG_22, 0xE0); /* Memory access control: MY = 1, MX = 0, MV = 1, ML = 0 */ } /* Set default font */ LCD_SetFont(&LCD_DEFAULT_FONT); }
/******************************************************************************* * Function Name : LCD_Setup * Description : Setups the LCD. * Input : None * Output : None * Return : None *******************************************************************************/ void LCD_Setup(void) { /* Configure the LCD Control pins --------------------------------------------*/ LCD_CtrlLinesConfig(); /* Configure the SPI3 interface ----------------------------------------------*/ LCD_SPIConfig(); timerDly(5); /* Delay 50 ms */ /* Start Initial Sequence ------------------------------------------------*/ LCD_WriteReg(R229, 0x8000); /* Set the internal vcore voltage */ LCD_WriteReg(R0, 0x0001); /* Start internal OSC. */ LCD_WriteReg(R1, 0x0100); /* set SS and SM bit */ LCD_WriteReg(R2, 0x0700); /* set 1 line inversion */ LCD_WriteReg(R3, 0x1030); /* set GRAM write direction and BGR=1. */ LCD_WriteReg(R4, 0x0000); /* Resize register */ LCD_WriteReg(R8, 0x0202); /* set the back porch and front porch */ LCD_WriteReg(R9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */ LCD_WriteReg(R10, 0x0000); /* FMARK function */ LCD_WriteReg(R12, 0x0000); /* RGB interface setting */ LCD_WriteReg(R13, 0x0000); /* Frame marker Position */ LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */ /* Power On sequence -----------------------------------------------------*/ LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */ LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */ timerDly(20); /* Dis-charge capacitor power voltage (200ms) */ LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */ timerDly(5); /* Delay 50 ms */ LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */ timerDly(5); /* Delay 50 ms */ LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */ LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */ timerDly(5); /* Delay 50 ms */ LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */ LCD_WriteReg(R33, 0x0000); /* GRAM Vertical Address */ /* Adjust the Gamma Curve ------------------------------------------------*/ LCD_WriteReg(R48, 0x0006); LCD_WriteReg(R49, 0x0101); LCD_WriteReg(R50, 0x0003); LCD_WriteReg(R53, 0x0106); LCD_WriteReg(R54, 0x0b02); LCD_WriteReg(R55, 0x0302); LCD_WriteReg(R56, 0x0707); LCD_WriteReg(R57, 0x0007); LCD_WriteReg(R60, 0x0600); LCD_WriteReg(R61, 0x020b); /* Set GRAM area ---------------------------------------------------------*/ LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */ LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */ LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */ LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */ LCD_WriteReg(R96, 0x2700); /* Gate Scan Line */ LCD_WriteReg(R97, 0x0001); /* NDL,VLE, REV */ LCD_WriteReg(R106, 0x0000); /* set scrolling line */ /* Partial Display Control -----------------------------------------------*/ LCD_WriteReg(R128, 0x0000); LCD_WriteReg(R129, 0x0000); LCD_WriteReg(R130, 0x0000); LCD_WriteReg(R131, 0x0000); LCD_WriteReg(R132, 0x0000); LCD_WriteReg(R133, 0x0000); /* Panel Control ---------------------------------------------------------*/ LCD_WriteReg(R144, 0x0010); LCD_WriteReg(R146, 0x0000); LCD_WriteReg(R147, 0x0003); LCD_WriteReg(R149, 0x0110); LCD_WriteReg(R151, 0x0000); LCD_WriteReg(R152, 0x0000); /* Set GRAM write direction and BGR = 1 */ /* I/D=01 (Horizontal : increment, Vertical : decrement) */ /* AM=1 (address is updated in vertical writing direction) */ LCD_WriteReg(R3, 0x1018); LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */ }
/******************************************************************************* * Function Name : LCD_Setup * Description : Setups the LCD. * Input : None * Output : None * Return : None *******************************************************************************/ void LCD_Setup(void) { /* Configure the LCD Control pins --------------------------------------------*/ LCD_CtrlLinesConfig(); /* Configure the SPI2 interface ----------------------------------------------*/ LCD_SPIConfig(); if(LCDType == LCD_ILI9320) { Delay(5); /* Delay 50 ms */ /* Start Initial Sequence ------------------------------------------------*/ LCD_WriteReg(R229, 0x8000); /* Set the internal vcore voltage */ LCD_WriteReg(R0, 0x0001); /* Start internal OSC. */ LCD_WriteReg(R1, 0x0100); /* set SS and SM bit */ LCD_WriteReg(R2, 0x0700); /* set 1 line inversion */ LCD_WriteReg(R3, 0x1030); /* set GRAM write direction and BGR=1. */ LCD_WriteReg(R4, 0x0000); /* Resize register */ LCD_WriteReg(R8, 0x0202); /* set the back porch and front porch */ LCD_WriteReg(R9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */ LCD_WriteReg(R10, 0x0000); /* FMARK function */ LCD_WriteReg(R12, 0x0000); /* RGB interface setting */ LCD_WriteReg(R13, 0x0000); /* Frame marker Position */ LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */ /* Power On sequence -----------------------------------------------------*/ LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */ LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */ Delay(20); /* Dis-charge capacitor power voltage (200ms) */ LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */ Delay(5); /* Delay 50 ms */ LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */ Delay(5); /* Delay 50 ms */ LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */ LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */ Delay(5); /* Delay 50 ms */ LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */ LCD_WriteReg(R33, 0x0000); /* GRAM Vertical Address */ /* Adjust the Gamma Curve ------------------------------------------------*/ LCD_WriteReg(R48, 0x0006); LCD_WriteReg(R49, 0x0101); LCD_WriteReg(R50, 0x0003); LCD_WriteReg(R53, 0x0106); LCD_WriteReg(R54, 0x0b02); LCD_WriteReg(R55, 0x0302); LCD_WriteReg(R56, 0x0707); LCD_WriteReg(R57, 0x0007); LCD_WriteReg(R60, 0x0600); LCD_WriteReg(R61, 0x020b); /* Set GRAM area ---------------------------------------------------------*/ LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */ LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */ LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */ LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */ LCD_WriteReg(R96, 0x2700); /* Gate Scan Line */ LCD_WriteReg(R97, 0x0001); /* NDL,VLE, REV */ LCD_WriteReg(R106, 0x0000); /* set scrolling line */ /* Partial Display Control -----------------------------------------------*/ LCD_WriteReg(R128, 0x0000); LCD_WriteReg(R129, 0x0000); LCD_WriteReg(R130, 0x0000); LCD_WriteReg(R131, 0x0000); LCD_WriteReg(R132, 0x0000); LCD_WriteReg(R133, 0x0000); /* Panel Control ---------------------------------------------------------*/ LCD_WriteReg(R144, 0x0010); LCD_WriteReg(R146, 0x0000); LCD_WriteReg(R147, 0x0003); LCD_WriteReg(R149, 0x0110); LCD_WriteReg(R151, 0x0000); LCD_WriteReg(R152, 0x0000); /* Set GRAM write direction and BGR = 1 */ /* I/D=01 (Horizontal : increment, Vertical : decrement) */ /* AM=1 (address is updated in vertical writing direction) */ LCD_WriteReg(R3, 0x1018); LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */ } else if(LCDType == LCD_SPFD5408) { /* Start Initial Sequence --------------------------------------------------*/ LCD_WriteReg(R227, 0x3008); /* Set internal timing */ LCD_WriteReg(R231, 0x0012); /* Set internal timing */ LCD_WriteReg(R239, 0x1231); /* Set internal timing */ LCD_WriteReg(R1, 0x0100); /* Set SS and SM bit */ LCD_WriteReg(R2, 0x0700); /* Set 1 line inversion */ LCD_WriteReg(R3, 0x1030); /* Set GRAM write direction and BGR=1. */ LCD_WriteReg(R4, 0x0000); /* Resize register */ LCD_WriteReg(R8, 0x0202); /* Set the back porch and front porch */ LCD_WriteReg(R9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */ LCD_WriteReg(R10, 0x0000); /* FMARK function */ LCD_WriteReg(R12, 0x0000); /* RGB interface setting */ LCD_WriteReg(R13, 0x0000); /* Frame marker Position */ LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */ /* Power On sequence -------------------------------------------------------*/ LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */ LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */ Delay(20); /* Dis-charge capacitor power voltage (200ms) */ LCD_WriteReg(R17, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */ Delay(5); /* Delay 50 ms */ LCD_WriteReg(R16, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ Delay(5); /* Delay 50 ms */ LCD_WriteReg(R18, 0x01BD); /* External reference voltage= Vci */ Delay(5); /* Delay 50 ms */ LCD_WriteReg(R19, 0x1400); /* VDV[4:0] for VCOM amplitude */ LCD_WriteReg(R41, 0x000E); /* VCM[4:0] for VCOMH */ Delay(5); /* Delay 50 ms */ LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */ LCD_WriteReg(R33, 0x013F); /* GRAM Vertical Address */ /* Adjust the Gamma Curve --------------------------------------------------*/ LCD_WriteReg(R48, 0x0007); LCD_WriteReg(R49, 0x0302); LCD_WriteReg(R50, 0x0105); LCD_WriteReg(R53, 0x0206); LCD_WriteReg(R54, 0x0808); LCD_WriteReg(R55, 0x0206); LCD_WriteReg(R56, 0x0504); LCD_WriteReg(R57, 0x0007); LCD_WriteReg(R60, 0x0105); LCD_WriteReg(R61, 0x0808); /* Set GRAM area -----------------------------------------------------------*/ LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */ LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */ LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */ LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */ LCD_WriteReg(R96, 0xA700); /* Gate Scan Line */ LCD_WriteReg(R97, 0x0001); /* NDL,VLE, REV */ LCD_WriteReg(R106, 0x0000); /* Set scrolling line */ /* Partial Display Control -------------------------------------------------*/ LCD_WriteReg(R128, 0x0000); LCD_WriteReg(R129, 0x0000); LCD_WriteReg(R130, 0x0000); LCD_WriteReg(R131, 0x0000); LCD_WriteReg(R132, 0x0000); LCD_WriteReg(R133, 0x0000); /* Panel Control -----------------------------------------------------------*/ LCD_WriteReg(R144, 0x0010); LCD_WriteReg(R146, 0x0000); LCD_WriteReg(R147, 0x0003); LCD_WriteReg(R149, 0x0110); LCD_WriteReg(R151, 0x0000); LCD_WriteReg(R152, 0x0000); /* Set GRAM write direction and BGR = 1 I/D=01 (Horizontal : increment, Vertical : decrement) AM=1 (address is updated in vertical writing direction) */ LCD_WriteReg(R3, 0x1018); LCD_WriteReg(R7, 0x0112); /* 262K color and display ON */ } else if(LCDType == LCD_HX8312) { /* Enable the LCD Oscillator ---------------------------------------------*/ LCD_WriteReg(R1, 0x10); LCD_WriteReg(R0, 0xA0); LCD_WriteReg(R3, 0x01); Delay(1); /* Delay 10 ms */ LCD_WriteReg(R3, 0x00); LCD_WriteReg(R43, 0x04); LCD_WriteReg(R40, 0x18); LCD_WriteReg(R26, 0x05); LCD_WriteReg(R37, 0x05); LCD_WriteReg(R25, 0x00); /* LCD Power On ----------------------------------------------------------*/ LCD_WriteReg(R28, 0x73); LCD_WriteReg(R36, 0x74); LCD_WriteReg(R30, 0x01); LCD_WriteReg(R24, 0xC1); Delay(1); /* Delay 10 ms */ LCD_WriteReg(R24, 0xE1); LCD_WriteReg(R24, 0xF1); Delay(6); /* Delay 60 ms */ LCD_WriteReg(R24, 0xF5); Delay(6); /* Delay 60 ms */ LCD_WriteReg(R27, 0x09); Delay(1); /* Delay 10 ms */ LCD_WriteReg(R31, 0x11); LCD_WriteReg(R32, 0x0E); LCD_WriteReg(R30, 0x81); Delay(1); /* Delay 10 ms */ /* Chip Set --------------------------------------------------------------*/ LCD_WriteReg(R157, 0x00); LCD_WriteReg(R192, 0x00); LCD_WriteReg(R14, 0x00); LCD_WriteReg(R15, 0x00); LCD_WriteReg(R16, 0x00); LCD_WriteReg(R17, 0x00); LCD_WriteReg(R18, 0x00); LCD_WriteReg(R19, 0x00); LCD_WriteReg(R20, 0x00); LCD_WriteReg(R21, 0x00); LCD_WriteReg(R22, 0x00); LCD_WriteReg(R23, 0x00); LCD_WriteReg(R52, 0x01); LCD_WriteReg(R53, 0x00); LCD_WriteReg(R75, 0x00); LCD_WriteReg(R76, 0x00); LCD_WriteReg(R78, 0x00); LCD_WriteReg(R79, 0x00); LCD_WriteReg(R80, 0x00); LCD_WriteReg(R60, 0x00); LCD_WriteReg(R61, 0x00); LCD_WriteReg(R62, 0x01); LCD_WriteReg(R63, 0x3F); LCD_WriteReg(R64, 0x02); LCD_WriteReg(R65, 0x02); LCD_WriteReg(R66, 0x00); LCD_WriteReg(R67, 0x00); LCD_WriteReg(R68, 0x00); LCD_WriteReg(R69, 0x00); LCD_WriteReg(R70, 0xEF); LCD_WriteReg(R71, 0x00); LCD_WriteReg(R72, 0x00); LCD_WriteReg(R73, 0x01); LCD_WriteReg(R74, 0x3F); LCD_WriteReg(R29, 0x08); /* R29:Gate scan direction setting */ LCD_WriteReg(R134, 0x00); LCD_WriteReg(R135, 0x30); LCD_WriteReg(R136, 0x02); LCD_WriteReg(R137, 0x05); LCD_WriteReg(R141, 0x01); /* R141:Register set-up mode for one line clock */ LCD_WriteReg(R139, 0x20); /* R139:One line SYSCLK number in one-line */ LCD_WriteReg(R51, 0x01); /* R51:N line inversion setting */ LCD_WriteReg(R55, 0x01); /* R55:Scanning method setting */ LCD_WriteReg(R118, 0x00); /* Gamma Set -------------------------------------------------------------*/ LCD_WriteReg(R143, 0x10); LCD_WriteReg(R144, 0x67); LCD_WriteReg(R145, 0x07); LCD_WriteReg(R146, 0x65); LCD_WriteReg(R147, 0x07); LCD_WriteReg(R148, 0x01); LCD_WriteReg(R149, 0x76); LCD_WriteReg(R150, 0x56); LCD_WriteReg(R151, 0x00); LCD_WriteReg(R152, 0x06); LCD_WriteReg(R153, 0x03); LCD_WriteReg(R154, 0x00); /* Display On ------------------------------------------------------------*/ LCD_WriteReg(R1, 0x50); LCD_WriteReg(R5, 0x04); LCD_WriteReg(R0, 0x80); LCD_WriteReg(R59, 0x01); Delay(4); /* Delay 40 ms */ LCD_WriteReg(R0, 0x20); } }
LCDTFTConf::LCDTFTConf() { CurrentFrameBuffer = LCD_FRAME_BUFFER; CurrentLayer = LCD_BACKGROUND_LAYER; LTDC_InitTypeDef LTDC_InitStruct; /* Configure the LCD Control pins ------------------------------------------*/ LCD_CtrlLinesConfig(); LCD_ChipSelect(DISABLE); LCD_ChipSelect(ENABLE); /* Configure the LCD_SPI interface -----------------------------------------*/ LCD_SPIConfig(); /* Power on the LCD --------------------------------------------------------*/ LCD_PowerOn(); /* 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(); /* Configure the FMC Parallel interface : SDRAM is used as Frame Buffer for LCD */ SDRAM_Init(); /* LTDC Configuration *********************************************************/ /* 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 */ /* Enable Pixel Clock */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAI_R = 192/4 = 48 Mhz */ /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 48/8 = 6 Mhz */ RCC_PLLSAIConfig(192, 7, 4); RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8); /* Enable PLLSAI Clock */ RCC_PLLSAICmd(ENABLE); /* Wait for PLLSAI activation */ while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET); /* Timing configuration */ /* Configure horizontal synchronization width */ LTDC_InitStruct.LTDC_HorizontalSync = 9; /* Configure vertical synchronization height */ LTDC_InitStruct.LTDC_VerticalSync = 1; /* Configure accumulated horizontal back porch */ LTDC_InitStruct.LTDC_AccumulatedHBP = 29; /* Configure accumulated vertical back porch */ LTDC_InitStruct.LTDC_AccumulatedVBP = 3; /* Configure accumulated active width */ LTDC_InitStruct.LTDC_AccumulatedActiveW = 269; /* Configure accumulated active height */ LTDC_InitStruct.LTDC_AccumulatedActiveH = 323; /* Configure total width */ LTDC_InitStruct.LTDC_TotalWidth = 279; /* Configure total height */ LTDC_InitStruct.LTDC_TotalHeigh = 327; LTDC_Init(<DC_InitStruct); LCD_LayerInit(); /* LTDC reload configuration */ LTDC_ReloadConfig(LTDC_IMReload); /* Enable the LTDC */ LTDC_Cmd(ENABLE); }
static void LCD_Config(void) { LTDC_InitTypeDef LTDC_InitStruct; LTDC_Layer_InitTypeDef LTDC_Layer_InitStruct; GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /* Configure NCS in Output Push-Pull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); /* Configure the LCD Control pins ------------------------------------------*/ LCD_CtrlLinesConfig(); LCD_ChipSelect(DISABLE); LCD_ChipSelect(ENABLE); /* Configure the LCD_SPI interface -----------------------------------------*/ LCD_SPIConfig(); /* Power on the LCD --------------------------------------------------------*/ LCD_PowerOn(); /* 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(); /* Configure the FMC Parallel interface : SDRAM is used as Frame Buffer for LCD */ SDRAM_Init(); /* Enable Pixel Clock --------------------------------------------------------*/ /* Configure PLLSAI prescalers for LCD */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAI_R = 192/3 = 64 Mhz */ /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64/8 = 8 Mhz */ 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) { } /* LTDC Initialization -------------------------------------------------------*/ /* 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; /* Timing configuration */ /* Configure horizontal synchronization width */ LTDC_InitStruct.LTDC_HorizontalSync = 9; /* Configure vertical synchronization height */ LTDC_InitStruct.LTDC_VerticalSync = 1; /* Configure accumulated horizontal back porch */ LTDC_InitStruct.LTDC_AccumulatedHBP = 29; /* Configure accumulated vertical back porch */ LTDC_InitStruct.LTDC_AccumulatedVBP = 3; /* Configure accumulated active width */ LTDC_InitStruct.LTDC_AccumulatedActiveW = 269; /* Configure accumulated active height */ LTDC_InitStruct.LTDC_AccumulatedActiveH = 323; /* Configure total width */ LTDC_InitStruct.LTDC_TotalWidth = 279; /* Configure total height */ LTDC_InitStruct.LTDC_TotalHeigh = 327; LTDC_Init(<DC_InitStruct); /* 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; LTDC_Init(<DC_InitStruct); /* LTDC initialization end ---------------------------------------------------*/ /* Layer1 Configuration ------------------------------------------------------*/ /* 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 = 30; LTDC_Layer_InitStruct.LTDC_HorizontalStop = (240 + 30 - 1); LTDC_Layer_InitStruct.LTDC_VerticalStart = 4; LTDC_Layer_InitStruct.LTDC_VerticalStop = (320 + 4 - 1); /* Pixel Format configuration*/ LTDC_Layer_InitStruct.LTDC_PixelFormat = LTDC_Pixelformat_RGB565; /* Alpha constant (255 totally opaque) */ LTDC_Layer_InitStruct.LTDC_ConstantAlpha = 255; /* Configure blending factors */ LTDC_Layer_InitStruct.LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_CA; LTDC_Layer_InitStruct.LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_CA; /* 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; /* Input Address configuration */ LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (uint32_t)&RGB565_240x320; /* 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 = 240 number of bytes per pixel = 2 (pixel_format : RGB565) */ LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((240 * 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 = (240 * 2); /* configure the number of lines */ LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 320; LTDC_LayerInit(LTDC_Layer1, <DC_Layer_InitStruct); LTDC_DitherCmd(ENABLE); }