AMT630H.c 12.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
#include "AMT630H.h"
#include <stdint.h>
#include "UartProtocol.h"
#include "Components.h"
#include "PicBin.h"
#include "GpioUser.h"
//#include "AMT630H_Datas.h"
#define AMT630H_ERR_TIME            10000U
#define AMT630H_RELEASE_MODE        1U
unsigned int AMT630H_InitTime = 0;
uint8_t g_sysFlag_Lcdcheck = 0;
/* Initialization */
LCD_TFT_SOUND_PARA_ST LcdSoundParamterData;
SOFTWARE_VERSION_ST amt630Version;

uint8_t Amt630hInitFinishFlag = 0;

uint32_t Amt630hInitTimerCnts = 0;
uint32_t Amt630hSequentialTimerCnts = 0;
uint32_t Amt630hFlashCheckTimerCnts = 0;
uint32_t Amt630hServiceTimerCnts = 0;


/* SOC Error */
uint16_t AMT630H_REQ_Time[ALIVE_COUNTER_TOTAL] = { 0 };
uint8_t AMT630H_Err = 0U;
uint8_t AMT630H_AliveCounter[ALIVE_COUNTER_TOTAL] = { 0 };
uint16_t AMT630H_CrcErrTime = 0;
uint32_t AMT630H_CrcErrCounter = 0;
uint8_t AMT630H_CrcErrMaxCounter = 0;

/* Flash Check */
#define  FLASH_CHECK_TIME_NUM       20000
s_AMT630H_FlashCheck_t AMT630H_FlashCheck;

/* Delay Time */
unsigned long Delay_Time = 0;
unsigned long Delay_Time_Set = 0;

extern uint32_t Check_Upgrade;
extern uint32_t Check_Upgrade_Cnt;

/* Refresh Time */
unsigned long AMT630H_RefreshTime = 0;
static uint8_t AMT630H_Animation_Start = 0;
static uint8_t AMT630H_Animation_Finish = 0;
static uint16_t AMT630H_Animation_DispPic = 0;
static uint16_t AMT630H_Animation_RefreshTime = 0;
static uint16_t AMT630H_Animation_RefreshTime_default = 0;
static const uint16_t BootAnimationList[AMT630H_ANIMATION_PIC_NUM] = {
    Pic_0860_0_0,
    Pic_0860_0_0,
    Pic_0860_0_0,
    Pic_0860_0_0,
    Pic_0859_0_0,
    Pic_0859_0_0,
    Pic_0859_0_0,
    Pic_0859_0_0,
    Pic_0858_0_0,
    Pic_0857_0_0,
    Pic_0856_0_0,
    Pic_0855_0_0,
    Pic_0854_0_0,
    Pic_0853_0_0,
    Pic_0852_0_0,
    Pic_0851_0_0,
    Pic_0850_0_0,
    Pic_0849_0_0,
    Pic_0848_0_0,
    Pic_0847_0_0,
    Pic_0846_0_0,
    Pic_0845_0_0,
    Pic_0844_0_0,
    Pic_0843_0_0,
    Pic_0842_0_0,
    Pic_0841_0_0,
    Pic_0840_0_0,
    Pic_0839_0_0,
    Pic_0838_0_0,
    Pic_0837_0_0,
    Pic_0836_0_0,
    Pic_0835_0_0,
    Pic_0834_0_0,
    Pic_0833_0_0,
    Pic_0832_0_0,
    Pic_0831_0_0,
    Pic_0830_0_0,
    Pic_0829_0_0,
    Pic_0828_0_0,
    Pic_0827_0_0,
    Pic_0826_0_0,
    Pic_0825_0_0,
    Pic_0824_0_0,
    Pic_0823_0_0,
    Pic_0822_0_0,
    Pic_0821_0_0,
    Pic_0820_0_0,
    Pic_0819_0_0,
    Pic_0818_0_0,
    Pic_0817_0_0,
    Pic_0816_0_0,
    Pic_0815_0_0,
    Pic_0814_0_0,
    Pic_0813_0_0,
    Pic_0812_0_0,
    Pic_0811_0_0,
    Pic_0810_0_0,
    Pic_0809_0_0,
    Pic_0808_0_0,
    Pic_0807_0_0,
    Pic_0806_0_0,
    Pic_0805_0_0,
    Pic_0804_0_0,
    Pic_0803_0_0,
    Pic_0802_0_0,
    Pic_0801_0_0,
    Pic_0800_0_0,
    Pic_0799_0_0,
    Pic_0798_0_0,
    Pic_0797_0_0,
    Pic_0796_0_0,
    Pic_0795_0_0,
    Pic_0794_0_0,
    Pic_0793_0_0,
    Pic_0792_0_0,
    Pic_0791_0_0,
    Pic_0790_0_0,
    Pic_0789_0_0,
    Pic_0788_0_0,
    Pic_0787_0_0,
    Pic_0786_0_0,
    Pic_0785_0_0,
    Pic_0784_0_0,
    Pic_0783_0_0,
    Pic_0782_0_0,
    Pic_0781_0_0,
    Pic_0780_0_0,
    Pic_0779_0_0,
    Pic_0778_0_0,
    Pic_0777_0_0,
    Pic_0776_0_0,
    Pic_0775_0_0,
    Pic_0774_0_0,
    Pic_0773_0_0,
    Pic_0772_0_0,
    Pic_0771_0_0,
    Pic_0770_0_0,
    Pic_0769_0_0,
    Pic_0768_0_0,
    Pic_0767_0_0,
    Pic_0766_0_0,
    Pic_0765_0_0,
    Pic_0764_0_0,
    Pic_0763_0_0,
    Pic_0762_0_0,
    Pic_0761_0_0,
    Pic_0760_0_0,
    Pic_0759_0_0,
    Pic_0758_0_0,
    Pic_0001_0_0
};
void AMT630H_Animation_PlayProc(uint16_t PicIndex)
{
    unsigned char *pBuf;
    uint32_t tmpLen = 0;
    SetPageGuid(GRAPHICS_PAGE_0, 1, 0, 0); 
    SetPageBackground(GRAPHICS_PAGE_0, PicIndex);
    PackedTransfer_Page();
  //  PackedTransfer_GetSwVer();

}
/* Timer */
void AMT630H_Timer(unsigned char Tms)
{
    unsigned char i = 0U;

    for(i = 0; i < ALIVE_COUNTER_TOTAL; i++)
    {
        if(AMT630H_REQ_Time[i] < AMT630H_ERR_TIME)
        {
            AMT630H_REQ_Time[i] += Tms;
        }
    }
    if(AMT630H_RefreshTime < AMT630H_REFRESH_TIME)
    {
        AMT630H_RefreshTime += Tms;
    }
    if(Delay_Time < Delay_Time_Set)
    {
        Delay_Time += Tms;
    }
    if(AMT630H_InitTime < 5000)
    {
        AMT630H_InitTime += Tms;
    }
    if(AMT630H_Animation_Finish == 0)
    {
        if(AMT630H_Animation_RefreshTime < AMT630H_ANIMATION_TIME)
        {
            AMT630H_Animation_RefreshTime += Tms;
        }
    }
    else
    {
        AMT630H_Animation_RefreshTime = 0;
    }
}
void Delay_Time_Ctrl(unsigned long Tms)
{
    Delay_Time = 0;
    Delay_Time_Set = Tms;

    while(Delay_Time < Delay_Time_Set)
    {
        RTE_WDT_Clear();
    }

    Delay_Time = 0;
    Delay_Time_Set = 0;
}

uint8_t UartRevBuff[0x1000] = { 0 };
uint32_t UartRevCnts = 0;
void Amt630hUartRecvData(uint16_t u16UARTData)
{
    UartRevBuff[UartRevCnts++] = (u16UARTData & 0xff);
    if (UartRevCnts >= 0x1000) 
    {
        UartRevCnts = 0;
    }
}
void AMT630H_RstCtrl(void)
{
    RTE_GPIO_Set_Level(VCC_33_EN_MCU, 0);//630
    RTE_GPIO_Set_Level(VCC1V2_AMT_EN, 0);//630
    RTE_GPIO_Set_Level(STBYB_LCD_MCU, 0);//lcd
    RTE_GPIO_Set_Level(MCU_RSTB_LCD, 0);//lcd
    Delay_Time_Ctrl(10);
    RTE_GPIO_Set_Level(VCC1V2_AMT_EN, 1);   
    Delay_Time_Ctrl(15);    
    RTE_GPIO_Set_Level(VCC_33_EN_MCU, 1);
    Delay_Time_Ctrl(30);
    RTE_GPIO_Set_Level(x1530_EN_MCU, 1);//1530
    Delay_Time_Ctrl(10);
    RTE_GPIO_Set_Level(MCU_RSTB_LCD, 1); 
    Delay_Time_Ctrl(15); 
    RTE_GPIO_Set_Level(STBYB_LCD_MCU, 1); 
   
}
void Amt630hInit(void)
{
    uint8_t i = 0;
    AMT630H_RstCtrl();
    AMT630H_RefreshTime = AMT630H_REFRESH_TIME;
    // Error State Init
    AMT630H_Err = 0U;
    for(i = 0; i < ALIVE_COUNTER_TOTAL; i++)
    {
        AMT630H_REQ_Time[i] = 0U;
        AMT630H_AliveCounter[i] = 0;
    }
    AMT630H_CrcErrTime = 0;
    AMT630H_CrcErrCounter = 0;

    // Param Config
    LcdSoundParamterData.LcdWidth = 1024;
    LcdSoundParamterData.LcdHeight = 600;
    LcdSoundParamterData.LcdBpp = 32;
    LcdSoundParamterData.LcdVideoInputValid = 0;
    LcdSoundParamterData.Ark7116ResetPin = 0;
    LcdSoundParamterData.LcdInterfaceType = LCD_INTERFACE_LVDS;
    LcdSoundParamterData.LcdWiringMode = LCD_WIRING_MODE_BGR;
    LcdSoundParamterData.LcdWiringBitOrder = LCD_WIRING_BIT_ORDER_MSB;
    LcdSoundParamterData.LcdDotClkReverse = 0;  /* NuoMa 50pin TFT */
    LcdSoundParamterData.LvdsPanelFormat = LVDS_PANEL_FORMAT_TI;
    LcdSoundParamterData.LvdsPanelData = LVDS_PANEL_DATA_8BIT;

    LcdSoundParamterData.LcdTimingVBP = 12;
    LcdSoundParamterData.LcdTimingVFP = 20;
    LcdSoundParamterData.LcdTimingVSW = 4;

    LcdSoundParamterData.LcdTimingHBP = 160;
    LcdSoundParamterData.LcdTimingHFP = 160;
    LcdSoundParamterData.LcdTimingHSW = 24;

    LcdSoundParamterData.LcdClkFreq = 51200000;

    LcdSoundParamterData.SoundChannelNum = 0;
    LcdSoundParamterData.SoundFreq = AUDIO_FREQ_48K;
    SetLcdSoundParameter(&LcdSoundParamterData);
    SetSwVerBuf((uint8_t*)&amt630Version);

    User_PicIndexDataInit();
    ResetInitedState();    

    AnalysisUartData();

    AMT630H_InitTime = 0;

    AMT630H_Animation_Start = 0;
    AMT630H_Animation_Finish = 0;
    AMT630H_Animation_DispPic = 0;
    AMT630H_Animation_RefreshTime = 0;
    AMT630H_Animation_RefreshTime_default = AMT630H_ANIMATION_REFRESHTIME_DEF(0);

    Amt630hInitFinishFlag = 0;

    AMT630H_FlashCheck.Flag = 0;
    AMT630H_FlashCheck.InquireTime = 0;
    AMT630H_FlashCheck.CheckStateTime = 0;
    AMT630H_FlashCheck.Result = 0;
    Check_Upgrade = 0;
    Check_Upgrade_Cnt = 0;
}
void AMT630H_Sleep(void)
{
    RTE_GPIO_Set_Level(STBYB_LCD_MCU, 0);    
    Delay_Time_Ctrl(30);    
    RTE_GPIO_Set_Level(VCC_33_EN_MCU, 0);
    RTE_GPIO_Set_Level(VCC1V2_AMT_EN, 0);
    RTE_GPIO_Set_Level(MCU_RSTB_LCD, 0);
    
}
static void AMT630H_AliveCounterMonitor(void)
{
    uint8_t i = 0;
    if(AMT630H_CrcErrCounter != GetCrcErrCnts())
    {
        AMT630H_CrcErrCounter = GetCrcErrCnts();
        AMT630H_CrcErrTime++;
        if(AMT630H_CrcErrTime >= 120)
        {
            AMT630H_Err = 1;
        }
        for(i = 0; i < ALIVE_COUNTER_TOTAL; i++)
        {
            AMT630H_REQ_Time[i] = 0;
        }
    }
    for(i = 0; i < ALIVE_COUNTER_TOTAL; i++)
    {
        if(AMT630H_AliveCounter[i] != GetAliveCounter(i))
        {
            AMT630H_AliveCounter[i] = GetAliveCounter(i);
            AMT630H_REQ_Time[i] = 0;
            if(AMT630H_CrcErrMaxCounter < AMT630H_CrcErrTime)
            {
                AMT630H_CrcErrMaxCounter = (unsigned char)AMT630H_CrcErrTime;
            }
            AMT630H_CrcErrTime = 0;
        }
        if(AMT630H_REQ_Time[i] >= AMT630H_ERR_TIME)
        {
            AMT630H_Err = 1;
        }
    }
}

void AMT630H_Main(void)
{
    unsigned char i;
    AnalysisUartData();
        
    if(GetLcdInitSt() != 1)
    {
        for(i = 0; i < ALIVE_COUNTER_TOTAL; i++)
        {
            AMT630H_REQ_Time[i] = 0U;           
        }
        return;
    }
    AMT630H_AliveCounterMonitor();
    if(AMT630H_Err == 1U)
    {
        AMT630H_Err = 0;
        Amt630hInit();
        AMT630H_Animation_Finish = 1;
        return;
    }
    // if(g_sysFlag_Lcdcheck == 1)
    // {
    //     if(AMT630H_FlashCheck.Flag == 0)
    //     {
    //         AMT630H_FlashCheck.Flag = 1;
    //         AMT630H_FlashCheck.InquireTime = 0;
    //         AMT630H_FlashCheck.CheckStateTime = 0;
    //         PackedTransfer_CheckFlash();           
    //         AMT630H_FlashCheck.Result = 0xFF;
    //     }
    //     if(AMT630H_FlashCheck.Flag == 1)
    //     {
    //         if(AMT630H_FlashCheck.InquireTime >= 100)
    //         {
    //             AMT630H_FlashCheck.InquireTime = 0;
    //             AMT630H_FlashCheck.Result = PackedTransfer_CheckFlashGetResult();
    //             if(AMT630H_FlashCheck.Result != 0xFF)
    //             {
    //                 if(AMT630H_FlashCheck.Result == 1)
    //                 {
    //                     PackedTransfer_CheckFlashForceDisplay(DISPLAY_CHECK_PASS, 3000);
    //                     AMT630H_FlashCheck.Flag = 2;
    //                 }
    //                 else if (AMT630H_FlashCheck.CheckStateTime >= FLASH_CHECK_TIME_NUM)
    //                 {
    //                     PackedTransfer_CheckFlashForceDisplay(DISPLAY_CHECK_FAIL, 60000);
    //                     AMT630H_FlashCheck.Flag = 2;
    //                 }
    //             }
                
    //         }
    //         else
    //         {
    //             PackedTransfer_CheckFlashForceDisplay(DISPLAY_CHECKING, 60000);
    //         }
    //     }
    // }
    if (SYS_OPR_STAT_IGN_ON)
    {
        if(AMT630H_Animation_Finish == 1)
        {
            AMT630H_Animation_RefreshTime = 0;
            if(AMT630H_RefreshTime >= AMT630H_REFRESH_TIME)
            {                
                AMT630H_RefreshTime = 0;
                AMT630H_GUI_DisplayProc();
                //SetPageGuid(GRAPHICS_PAGE_0, 1, 0, 0);
                //SetPageBackground( GRAPHICS_PAGE_0, Pic_0001_0_0 );
                //SetPagePic(GRAPHICS_PAGE_0, Pic_0002_751_440);
                //SetPagePic(GRAPHICS_PAGE_0, Pic_0003_681_441);
                //SetPagePic(GRAPHICS_PAGE_0, Pic_0005_521_444);
                //SetPagePic(GRAPHICS_PAGE_0, Pic_0010_90_443);
                //SetPagePic(GRAPHICS_PAGE_0, Pic_0012_0_95);
                //PackedTransfer_Page();
            }
        }
        else
        {
            AMT630H_RefreshTime = 0;
            if(AMT630H_Animation_Start == 0)
            {
                AMT630H_Animation_Start = 1;                
                AMT630H_Animation_RefreshTime_default = AMT630H_ANIMATION_REFRESHTIME_DEF(0);
            }
            if(AMT630H_Animation_RefreshTime >= AMT630H_Animation_RefreshTime_default)
            {
                AMT630H_Animation_RefreshTime = 0;
                AMT630H_Animation_PlayProc(BootAnimationList[AMT630H_Animation_DispPic]);
                AMT630H_Animation_DispPic++;
                if(AMT630H_Animation_DispPic >= AMT630H_ANIMATION_PIC_NUM)
                {
                    AMT630H_Animation_Finish = 1;
                }
            }
        } 
        

    }
    else
    {
        AMT630H_Animation_RefreshTime = 0;
        if(AMT630H_RefreshTime >= AMT630H_REFRESH_TIME)
        {
            AMT630H_RefreshTime = 0;
            //AMT630H_GUI_DisplayProc();
        }
    }
}

unsigned char AMT630H_isInitFinish(void)
{
    if((AMT630H_InitTime >= 600) || (GetLcdInitSt() == 1))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}