⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 手机lcd驱动代码
💻 C
字号:


void LCD_Init_MC2TA7402(kal_uint32 bkground, void **buf_addr)
{
    lcd_check = 0;
  
    SET_LCD_CTRL_RESET_PIN;
    LCD_Delay(0x10);
    CLEAR_LCD_CTRL_RESET_PIN;
    LCD_Delay(0x1000);
    SET_LCD_CTRL_RESET_PIN;
    LCD_Delay(0x1000);
 #if 0 //sva's   
    LCD_set_reg(0x0007,0x0804);
    
    LCD_set_reg(0x0011,0x3C04);
    LCD_set_reg(0x0014,0x201d);
    LCD_Delay(0x200);//10ms
    
    LCD_set_reg(0x0010,0x1e80);
    LCD_set_reg(0x0013,0x0040);   
    LCD_Delay(0x800);	//40ms
    LCD_set_reg(0x0013,0x0060);
    LCD_Delay(0x800);	//40ms
    LCD_set_reg(0x0013,0x0070);
    LCD_Delay(0x400);	//40ms	
    /*display init */
    LCD_set_reg(0x0001,0x011b);
    LCD_set_reg(0x0002,0x0700);
    LCD_set_reg(0x0003,0x1030);
    LCD_set_reg(0x0008,0x0202);
    LCD_set_reg(0x0009,0x0000);
    LCD_set_reg(0x000b,0x3001);
    LCD_set_reg(0x000c,0x0000);
    /*gamma adjustment*/
    LCD_set_reg(0x0030,0x0000);
    LCD_set_reg(0x0031,0x0306);
    LCD_set_reg(0x0032,0x0203);
    LCD_set_reg(0x0033,0x0001);
    LCD_set_reg(0x0034,0x0405);
    LCD_set_reg(0x0035,0x0104);
    LCD_set_reg(0x0036,0x0707);
    LCD_set_reg(0x0037,0x0100);
    LCD_set_reg(0x0038,0x1f00);
    LCD_set_reg(0x0039,0x1f00);
    /* Coordinate init */
    LCD_set_reg(0x0040,0x0000);
    LCD_set_reg(0x0042,0xdb00);
    LCD_set_reg(0x0043,0xdb00);
    LCD_set_reg(0x0044,0xaf00);
    LCD_set_reg(0x0045,0xdb00);
    /* Ram address Set */
    LCD_set_reg(0x0021,0x0000);
    /* Display on */
    LCD_set_reg(0x0010,0x1e80);
    LCD_set_reg(0x0007,0x0816);
    LCD_Delay(0x400);	//20ms
    LCD_set_reg(0x0007,0x0817);
    LCD_Delay(0x600);	//30ms
    LCD_CtrlWrite_MC2TA7402(0x0022);
    			/* delay 30ms */
 #else
      LCD_CtrlWrite_MC2TA7402(0x0001);LCD_DataWrite_MC2TA7402(0x091B);  
     LCD_CtrlWrite_MC2TA7402(0x0002);LCD_DataWrite_MC2TA7402(0x0700);  
     LCD_CtrlWrite_MC2TA7402(0x0003);LCD_DataWrite_MC2TA7402(0x5030);  
     LCD_CtrlWrite_MC2TA7402(0x0007);LCD_DataWrite_MC2TA7402(0x0004);  
     LCD_CtrlWrite_MC2TA7402(0x0008);LCD_DataWrite_MC2TA7402(0x040C);  
     LCD_CtrlWrite_MC2TA7402(0x0009);LCD_DataWrite_MC2TA7402(0x0041);  
     LCD_CtrlWrite_MC2TA7402(0x000B);LCD_DataWrite_MC2TA7402(0xF002);  
     LCD_CtrlWrite_MC2TA7402(0x000C);LCD_DataWrite_MC2TA7402(0x0001);  
     LCD_CtrlWrite_MC2TA7402(0x0014);LCD_DataWrite_MC2TA7402(0x0F0B);  
     LCD_CtrlWrite_MC2TA7402(0x0021);LCD_DataWrite_MC2TA7402(0x0000);  
     LCD_CtrlWrite_MC2TA7402(0x0030);LCD_DataWrite_MC2TA7402(0x0300);  
     LCD_CtrlWrite_MC2TA7402(0x0031);LCD_DataWrite_MC2TA7402(0x0007);  
     LCD_CtrlWrite_MC2TA7402(0x0032);LCD_DataWrite_MC2TA7402(0x0000);  
     LCD_CtrlWrite_MC2TA7402(0x0033);LCD_DataWrite_MC2TA7402(0x0407);  
     LCD_CtrlWrite_MC2TA7402(0x0034);LCD_DataWrite_MC2TA7402(0x0200);  
     LCD_CtrlWrite_MC2TA7402(0x0035);LCD_DataWrite_MC2TA7402(0x0003);  
     LCD_CtrlWrite_MC2TA7402(0x0036);LCD_DataWrite_MC2TA7402(0x0307);  
     LCD_CtrlWrite_MC2TA7402(0x0037);LCD_DataWrite_MC2TA7402(0x0101);  
     LCD_CtrlWrite_MC2TA7402(0x0038);LCD_DataWrite_MC2TA7402(0x1F07);  
     LCD_CtrlWrite_MC2TA7402(0x0039);LCD_DataWrite_MC2TA7402(0x0C04);  
     LCD_CtrlWrite_MC2TA7402(0x0040);LCD_DataWrite_MC2TA7402(0x0000);  
     LCD_CtrlWrite_MC2TA7402(0x0041);LCD_DataWrite_MC2TA7402(0x0000);  
     LCD_CtrlWrite_MC2TA7402(0x0042);LCD_DataWrite_MC2TA7402(0xEB00);  
     LCD_CtrlWrite_MC2TA7402(0x0043);LCD_DataWrite_MC2TA7402(0xFFFF);  
     LCD_CtrlWrite_MC2TA7402(0x0044);LCD_DataWrite_MC2TA7402(0xAF00);  
     LCD_CtrlWrite_MC2TA7402(0x0045);LCD_DataWrite_MC2TA7402(0xDB00);  
     LCD_CtrlWrite_MC2TA7402(0x0053);LCD_DataWrite_MC2TA7402(0x0000);  
     LCD_CtrlWrite_MC2TA7402(0x0059);LCD_DataWrite_MC2TA7402(0x0003);  
     LCD_CtrlWrite_MC2TA7402(0x005A);LCD_DataWrite_MC2TA7402(0x0000);  
     LCD_CtrlWrite_MC2TA7402(0x0011);LCD_DataWrite_MC2TA7402(0x2F04);
     LCD_Delay(0x200);//10ms
     LCD_CtrlWrite_MC2TA7402(0x0010);LCD_DataWrite_MC2TA7402(0x0580);  
     LCD_CtrlWrite_MC2TA7402(0x0013);LCD_DataWrite_MC2TA7402(0x0040);  
     LCD_Delay(0x800); //40ms
     LCD_CtrlWrite_MC2TA7402(0x0013);LCD_DataWrite_MC2TA7402(0x0060);  
     LCD_Delay(0x800); //40ms
     LCD_CtrlWrite_MC2TA7402(0x0013);LCD_DataWrite_MC2TA7402(0x0070);  
     LCD_Delay(0x10);
     LCD_CtrlWrite_MC2TA7402(0x0011);LCD_DataWrite_MC2TA7402(0x2E01);  
     LCD_Delay(0x200);//10ms
     LCD_CtrlWrite_MC2TA7402(0x0010);LCD_DataWrite_MC2TA7402(0x0E00);  
     LCD_CtrlWrite_MC2TA7402(0x0007);LCD_DataWrite_MC2TA7402(0x0004);  
     LCD_CtrlWrite_MC2TA7402(0x0007);LCD_DataWrite_MC2TA7402(0x0016);
     LCD_Delay(0x800);  //40ms
     LCD_CtrlWrite_MC2TA7402(0x0007);LCD_DataWrite_MC2TA7402(0x0017);  
     LCD_Delay(0x800); //40ms
     LCD_CtrlWrite_MC2TA7402(0x0021);LCD_DataWrite_MC2TA7402(0x0000);    
     LCD_CtrlWrite_MC2TA7402(0x0022);    
 #endif   
    LCD_ClearAll_MC2TA7402(0x07E0);

    LCD_Delay(0x80000);

    lcd_check = 1;
}

void LCD_PWRON_MC2TA7402(kal_bool on)
{
}

void LCD_SetContrast_MC2TA7402(kal_uint8 level)
{
}

void LCD_ON_MC2TA7402(kal_bool on)
{
}

void LCD_BlockWrite_MC2TA7402(kal_uint16 startx,kal_uint16 starty,kal_uint16 endx,kal_uint16 endy)
{
	while (LCD_IS_RUNNING);

//   ASSERT(lcd_assert_fail==KAL_FALSE);
    lcd_assert_fail = KAL_TRUE;
	#ifdef LCD_CMD_DMA_MODE
		#if (defined(LCD_8BIT_MODE))
		#elif (defined(LCD_9BIT_MODE))
		#elif (defined(LCD_16BIT_MODE))
			//SET_LCD_CMD_PARAMETER(0,LCD_CMD,((((kal_uint32)0x42) & 0xFF00)|((((kal_uint32)0x42)&0xFF))));
			//SET_LCD_CMD_PARAMETER(1,LCD_DATA,(((((kal_uint32)endx) & 0xFF)<<7) |(((kal_uint32)startx)&0xFF)));
			//SET_LCD_CMD_PARAMETER(2,LCD_CMD,((((kal_uint32)0x43) & 0xFF00)|((((kal_uint32)0x43)&0xFF))));
			//SET_LCD_CMD_PARAMETER(3,LCD_DATA,(((((kal_uint32)endx) & 0xFF)<<7) |(((kal_uint32)startx)&0xFF)));
			
			SET_LCD_CMD_PARAMETER(0,LCD_CMD,((((kal_uint32)0x44) & 0xFF00)|((((kal_uint32)0x44)&0xFF))));
			SET_LCD_CMD_PARAMETER(1,LCD_DATA,(((((kal_uint32)endx) & 0xFF)<<8) |(((kal_uint32)startx)&0xFF)));
			//SET_LCD_CMD_PARAMETER(1,LCD_DATA,0xaf00);
			SET_LCD_CMD_PARAMETER(2,LCD_CMD,((((kal_uint32)0x45) & 0xFF00)|(((kal_uint32)0x45)&0xFF)));
			SET_LCD_CMD_PARAMETER(3,LCD_DATA,(((((kal_uint32)endy) & 0xFF)<<8)|(((kal_uint32)starty)&0xFF)));
			//SET_LCD_CMD_PARAMETER(3,LCD_DATA,0xdb00);
			
			SET_LCD_CMD_PARAMETER(4,LCD_CMD,((((kal_uint32)0x21) & 0xFF00)|(((kal_uint32)0x21)&0xFF)));
			SET_LCD_CMD_PARAMETER(5,LCD_DATA,(((((kal_uint32)starty) & 0x00FF)<<8)|(((kal_uint32)startx)&0xFF)));
			//SET_LCD_CMD_PARAMETER(5,LCD_DATA,0xdbaf);
			SET_LCD_CMD_PARAMETER(6,LCD_CMD,((((kal_uint32)0x22) & 0xFF00)|(((kal_uint32)0x22)&0xFF)));
			
		#elif (defined(LCD_18BIT_MODE))
		#endif
		ENABLE_LCD_TRANSFER_COMPLETE_INT;
		ENABLE_LCD_ROI_CTRL_CMD_FIRST;
		SET_LCD_ROI_CTRL_NUMBER_OF_CMD(7);
		START_LCD_TRANSFER;
	#else   /* LCD_CMD_DMA_MODE */
		LCD_CtrlWrite_MC2TA7402(0x0050);
		LCD_DataWrite_MC2TA7402(startx);
		LCD_CtrlWrite_MC2TA7402(0x0051);
		LCD_DataWrite_MC2TA7402(endx);
		LCD_CtrlWrite_MC2TA7402(0x0052);
		LCD_DataWrite_MC2TA7402(starty);
		LCD_CtrlWrite_MC2TA7402(0x0053);
		LCD_DataWrite_MC2TA7402(endy);
		LCD_CtrlWrite_MC2TA7402(0x0020);
		LCD_DataWrite_MC2TA7402(startx);
		LCD_CtrlWrite_MC2TA7402(0x0021);
		LCD_DataWrite_MC2TA7402(starty);
		LCD_CtrlWrite_MC2TA7402(0x0022);

		DISABLE_LCD_TRANSFER_COMPLETE_INT;
		DISABLE_LCD_ROI_CTRL_CMD_FIRST;
		START_LCD_TRANSFER;
    #endif /* LCD_CMD_DMA_MODE */

    lcd_assert_fail = KAL_FALSE;
}

void LCD_Size_MC2TA7402(kal_uint16 *out_LCD_width, kal_uint16 *out_LCD_height)
{
   	*out_LCD_width = LCD_WIDTH;
   	*out_LCD_height = LCD_HEIGHT;
}

/*Engineering mode*/
kal_uint8 LCD_GetParm_MC2TA7402(lcd_func_type type)
{
    switch(type) {
    case lcd_Bais_func:
        return 1;

    case lcd_Contrast_func:
        return 1;

    case lcd_LineRate_func:
        return 4;

    case lcd_Temperature_Compensation_func:
        return 4;

    default:
        ASSERT(0);
   }

   return 100;
}

void LCD_SetBias_MC2TA7402(kal_uint8 *bias)
{
}

void LCD_Contrast_MC2TA7402(kal_uint8 *contrast)
{
}

void LCD_LineRate_MC2TA7402(kal_uint8 *linerate)
{
}

void LCD_Temp_Compensate_MC2TA7402(kal_uint8 *compensate)
{
}

kal_bool LCD_ESD_check_MC2TA7402()
{
    volatile  kal_uint16 data_value = 0;
    kal_uint16 data_addr = 0;
	kal_uint8 i, reg_start_idx, reg_end_idx;
	
	if (lcd_reg_index > 2) {
        lcd_reg_index = 0;
	}
   
	while (LCD_IS_RUNNING);   

    if (lcd_reg_index == 0) {
      reg_start_idx = 0;
      reg_end_idx = 7;
   }else if (lcd_reg_index == 1) {
      reg_start_idx = 8;
      reg_end_idx = 14;
   }else{
      reg_start_idx = 15;
      reg_end_idx = N_lcd_reg - 1;
   }   

    for (i = reg_start_idx; i <= reg_end_idx; i++) {
        if (lcd_check == 1) {
            data_addr = lcd_check_reg.reg[i].addr;
            data_value = readreg_MC2TA7402(data_addr);	   
            kal_prompt_trace(MOD_ENG, "--read %x as %x", data_addr, data_value);
            if (data_value != lcd_check_reg.reg[i].para) {
                kal_prompt_trace(MOD_ENG, "ESD FAIL read %x as %x", data_addr, data_value);
                return KAL_FALSE;
            }
	    }
    }

    lcd_reg_index++;
    while (LCD_IS_RUNNING);
   
    return KAL_TRUE;
}

/*===================The above is LCD dependent==========*/
#if ( (defined(MT6205B)) || (defined(MT6218)) )
void LCD_memcpy(void *dst /*s1*/, const void *src /*s2*/, kal_uint16 size)
{
   #ifdef LCD_DMAENABLE
      kal_uint32 srcaddr=(kal_uint32)src;
      kal_uint32 dstaddr=(kal_uint32)dst;
      kal_uint16 size_MSB = (kal_uint16)(size >> 9);
      kal_uint16 size_LSB = (kal_uint16)(size & 0x01ff);

      ASSERT(lcd_assert_fail==KAL_FALSE);
      lcd_assert_fail = KAL_TRUE;
      ASSERT(DRV_Reg(LCD_REFR)==0x00);
      if(size_MSB)
      {
         DRV_WriteReg(LCD_MSBSRC,(kal_uint16)(srcaddr >> 16));
         DRV_WriteReg(LCD_LSBSRC,(kal_uint16)srcaddr);

         DRV_WriteReg(LCD_REFR,0x0000);
         DRV_WriteReg(LCD_MSBDST,(kal_uint16)(dstaddr >> 16));
         DRV_WriteReg(LCD_LSBDST,(kal_uint16)(dstaddr));

         DRV_WriteReg(LCD_CADDRSET,512);
         DRV_WriteReg(LCD_PADDRSET,size_MSB);
         DRV_WriteReg(LCD_CHOP,0);

         DRV_WriteReg(LCD_PCON,LCD_PCON_DINC);

         DRV_WriteReg(LCD_START,LCD_START_BIT);
         while(DRV_Reg(LCD_GSTA)&LCD_GSTA_PRUN);
         DRV_WriteReg(LCD_START,LCD_STOP_BIT);
      }

      if (size_LSB)
      {
         srcaddr = (srcaddr + size - size_LSB);
         dstaddr = (dstaddr + size - size_LSB);

         DRV_WriteReg(LCD_MSBSRC,(kal_uint16)(srcaddr >> 16));
         DRV_WriteReg(LCD_LSBSRC,(kal_uint16)srcaddr);

         DRV_WriteReg(LCD_REFR,0x0000);
         DRV_WriteReg(LCD_MSBDST,(kal_uint16)(dstaddr >> 16));
         DRV_WriteReg(LCD_LSBDST,(kal_uint16)(dstaddr));

         DRV_WriteReg(LCD_CADDRSET,size_LSB);
         DRV_WriteReg(LCD_PADDRSET,1);
         DRV_WriteReg(LCD_CHOP,0);

         DRV_WriteReg(LCD_PCON,LCD_PCON_DINC);

         DRV_WriteReg(LCD_START,LCD_START_BIT);
         while(DRV_Reg(LCD_GSTA)&LCD_GSTA_PRUN);
         DRV_WriteReg(LCD_START,LCD_STOP_BIT);
      }

      lcd_assert_fail = KAL_FALSE;
   #else /*!LCD_DMAENABLE*/
      kal_mem_cpy(dst,src,size);
   #endif   /*LCD_DMAENABLE*/
}
#else /*!(MT6205B,MT6218)*/
void LCD_memcpy(void *dst /*s1*/, const void *src /*s2*/, kal_uint16 size)
{
   kal_mem_cpy(dst,src,size);
}
#endif   /*(MT6205B,MT6218)*/

LCD_Funcs LCD_func_MC2TA7402 = {
   LCD_Init_MC2TA7402,
   LCD_PWRON_MC2TA7402,
   LCD_SetContrast_MC2TA7402,
   LCD_ON_MC2TA7402,
   LCD_BlockWrite_MC2TA7402,
   LCD_Size_MC2TA7402,
   LCD_EnterSleep_MC2TA7402,
   LCD_ExitSleep_MC2TA7402,
   LCD_Partial_On_MC2TA7402,
   LCD_Partial_Off_MC2TA7402,
   LCD_Partial_line_MC2TA7402,
   /*Engineering mode*/
   LCD_GetParm_MC2TA7402,
   LCD_SetBias_MC2TA7402,
   LCD_Contrast_MC2TA7402,
   LCD_LineRate_MC2TA7402,
   LCD_Temp_Compensate_MC2TA7402
   #ifdef __LCD_ESD_RECOVERY__   
   ,LCD_ESD_check_MC2TA7402
   #endif 
};

void LCD_FunConfig(void)
{
    MainLCD = &LCD_func_MC2TA7402;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -