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

📄

📁 使用Linux ARM GCC编译器来编译
💻
📖 第 1 页 / 共 2 页
字号:
#include "2440addr.h"
#include "def.h"
#include "2440iic.h"
#include "../include/command.h"
#include "lcd.h"

#define NULL 0
void printk(const char* , ...);

typedef unsigned int* u_pt;
#define GPEUP (*(u_pt)0x54000048)
#define GPECON (*(unsigned int*)0x54000040)
#define BANKCON6 (*(unsigned int*)0x4800001c)
#define BANKCON7 (*(unsigned int*)0x48000020)
#define REFRESH (*(unsigned int*)0x48000024)
#define MRSRB6 (*(unsigned int*)0x4800002c)
#define MRSRB7 (*(unsigned int*)0x48000030)

/*#define IICCON (*(unsigned int*)0x54000000)
#define IICADD (*(unsigned int*)0x54000008)
#define IICSTAT (*(unsigned int*)0x54000004)

#define IIC_INTPEND 0x10*/

//#define DELAYTIME 1000
//#define TIMEOUT 0x200
//#define Delay(x) udelay (x)
typedef unsigned long ulong;
#define DELAYTIME 1000
#define TIMEOUT (15625*10)
#define Delay(x) udelay (x)
ulong get_timer(ulong base);

char iic_data;

void udelay (int);

static U8 _iicData[IICBUFSIZE];
static volatile int _iicDataCount;
static volatile int _iicStatus;
static volatile int _iicMode;
static int _iicPt;
unsigned short int * const __LCDFrameBuffer = (unsigned short int*)0x30500000;

void Lcd_Init()
{
    rGPCUP=0xffffffff; // Disable Pull-up register
    rGPCCON=0xaaaaaaaa; //Initialize VD[7:0],LCDVF[2:0],VM,VFRAME,VLINE,VCLK,LEND 
    rGPDUP=0xffffffff; // Disable Pull-up register
    rGPDCON=0xaaaaaaaa; //Initialize VD[23:8]   
    
#if 0
    //         时钟25MHz               MVAL值       TFT    24BPP
    rLCDCON1=(CLKVAL_TFT_640480<<8)|(MVAL_USED<<7)|(3<<5)|(13<<1)|0;
    rLCDCON2=(VBPD_640480<<24)|(LINEVAL_TFT_640480<<14)|(VFPD_640480<<6)|(VSPW_640480);
    rLCDCON3=(HBPD_640480<<19)|(HOZVAL_TFT_640480<<8)|(HFPD_640480);
    rLCDCON4=(MVAL<<8)|(HSPW_640480);

    //0x00 XX XX XX
    // ---  R  G  B
    rLCDCON5=(0<<12)|(1<<9)|(1<<8); // BPP24:MSB,HSYNC and VSYNC are inverted

    
    rLCDSADDR1=( ( (unsigned int)__LCDFrameBuffer >> 22) << 21 ) | M5D ( (unsigned int)__LCDFrameBuffer >> 1 );
    rLCDSADDR2=M5D( ( (unsigned int)__LCDFrameBuffer + (LCD_XSIZE_TFT_640480*LCD_YSIZE_TFT_640480*2 ) ) >> 1 );

    rLCDSADDR3=(0<<11)|(LCD_DISPLAY_XSIZE_TFT_640480*1);

    rLPCSEL&=(~7); // Disable LPC3600
    rTPAL=0; // Disable Temp Palette
#endif

    //         时钟25MHz               MVAL值       TFT    16BPP
    rLCDCON1= LCD_DISPLAY_CLKVAL|MVAL_USED|MODE_TFT|BPP_16|LCD_DIS;
    rLCDCON2=(LCD_DISPLAY_VBPD<<24)|(LCD_DISPLAY_LINEVAL<<14)|(LCD_DISPLAY_VFPD<<6)|(LCD_DISPLAY_VSPW);
    rLCDCON3=(LCD_DISPLAY_HBPD<<19)|(LCD_DISPLAY_HOZVAL<<8)|(LCD_DISPLAY_HFPD);
    rLCDCON4=(MVAL<<8)|(LCD_DISPLAY_HSPW);

    //0x00 XX XX XX
    // ---  R  G  B
    rLCDCON5=(0<<12)|(1<<11)|(1<<9)|(1<<8)|1; // BPP24:LSB,5:6:5 Format,HSYNC and VSYNC are inverted,half-word swap

    
    rLCDSADDR1=( ( (unsigned int)__LCDFrameBuffer >> 22) << 21 ) | M5D ( (unsigned int)__LCDFrameBuffer >> 1 );
    rLCDSADDR2=M5D( ( (unsigned int)__LCDFrameBuffer + (LCD_DISPLAY_XSIZE*LCD_DISPLAY_YSIZE*2 ) ) >> 1 );

    rLCDSADDR3=(0<<11)|(LCD_DISPLAY_XSIZE*1);

    rTCONSEL &= ~((1<<4)|7); // Disable LPC3600 & LCC3600
    rTPAL=0; // Disable Temp Palette
    
    //
    // 为了避免屏幕抖动,先不打开液晶控制器
    //

  rLCDCON1 = rLCDCON1 | LCD_EN;
}

intnand_read_ll(unsigned char *buf, unsigned long start_addr, int size);

void Lcd_ClearDisplayBuff(void)
{
    memset(__LCDFrameBuffer, 0xff, LCD_DISPLAY_XSIZE*LCD_DISPLAY_YSIZE*2);
    //memcpy(__LCDFrameBuffer, (unsigned char*)0+0x180000, LCD_DISPLAY_XSIZE*LCD_DISPLAY_YSIZE*2);
    //nand_read_ll((unsigned char *)__LCDFrameBuffer, (unsigned long)0x200000, 0x200000);
}

#if 0
//**************[ iic_wr ]*****************************************
#define IIC_DATAPIN 0x8000
#define IIC_CLKPIN 0x4000
#define IICDATA_STATUS() ((rGPEDAT&IIC_DATAPIN)?1:0)
#define IICDATA_HIGH() do{rGPEDAT |= IIC_DATAPIN;}while(0)
#define IICDATA_LOW() do{rGPEDAT &= ~IIC_DATAPIN;}while(0)
#define IICCLK_HIGH() do{rGPEDAT |= IIC_CLKPIN;}while(0)
#define IICCLK_LOW() do{rGPEDAT &= ~IIC_CLKPIN;}while(0)

typedef unsigned char uchar;
static void iic_start(void)
{
    IICCLK_HIGH();
    udelay(2000*5);
    IICDATA_HIGH();
    udelay(2000*5);
    IICDATA_LOW();
    udelay(2000*5);
    IICCLK_LOW();
    
    udelay(2000*10);
}

static void iic_stop(void)
{
    IICCLK_LOW();
    udelay(2000*5);
    IICDATA_LOW();
    udelay(2000*5);
    IICCLK_HIGH();
    udelay(2000*5);
    IICDATA_HIGH();
    
    udelay(2000*10);
}

static void iic_restart(void)
{
    udelay(2000*5);
    IICDATA_HIGH();
    udelay(2000*5);
    IICCLK_HIGH();
    
    IICDATA_LOW();
    udelay(2000*5);
    IICCLK_LOW();
    
    udelay(2000*10);
}

static int iic_out(uchar data, int ack)
{
    int i;
    int ret=0;
    
    udelay(2000*5);
    for (i=0;i<8;i++) {
        if (data&0x80)
            IICDATA_HIGH();
        else
            IICDATA_LOW();
        data <<= 1;
        udelay(2000*5);
        IICCLK_HIGH();
        udelay(2000*20);
        IICCLK_LOW();
        udelay(2000*5);
    }

    if (ack) {
        rGPECON &= ~0xc0000000;
        udelay(2000*5);
        IICCLK_HIGH();
        udelay(2000*10);
        ret = IICDATA_STATUS();
        udelay(2000*10);
        IICCLK_LOW();
        udelay(2000*5);
        rGPECON |= 0x40000000;
    }
    IICDATA_HIGH();
    udelay(2000*5);
    return ret;
}

static uchar iic_in(int ack)
{
    uchar data=0;
    int i;
    
    rGPECON &= ~0xc0000000;

    udelay(2000*5);
    for (i=0;i<8;i++) {
        IICCLK_HIGH();
        udelay(2000*10);
        
        data <<= 1;
        data |= IICDATA_STATUS();
        udelay(2000*10);

        IICCLK_LOW();
        udelay(2000*5);
    }
    
    rGPECON |= 0x40000000;

    if (ack) {
        udelay(2000*5);
        IICDATA_LOW();
        udelay(2000*5);
        IICCLK_HIGH();
        udelay(2000*20);
        IICCLK_LOW();
        udelay(2000*10);
    }
    IICDATA_HIGH();
    udelay(2000*5);
    return data;

}
#endif

void iic_wr(U32 slvAddr,U32 addr,U8 data)
{
#if 0
    printk("deviceid:%02x addr:%02x data:%02x\n",slvAddr,addr,data);
    iic_start();
    do {
        if (iic_out(slvAddr&~1,1)) break;
        if (iic_out(addr,1)) break;
        if (iic_out(data,1)) break;
        iic_stop();
        return ;
    } while (0);
    iic_stop();
    printk("error\n");
#else
    ulong timeout;
    _iicMode      = WRDATA;
    _iicPt        = 0;
    _iicData[0]   = (U8)addr;
    _iicData[1]   = data;
    _iicDataCount = 2;
    
    //while (rIICSTAT & 0x20);
    
    rIICDS        = slvAddr;            //0xa0
      //Master Tx mode, Start(Write), IIC-bus data output enable
      //Bus arbitration sucessful, Address as slave status flag Cleared,
      //Address zero status flag cleared, Last received bit is 0
    rIICSTAT      = 0xf0;      
    //rIICCON       = 0xaf;
      //Clearing the pending bit isn't needed because the pending bit has been cleared.
    //timeout = 0;
    //while(_iicDataCount!=-1) {
    //   Run_IicPoll();
    //   if (timeout++ > TIMEOUT) break;
    //}
    timeout = get_timer(0);
    while(_iicDataCount!=-1) {
       Run_IicPoll();
       if (get_timer(0)-timeout > TIMEOUT) break;
    }

    _iicMode = POLLACK;

    while(1)
    {
        rIICDS     = slvAddr;
        _iicStatus = 0x100;             //To check if _iicStatus is changed 
        rIICSTAT   = 0xf0;              //Master Tx, Start, Output Enable, Sucessful, Cleared, Cleared, 0
        rIICCON    = 0xaf;              //Resumes IIC operation. 
        //while(_iicStatus==0x100)  
        //    Run_IicPoll();
        timeout = get_timer(0);
        while(_iicStatus==0x100) {
           Run_IicPoll();
           if (get_timer(0)-timeout > TIMEOUT) break;
        }
              
        if(!(_iicStatus & 0x1))
            break;                      //When ACK is received
    }
    rIICSTAT = 0xd0;                    //Master Tx condition, Stop(Write), Output Enable
    rIICCON  = 0xaf;                    //Resumes IIC operation.
    Delay(DELAYTIME);                           //Wait until stop condtion is in effect.
      //Write is completed.
#endif
}
        
//************************[ iic_rd ]********************************
void iic_rd(U32 slvAddr,U32 addr,U8 *data)
{
#if 0
    iic_start();
    do {
        if (iic_out(slvAddr&~1,1)) break;
        if (iic_out(addr,1)) break;
        iic_restart();
        if (iic_out(slvAddr|1,1)) break;
        *data = iic_in(1);
        iic_stop();
        printk("deviceid:%02x addr:%02x data:%02x\n",slvAddr,addr,*data);
        return ;
    } while (0);
    iic_stop();
    printk("error\n");
#else
    ulong timeout;
    
    _iicMode      = SETRDADDR;
    _iicPt        = 0;
    _iicData[0]   = (U8)addr;

⌨️ 快捷键说明

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