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

📄 vfd_hw.~c

📁 MTK 1389e版 MINI组合音响代码
💻 ~C
📖 第 1 页 / 共 2 页
字号:
/***************    MTK CONFIDENTIAL & COPYRIGHTED     ****************/
/***************                                       ****************/
/*************** Description : VFD Driver Routine      ****************/
/***************                                       ****************/
/***************                                       ****************/
/***************     Company : MediaTek Inc.           ****************/
/***************  Programmer : Harrison Hsieh          ****************/
/**********************************************************************/
#define _VFD_HW_C_

#pragma NOAREGS

#include "8032api.h"
#include "vfd_hw.h"

#ifdef VFD_SUPPORT

#include "vfd.h"

#include VFD_CUS_H

#if  defined(DVD_RECEIVER)   //xiao 03-05-02
#include  "receiver\dvdrec.h"
#include  "vfd_symb.h"
extern xdata BYTE _bPWRMode;            //MUSET uses this not _bSysState
xdata BYTE pbVFDShadow[MAX_VFD_ADDR];   //When PowerDown Use these to replace shareinfo
xdata BYTE bVfdRefreshPos ;             //Start Position of refresh                          
#endif


extern structFlagI2C xdata sFlagI2C;

void vVfdInit(void) large
{
  BYTE i;

  vVfdDirectClrAll();
  //BillDen vVfdShowMsg(SEG_MSG_HELLO, TRUE);
  vVfdStrobe(FALSE);         // begin to write the VFD command
  vVfdUpdate(MODESET);
  vVfdStrobe(TRUE);          // strobe pull high to release the mode set
  
  vVfdStrobe(FALSE);         // begin to write the VFD command
  vVfdUpdate(VFD_CONTROL);
  _bVfdPulseLvl = VFD_CONTROL;
  vVfdStrobe(TRUE);          // strobe pull high to release the mode set

  for(i = 0; i <= MAX_VFD_ADDR; i++)
  {
    vSetSharedInfo(SI_VFD_SHADOW_START + i, 0xff);  // reset the tmpbuf to zero
  }


  vVfdClearAll();
/*
  for(i = 0; i <= MAX_VFD_ADDR; i++)
  {
//    vSetSharedInfo(SI_VFD_TMPBUF_START + i, 0);  // reset the tmpbuf to zero
    vSetSharedInfo(SI_VFD_SHADOW_START + i, 0);
  }
*/

  vVfdSetFlash(FALSE);    //set _fgVfdFlsh = fgOn
  _bVfdState = 0;
  _bVfdKeyScan = IR_NONE;
}

#if 0
static void vVFDWait(BYTE time) large
{
    BYTE timex;
    WORD onesecond;
    for(timex=0;timex<time;timex++)
   for(onesecond =0; onesecond <5000; onesecond ++)
   	{
   	  _nop_();_nop_();_nop_();_nop_(); 
   	  _nop_();_nop_();_nop_();_nop_(); 
   	  _nop_();_nop_();_nop_();_nop_(); 
   	  _nop_();_nop_();_nop_();_nop_();
   	  _nop_();_nop_();_nop_();_nop_(); 
   	  _nop_();_nop_();_nop_();_nop_(); 
   	  _nop_();_nop_();_nop_();_nop_(); 
   	  _nop_();_nop_();_nop_();_nop_(); 
   	  _nop_();_nop_();_nop_();_nop_();
   	  _nop_();_nop_();_nop_();_nop_();
   	}
}
#endif

void vVfdPwrDownInit(BOOL fgCleanAll) large
{
  BYTE i;

  vVfdStrobe(FALSE);         // begin to write the VFD command
  vVfdUpdate(MODESET);
  vVfdStrobe(TRUE);          // strobe pull high to release the mode set

#if defined(DVD_RECEIVER)
  for(i = 0; i <= MAX_VFD_ADDR; i++)
  {
       pbVFDShadow[i] = 0; 
  }
#endif      

  if(fgCleanAll)
  {
    for(i = 0; i <= MAX_VFD_ADDR; i++)   //xiao 03-05-03
    {
      vVfdDirectWrite(i, 0);
    }
    
    vVfdStrobe(FALSE);         // begin to write the VFD command
    vVfdUpdate(VFD_CONTROL);          //set VFD dark
    vVfdStrobe(TRUE);          // strobe pull high to release the mode set
  }
  vVfdSetFlash(FALSE);
  _bVfdState = 0;
#if defined(DVD_RECEIVER)
  bVfdRefreshPos = 0;
  _bVfdTimer = 0;
#endif
  _bVfdKeyScan = IR_NONE;
}

//////////////////////////////////////////////////////////////////
//Use the serial port to send  data bTmp
static void vVfdUpdate(BYTE bTmp) large
{
  BYTE i;

  for (i = 0; i < 8; i++)
  {
    vVfdClk(FALSE);

    vVfdCombineBit(bTmp);   //Set data_pin: DATA_PIN = (bData & 0x1) 
    bTmp >>= 1;

    vVfdClk(TRUE);
  }

  vVfdData(TRUE);
}

// should use increamental address and add a check to see that if we need to update address again
// set the date to display memery  
static void vVfdWrite(BYTE bAddr) large
{
  BYTE bCnt = 0;
  BYTE bData;
  
  if(sFlagI2C.fgbusy_TUNER==TRUE)
		return;
  sFlagI2C.fgbusy_VFD = TRUE;
	
  vVfdStrobe(FALSE);
  vVfdUpdate(DATA_SET_INC) ;  // issue the write data command
  vVfdStrobe(TRUE);

  
  vVfdStrobe(FALSE);
  vVfdUpdate(ADDR_SET | bAddr);  // after setting the address, the strobe need not to pull high
  vVfdStrobe(FALSE);


  while(TRUE)
  {
    bCnt++;
    #if defined(DVD_RECEIVER)
//      if (_bSysState != DVD_STATE)   //xiao 03-05-03
      if (_bPWRMode >= 4)     //#define SV_PWR_STANDBY 4
      {
        bData = pbVFDShadow[bAddr];  // get the data from the shadow
      }
      else  
    #endif
        bData = bSharedInfo(SI_VFD_TMPBUF_START + bAddr);  // get the data from the shadow
   
    
    vVfdUpdate(bData);   // the final data is written , strobe pull high
  
    #if defined(DVD_RECEIVER)     //xiao 03-05-03
//      if (_bSysState == DVD_STATE)  //only  PowerOn can uses shareinfo
       if (_bPWRMode < 4)     //#define SV_PWR_STANDBY 4
    #endif
         vSetSharedInfo(SI_VFD_SHADOW_START + bAddr, bData);  // set the data in the display buf
    vVfdClrQueueMark(bAddr);    // after updating, clear the queue mark
    bAddr++;   // update the address to next
    if(bAddr == VFD_MAX_ADDR)
    {
      bAddr = 0;   //reset to 0;
    }

    if((bCnt >= VFD_MAX_UPDATE_CNT) || (!fgVfdQueueMark(bAddr)))
    {
      break;
    }
  }
  vVfdStrobe(TRUE);  
  sFlagI2C.fgbusy_VFD = FALSE;
}

//////////////////////////////////////////////////////////////////
//display the bNum in the SegPos,SegPos indecated to  _pbVfdSeg[]
//This function only used for VFD Message
void vVfdSegDisplay(BYTE SegPos, BYTE bNum, BOOL fgDirect) large
{
#if ((SEG_SIZE == 10) || (SEG_SIZE == 14))
  WORD wSegInfo;
#else
  BYTE bSegInfo;
#endif  
  
  BYTE i;
  BYTE bData;
  BYTE bAddr = VFD_ADDR_LIMIT;   // a initial unknown value in VFD memory
  BYTE bIsTempMsg = FALSE;
  
  if(!fgDirect)
  {    
#if  defined(DVD_RECEIVER)      //xiao 03-04-26
      if  (_bVfdTimer)   //Although have the temp VFD_TEXT ,but the normal VFD
                         //is changed,the backup is invalid ,must refresh
      {  
//      	  if (_bSysState != DVD_STATE)
         if (_bPWRMode < 4) 
             vSetSharedInfo(SI_VFD_SEG_ORG + SegPos, bNum);	
          return;
      }     
      else if (_bPWRMode < 4)     //#define SV_PWR_STANDBY 4/*if (_bSysState == DVD_STATE)  */
      {
          if (bSharedInfo(SI_VFD_SEG_BAK + SegPos) == bNum)
              return;                   
      }
#else
    if((_bVfdTimer) || (bSharedInfo(SI_VFD_SEG_BAK + SegPos) == bNum))
    return;
#endif    
  }


#if ((SEG_SIZE == 10) || (SEG_SIZE == 14))
  wSegInfo = _pbSegUnit[bNum] + (_pbSegUnitHi[bNum] << 8);
  if(fgDirect)
  {
    vDirectSequenceUpd(SEG_SIZE, _pbVfdSeg[SegPos], wSegInfo);  
  }
  else
  {
    vVfdSequenceUpdate(SEG_SIZE, _pbVfdSeg[SegPos], wSegInfo);  
  }
#else
  bSegInfo = _pbSegUnit[bNum];        // segment size = 7/8
  if(fgDirect)
  {
    vDirectSequenceUpd(SEG_SIZE, _pbVfdSeg[SegPos], (WORD)bSegInfo);  
  }
  else
  {
    vVfdSequenceUpdate(SEG_SIZE, _pbVfdSeg[SegPos], (WORD)bSegInfo);  
  }
#endif  
  

  // update into tmp buf here
  if(!fgDirect && !_bVfdTimer)
  {
     if (_bPWRMode < 4) 	
        vSetSharedInfo(SI_VFD_SEG_BAK + SegPos, bNum);
  }
//  vVfdWriteQueue(bAddr, bData);  
}


// bTime one unit for half seconds
void vVfdShowTempMsg(BYTE bMsgId, BYTE b20msCnt) large
{
  BYTE i;

  if (!_bVfdTimer) //BillDen Mod 2003.3.17
  {
    for(i = 0; i < MAX_SEG_SEQ_NUM; i++)
    {
      #if  defined(DVD_RECEIVER)
//      	 if (_bSysState == DVD_STATE)
          if (_bPWRMode < 4)     //#define SV_PWR_STANDBY 4
      #endif    
            vSetSharedInfo(SI_VFD_SEG_ORG + i, bSharedInfo(SI_VFD_SEG_BAK + i));  // backup the original
  
    }
  }
  else _bVfdTimer = 0;  //can show the temp message

  vVfdShowMsg(bMsgId, FALSE);
  

  _bVfdTimer = b20msCnt;  
}


static void vVfdRecoverSeg(void) large
{
  BYTE i;
  BYTE bSeg;

  for(i = 0; i < MAX_SEG_SEQ_NUM; i++)
  {
    bSeg = _pbSegSequence[i];
    vVfdSegDisplay(bSeg, bSharedInfo(SI_VFD_SEG_ORG + bSeg), FALSE);
  }
}


void vVfdShowMsg(BYTE bMsgIdIdx, BOOL fgDirect) large
{
  BYTE bPos; 
  BYTE bBound;
  BYTE i;
  WORD bMsgId;

  bMsgId = _pbMsgTable[bMsgIdIdx];  //the position in  the  _pbVfdMsg[]
  
#if defined(DVD_RECEIVER)    //beacause the vVfdSegDisplay() have deal with 
  if(_bVfdTimer)     // temp msg is still showed, do not cover it
  {
         if(!fgDirect)
        {
           for(i = 0; i < MAX_SEG_SEQ_NUM; i++)
           {
              bPos = _pbSegSequence[i];
              vSetSharedInfo(SI_VFD_SEG_ORG + i, _pbVfdMsg[bMsgId + i + 1]);
           }
        }
         return;
  }
#else  
  if(_bVfdTimer )     // temp msg is still showed, do not cover it
  {                    
    return;
  }
#endif

  if(fgDirect)
  {
    vVfdStrobe(FALSE);         // begin to write the VFD command
    vVfdUpdate(MODESET);
    vVfdStrobe(TRUE);          // strobe pull high to release the mode set

    vVfdStrobe(FALSE);         // begin to write the VFD command
    vVfdUpdate(VFD_CONTROL);
    _bVfdPulseLvl = VFD_CONTROL;
    vVfdStrobe(TRUE);          // strobe pull high to release the mode set
  }
  
  bPos = (_pbVfdMsg[bMsgId] & 0xf0) >> 4;  //begin position In vfd

  bBound = bPos + (_pbVfdMsg[bMsgId] & 0xf); // end position in vfd

  for(i = 0; i < MAX_SEG_SEQ_NUM; i++)
  {
    if((i >= bPos) && (i < bBound))
    {
       vVfdSegDisplay(_pbSegSequence[i], _pbVfdMsg[bMsgId + i - bPos + 1], FALSE);
    }
    else
    {
      vVfdSegDisplay(_pbSegSequence[i], SEG_CLEAN, fgDirect);
    }
  }

#ifdef DIRECT_CROSS_TABLE  
  if(fgDirect)
  {
    bPos = _pbMsgDirectTable[bMsgIdIdx];   // start position

    if(bPos == 0xff)
    {
      return;
    }

    bBound = _pbVfdDirectMsg[bPos];
 
    for(i = 0; i < bBound; i++)
    {
      i = i << 1;
      vVfdDirectWrite(_pbVfdDirectMsg[bPos + 1 + i], _pbVfdDirectMsg[bPos + 1 + i + 1]);

      i = i >> 1;
    }
  }

#endif
}

////////////////////////////////////////////////////////////////
//Function :display the ICON 
//Parameter: bMode is defined as VFD_MODE_XXX in file vfd_func.h
//           fgEnable is indicate Display or not
//Descripte: After finished int shareinfo , write it to Queue
void vVfdSetMode(BYTE bMode, BOOL fgEnable) large
{
  BYTE bData;

  if(_pbVfdMode[bMode] == VFD_UNKNOWN_ADDR )
  {
    return;     // ignore this command
  }

#if  defined(DVD_RECEIVER)
//   if (_bSysState != DVD_STATE)
   if (_bPWRMode >= 4)     //#define SV_PWR_STANDBY 4
      bData = pbVFDShadow[_pbVfdMode[bMode]];
   else
#endif
      bData = bSharedInfo(SI_VFD_TMPBUF_START + _pbVfdMode[bMode]);

  if(fgEnable)
  {  
    bData = bData | _pbVfdMode[bMode + 1];
  }
  else
  {
    bData = bData & (~_pbVfdMode[bMode + 1]);
  }

  vVfdWriteQueue(_pbVfdMode[bMode], bData);
}


static void vVfdUpdateState(void) large // update into the VFD display memory
{
  BYTE i;
  BYTE bCnt = 0;    // initial value to 0
  BYTE bLimit;

#if  defined(DVD_RECEIVER)
//   if (_bSysState != DVD_STATE)
   if (_bPWRMode >= 4)     //#define SV_PWR_STANDBY 4
      i = bVfdRefreshPos;
   else
#endif
       i = bSharedInfo(SI_VFD_UPDATE_WRIDX);
  bLimit = i;

  while(TRUE)
  {
    if(bCnt > VFD_MAX_UPDATE_CNT)
    {
#if defined(DVD_RECEIVER)
//      if (_bSysState != DVD_STATE)
      if (_bPWRMode >= 4)     //#define SV_PWR_STANDBY 4
         bVfdRefreshPos = i;
      else   
#endif   	
         vSetSharedInfo(SI_VFD_UPDATE_WRIDX, i);
      break;
    }

    if(fgVfdQueueMark(i))
    {
      vVfdWrite(i);
      bCnt++;
    }    

    i++;

    if(i == VFD_MAX_ADDR)
    {
      i = 0;    // reset i to 0, wrap around to the head of the ring buffer
    }
    
    if(i == bLimit)    // all loop finish
    {
      break;   // write index not change in this case
    }
  }

}

static void vVfdDirectWrite(BYTE bAddr, BYTE bData) large
{
  if(bAddr == 0xff)
  {
    return;
  }

  vVfdStrobe(FALSE);
  vVfdUpdate(DATA_SET_INC) ;  // issue the write data command
  vVfdStrobe(TRUE);

  
  vVfdStrobe(FALSE);
  vVfdUpdate(ADDR_SET | bAddr);  // after setting the address, the strobe need not to pull high
  vVfdStrobe(FALSE);

  vVfdUpdate(bData);   // the final data is written , strobe pull high
  vVfdStrobe(TRUE);
}


static vVfdWriteQueue(BYTE bAddr, BYTE bData) large
{
  BYTE bShadowData;

  if(bAddr == 0xff)
  {
    return;
  }

#if defined(DVD_RECEIVER)
// if (_bSysState != DVD_STATE)
  if (_bPWRMode >= 4)     //#define SV_PWR_STANDBY 4
     bShadowData = pbVFDShadow[bAddr] ;
  else   
#endif
     bShadowData = bSharedInfo(SI_VFD_SHADOW_START + bAddr);

  if(bShadowData != bData)  // if it is the same as VFD display data, ignore this command
  {
#if defined(DVD_RECEIVER)  
//    if (_bSysState != DVD_STATE)
   if (_bPWRMode >= 4)     //#define SV_PWR_STANDBY 4
      pbVFDShadow[bAddr] = bData;
    else  
#endif	
       vSetSharedInfo(SI_VFD_TMPBUF_START + bAddr, bData);   // set the tmp buf data

    if(!fgVfdQueueMark(bAddr))  // the position is not in update queue already
    {
      vVfdSetQueueMark(bAddr);  // add the queue mark
    }
  }
  else
  {
#if defined(DVD_RECEIVER)  
//    if (_bSysState == DVD_STATE)
   if (_bPWRMode >= 4)     //#define SV_PWR_STANDBY 4
   {
       pbVFDShadow[bAddr]=bShadowData;
       if(!fgVfdQueueMark(bAddr))  // the position is not in update queue already
       {
         vVfdSetQueueMark(bAddr);  // add the queue mark
       }
   }
   else
#endif		
    { 
       vSetSharedInfo(SI_VFD_TMPBUF_START + bAddr, bShadowData);
       vVfdClrQueueMark(bAddr);
    }    
  } 
}

#ifdef VFD_LED      
static void vVfdLedUpdate(void) large
{
#if defined(DVD_RECEIVER)    //XIAO 03-05-23
//   if(_bSysState == TUNER_STATE && _fgLedOnOff)
//   {
//     _bLedPort = 0x80;
//     _fgLedOnOff = FALSE;
//   }
#endif	
  if(_bLedPort & 0x80)   // the msb indicate that the LED has something change
  {
    vVfdStrobe(FALSE);
    vVfdUpdate(DATA_SET_LED) ;  // issue the write data command
    vVfdStrobe(FALSE);
    vVfdUpdate(_bLedPort & 0x1f);   // 16311 at least 5 led ports
    vVfdStrobe(TRUE);
    _bLedPort &= 0x7f;   // mask the msb bit 
  }  
}

void vVfdLed(BYTE bLedNum, BOOL fgOn) large
{
  BYTE bLed;

#if defined(DVD_RECEIVER)
  if (fgOn)
  {
    _bLedPort = bLedNum | 0x80;	
  }
  else
  {
    _bLedPort = 0x8f; 
  }
#else
  bLed = _bLedPort;

  if(fgOn)
  {
    bLed |= (1 << bLedNum);
  }
  else
  {
    bLed |= 0x1f; //BillDen
    bLed &= (~(1 << bLedNum));
  }

⌨️ 快捷键说明

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