ircmd_card.c
上传用户:poi891205
上传日期:2013-07-15
资源大小:9745k
文件大小:18k
源码类别:

DVD

开发平台:

C/C++

  1. /**************************************************************************
  2.  * File Name:   ircmd_card.c
  3.  * Created:     2004.05.19 13:36 Maoyong 
  4.  * Description: contain some utilized functions for card switch or move/exist
  5.                 state check and so on
  6.  *************************************************************************/
  7. #if defined(SUPPORT_CARD_STORAGE)||defined(SUPPORT_USB)||defined(SPHE8202_CARD_STORAGE)
  8. #ifdef SUPPORT_USB
  9. extern UINT32 UsbTestReady(void);
  10. extern BYTE IsUSBCardReader(void);
  11. extern UINT8 USBCheckNextReadyLun(void);
  12. extern UINT8 CBWLUN;
  13. #ifdef SWITCH_BETWEEN_USB_CARDS //for different cards swithch on USB card reader
  14. #define MAX_USB_CARDS  4       //one port for SD/MS/SM/MMC, another for CF/Micro Driver(zhongshan modify for usb cardreader 4 port)
  15. UINT8  card_switch_times = 0;   //record times switch between cards, if = 2, switch to CD
  16. #endif  //#ifdef SWITCH_BETWEEN_USB_CARDS
  17. #endif  //#ifdef SUPPORT_USB
  18. extern BYTE ReadPercent;
  19. extern CARD_FILE       cardFile;
  20. extern void InitVar(void);
  21. #ifdef IR_SWITCH_CARD_CD //lijd 2004-9-30 10:25
  22. extern UINT8 atapi_p_start_stop_unit(UINT8 start);
  23. extern UINT8 USBCheckNextReadyLun(void);//zhongshan add 01/14
  24. #endif
  25. #ifdef IR_SWITCH_CD_USB_CF_OTHER  //dingzhy 04-10-22
  26. BYTE now_valid_type = 0;
  27. BYTE    detect_result_last = 0; 
  28. extern void polling_storage(void);
  29. #endif
  30. #ifdef FILE_MODE_WRITE//added by wangwei,2005-1-25 9:29
  31. extern BYTE file_mode_flag;
  32. #endif
  33. /**************************************************************************
  34.  * Functioin:  SwitchMedia
  35.  * Input:      direction: CARD2CD/CD2CARD/CARD2CARD
  36.  * Purpose:    used for switch media between card and cd / card and card
  37.  *************************************************************************/
  38. void SwitchMedia(BYTE direction)
  39. {
  40.     if( (direction == CD2CARD) || (direction == CARD2CARD) )
  41.     {
  42.         InitVar();      //maoyong 2004.05.25 just treat as change disc
  43.         media_type = MEDIA_CARD; 
  44.         cardFile.status = CARD_STATUS_NORMAL;   //for flow control, status will be set dynamically so no influence.
  45.         #ifndef SP1000_NO_DVD
  46.         atapi_p_start_stop_unit(START_STOP_DO_STOP);
  47.         #endif //#ifndef SP1000_NO_DVD
  48.     }
  49.     else if(direction == CARD2CD)
  50.     {
  51.      GPIO_O_SET(17,1);//dingzhy for off the card light 4-10-23 14:18
  52.         no_disk_cnt = DETECT_TIMES;
  53.         media_type = MEDIA_CD;          
  54.         adv_search_time = 0;
  55. #ifndef SPHE1000 //Jeff 20041217
  56.         atapi_open_tray();  //Maoyong 2004-8-10 11:00
  57.         atapi_close_tray(0);
  58. #endif
  59.     }
  60.     AVD_SetMediaTimeout();
  61.     play_state = VCD_STATE_CLOSE;   
  62.     full_scrn = 0;     
  63.     ClearOsdMsg(0);     
  64.     t_disp = 0; 
  65.     osd_init();
  66.     ircmd_post_func(CMD_FUNC | CMD_FUNC_OPEN);                  
  67.     system_state = SYSTEM_OPEN;    
  68.    
  69. }
  70. /**************************************************************************
  71.  * Functioin:  IsCardMediaExist
  72.  * Purpose:    used for switch condition check, if return FALSE, can't switch
  73.                to Card Media now.
  74.  *************************************************************************/
  75. BYTE IsCardMediaExist(void)
  76. {
  77.     if( CARDIsPlugIn() )
  78.     {
  79.         //Maoyong 2004.05.20 for other storage_type and USB Card reader consideration
  80.         #ifdef SUPPORT_USB
  81.         if(storage_type&USB_DEVICE)
  82.         {
  83.             if( !UsbTestReady() )
  84.                 return FALSE;
  85.         }
  86.         #endif
  87.         
  88.         //Maoyong 2004.05.21 for flow control when switch to CD, to avoid SwitchMedia 
  89.         //called again and back to CARD again when IsCardMediaRemove called.        
  90.         cardFile.status = CARD_STATUS_NORMAL;
  91.         return TRUE;        
  92.     }    
  93.     return FALSE;
  94. }
  95. /**************************************************************************
  96.  * Functioin:  IsCardMediaRemove
  97.  * Purpose:    play card media program, check if card remove when no card
  98.                data reading such as: Jpeg/MPEG/MP4 file list, pause state
  99.  *************************************************************************/
  100. BYTE IsCardMediaRemove(void)
  101. {
  102.     if (media_type == MEDIA_CARD) 
  103.     {
  104. //        if ( CardGetStatus() == CARD_STATUS_NG ) 
  105.         if ( FSGetStatus() == CARD_STATUS_NG ) 
  106.         {
  107.             #if defined(SUPPORT_CARD_STORAGE)||defined(SUPPORT_USB)
  108.             #ifndef HOST_UHCI                                                                                                                                                                       
  109.             CardReset();
  110.             #endif 
  111.             #endif
  112.             //Mp3ReadFinish = 0;
  113.             //ircmd_stop();            
  114.             SwitchMedia(CARD2CD); 
  115.             return 1;
  116.         }
  117.     }
  118.     return 0;    
  119. }
  120. /**************************************************************************
  121.  * Functioin:  show_card_reading_osd
  122.  * input:      SHOW_MEDIA/SHOW_READ_PERCENT/SHOW_OFF (gb_def.h)
  123.  * Purpose:    display card media reading info: type/read file percent
  124.  *************************************************************************/
  125. void  show_card_reading_osd(BYTE type)
  126. {
  127.     #ifdef PMP_UI//liweihua 2004-12-22 13:56
  128.     return;
  129.     #endif
  130.     if(ReadPercent > 100)
  131.         ReadPercent = 100;
  132.     #ifdef FILE_MODE_WRITE//develope use,for switching to play CDROM show "read usb" bug, modified by wangwei,2005-1-24 15:07
  133.     if((type != SHOW_OFF)&&(!file_mode_flag))
  134.     #else
  135.     if(type != SHOW_OFF)
  136.     #endif
  137.     {
  138.         #ifdef SWITCH_BETWEEN_USB_CARDS    //Maoyong 2004.05.25 here just for USB
  139.         if(type == SHOW_MEDIA)
  140.         {
  141.         if(storage_type & USB_DEVICE)
  142.         {
  143.             //show card number 1, 2, 3...
  144.             psprintf(RegionValStr[REGION1], "READ CARD %d", CBWLUN+1);
  145.             PrintOsdMsg(STR_OS_SPACE, REGION1, 0, 1);
  146.             }
  147.         }
  148.         else //SHOW_READ_PERCENT
  149.         {
  150.             psprintf(RegionValStr[REGION1], "READ CARD %d %02d%s  [%04d]", CBWLUN+1, ReadPercent, "%", pFsJpeg->iso9660_file_cnt);
  151.             if(storage_type & USB_DEVICE)
  152.             {
  153.                 //show reading percent here
  154.                 PrintOsdMsg(STR_OS_SPACE, REGION1, 0, 1);
  155.             }
  156.         }
  157.         #else  //SWITCH_BETWEEN_USB_CARDS
  158.         if(type == SHOW_MEDIA)
  159.         {
  160.             //if(storage_type & USB_DEVICE)
  161.             if(storage_type)//liweihua mod 2004-6-9
  162.             {
  163.                 //show card number 1, 2, 3...
  164.                if(storage_type & USB_DEVICE) 
  165.                 psprintf(RegionValStr[REGION1], "READ USB");  //wthsin, 2004/7/19 03:02pm
  166.                else  
  167.                 psprintf(RegionValStr[REGION1], "READ CARD");
  168.                PrintOsdMsg(STR_OS_SPACE, REGION1, 0, 1);
  169.             }
  170.         }
  171.         else
  172.         {
  173.             if(storage_type & USB_DEVICE)  //wthsin, 2004/7/19 03:02pm
  174.              psprintf(RegionValStr[REGION1], "READ USB %02d%s  [%04d]", ReadPercent, "%", pFsJpeg->iso9660_file_cnt);
  175.             else    
  176.              psprintf(RegionValStr[REGION1], "READ CARD %02d%s  [%04d]", ReadPercent, "%", pFsJpeg->iso9660_file_cnt);
  177.             
  178. if(storage_type & USB_DEVICE)
  179.             {
  180.                 //show reading percent
  181.                 PrintOsdMsg(STR_OS_SPACE, REGION1, 0, 1);
  182.             }
  183.         }
  184.         #endif //SWITCH_BETWEEN_USB_CARDS
  185.     }
  186.     else    //turn off osd display
  187.         ClearOsdMsg(1);
  188. }
  189. /* SWITCH_BETWEEN_USB_CARDS: CD--->USB CARD A ---> USB CARD B ---> CD in turn */
  190. #if defined(IR_SWITCH_CARD_CD) || defined(SUPPORT_SPI_QSI) //Maoyong 2004.05.13
  191. void  ircmd_switch_card_cd(void)
  192. {
  193.     if(media_type == MEDIA_CD)      //switch CD to Card
  194.     {
  195.         if( IsCardMediaExist() )
  196.         {
  197.             #ifdef SWITCH_BETWEEN_USB_CARDS
  198.             card_switch_times = 1;
  199.             #endif
  200.             SwitchMedia(CD2CARD);  
  201.         }
  202.         else 
  203.         {   
  204.             psprintf(RegionValStr[REGION1], "CARD NOT FOUND");  
  205.             PrintOsdMsg(STR_OS_SPACE, REGION1, 1, 1);           
  206.         }   
  207.     }
  208.     else    //switch from card  to cd, in fact should check if no disc here!
  209.     {
  210.         #ifdef SWITCH_BETWEEN_USB_CARDS
  211.         if( storage_type&USB_DEVICE )
  212.         {
  213.             if( IsUSBCardReader() && USBCheckNextReadyLun()&& (card_switch_times < MAX_USB_CARDS) )
  214.             {
  215.                 card_switch_times++;
  216.                 SwitchMedia(CARD2CARD);
  217.             }
  218.             else
  219.             {
  220.                 SwitchMedia(CARD2CD);
  221.                 card_switch_times = 0;
  222.             }
  223.         }
  224.         #else  //SWITCH_BETWEEN_USB_CARDS
  225.         SwitchMedia(CARD2CD);
  226.         #endif //SWITCH_BETWEEN_USB_CARDS
  227.     }
  228. }
  229. #endif //#ifdef  IR_SWITCH_CARD_CD
  230. #ifdef IR_SWITCH_CD_USB_CF_OTHER  //added by dingzhy  4-10-20 13:57
  231. void ircmd_switch_cd_usb_cf_other(void)
  232. {
  233.     if(media_type == MEDIA_CD)      //switch CD to Card
  234.     {
  235.      if( IsCardMediaExist() )
  236.            {
  237.             now_valid_type = detect_type;//for bug:read cf,insert usb,will read cf again.
  238.          SwitchMedia(CD2CARD);
  239.          }
  240.         else 
  241.             {   
  242.         if(play_state != VCD_STATE_OPEN)
  243.              {
  244.         psprintf(RegionValStr[REGION1], "USB/CARD NOT FOUND");  
  245.         PrintOsdMsg(STR_OS_SPACE, REGION1, 1, 1);           
  246.          }
  247.             }   
  248.     }  
  249.         
  250.     else if(detect_result_last==0x01)   //when play USB
  251.     {
  252.      if(detect_type == 0x01)
  253.      SwitchMedia(CARD2CD);
  254.      else
  255.      {
  256.         now_valid_type = (detect_type & 0x1e);
  257.         SwitchMedia(CD2CARD);
  258.         }
  259.      }   
  260.     else if(detect_result_last==0x02)   //when play CF
  261.     {
  262.      if((detect_type == 0x03)||(detect_type == 0x02))
  263.      {
  264.      now_valid_type = 0;
  265.      SwitchMedia(CARD2CD);
  266.      }
  267.      else
  268.      {
  269.         now_valid_type = (detect_type & 0x1c);
  270.         SwitchMedia(CD2CARD);
  271.         }
  272.         
  273.      }   
  274.     else //play other card  dingzhy 4-10-22 13:52
  275.     {
  276.     SwitchMedia(CARD2CD);
  277.     now_valid_type = 0;
  278.     }
  279. }
  280. #endif //#ifdef IR_SWITCH_CD_USB_CF_OTHER
  281. #ifdef SWITCH_CD_CARD_USB//liweihua add 2004-6-8 13:57, for swtich between cd/card/usb
  282. //color define
  283. #define COLOR_WHITE         2
  284. #define COLOR_GRAY          3
  285. #define COLOR_GRAYWHITE     14
  286. #define COLOR_YELLOW        7
  287. #define COLOR_YELLOWGREEN   9
  288. #define COLOR_DBLUE         4
  289. #define COLOR_LBLUE         6
  290. #define COLOR_GREEN         13
  291. #define COLOR_ORANGE        5
  292. //button id define
  293. #define CDBUTTON            0
  294. #ifdef SUPPORT_USB
  295. #define USBBUTTON           CDBUTTON+1
  296. #else
  297. #define USBBUTTON           CDBUTTON
  298. #endif
  299. #define CFBUTTON            (USBBUTTON+1)
  300. #define SDBUTTON            (USBBUTTON+2)
  301. #define MSBUTTON            (USBBUTTON+3)
  302. #define SMCBUTTON           (USBBUTTON+4)
  303. //define osd parameter
  304. #define RWIDTH      64*4
  305. #define RHEIGHT     288
  306. #define GUIREGION   3
  307. BYTE *show_string[] = { "READ CD",
  308.                         #ifdef SUPPORT_USB
  309.                         "READ USB",
  310.                         #endif
  311.                         "READ CF",
  312.                         "READ SD/MMC",
  313.                         "READ MS/MS PRO",
  314.                         "READ SMC",
  315.                         };
  316. BYTE select_media_type = 0;//define selected media type through switch gui
  317. BYTE hilight_button_id;
  318. void draw_switch_background(void)
  319. {
  320.     osd_draw_region_rect(0, 0, RWIDTH, RHEIGHT, COLOR_LBLUE, GUIREGION);
  321.     osd_DrawRegionLine(0, 0, RWIDTH-1, 0, COLOR_WHITE, 1, GUIREGION);
  322.     osd_DrawRegionLine(0, 0, 0, RHEIGHT-1, COLOR_WHITE, 1, GUIREGION);
  323.     osd_DrawRegionLine(RWIDTH-1, 0, RWIDTH-1, RHEIGHT, COLOR_GRAY,1, GUIREGION);
  324.     osd_DrawRegionLine(0, RHEIGHT-1, RWIDTH, RHEIGHT-1, COLOR_GRAY, 1, GUIREGION);    
  325. }
  326. void draw_switch_button(BYTE button_id,BYTE fontcolor,BYTE backcolor,BYTE region)
  327. {
  328.     osd_DrawRegionString(1, button_id*8+6, show_string[button_id],fontcolor,backcolor,region);    
  329. }
  330. void show_switch_gui(void)
  331. {
  332.     osd_init_switchGUI();
  333.     hilight_button_id = 0;
  334.     if(detect_type == 0)
  335.     {
  336.         psprintf(RegionValStr[REGION1], "USB/CARD NOT FOUND");
  337.         PrintOsdMsg(STR_OS_SPACE, REGION1, 1, 1);   
  338.     }
  339.     else
  340.     {
  341.         draw_switch_background();
  342.         if(media_type == MEDIA_CARD)
  343.             hilight_button_id = CDBUTTON;
  344.         else if((detect_type & USB_DEVICE) ) 
  345.             hilight_button_id = USBBUTTON;
  346.         else if((detect_type & CF_CARD_DEVICE)) 
  347.             hilight_button_id = CFBUTTON;
  348.         else if((detect_type & SD_CARD_DEVICE)) 
  349.             hilight_button_id = SDBUTTON;
  350.         else if((detect_type & MS_CARD_DEVICE)) 
  351.             hilight_button_id = MSBUTTON;
  352.         else if((detect_type & SMC_CARD_DEVICE)) 
  353.             hilight_button_id = SMCBUTTON;
  354.         
  355.         hilight_button(hilight_button_id);
  356.     }
  357.     
  358. }
  359. //draw default button 
  360. void set_switch_button(void)
  361. {
  362.     BYTE i;
  363.     //DRAW all button with gray font
  364.     for(i=CDBUTTON;i<=SMCBUTTON;i++)
  365.         draw_switch_button(i,COLOR_GRAY,COLOR_LBLUE,GUIREGION);
  366.         
  367.     //draw all exist media button with white font
  368.     //CD button    
  369.     if(media_type == MEDIA_CARD)
  370.         draw_switch_button(CDBUTTON,COLOR_WHITE,COLOR_LBLUE,GUIREGION);
  371.     // USB button
  372.     #ifdef SUPPORT_USB
  373.     if(detect_type & USB_DEVICE)
  374.         draw_switch_button(USBBUTTON,COLOR_WHITE,COLOR_LBLUE,GUIREGION);
  375.     #endif
  376.     // CF button
  377.     if(detect_type & CF_CARD_DEVICE)
  378.         draw_switch_button(CFBUTTON,COLOR_WHITE,COLOR_LBLUE,GUIREGION);
  379.     // SD/MMC button
  380.     if(detect_type & SD_CARD_DEVICE)
  381.         draw_switch_button(SDBUTTON,COLOR_WHITE,COLOR_LBLUE,GUIREGION);
  382.     // MS/MS pro button
  383.     if(detect_type & MS_CARD_DEVICE)
  384.         draw_switch_button(MSBUTTON,COLOR_WHITE,COLOR_LBLUE,GUIREGION);
  385.     // SMC button
  386.     if(detect_type & SMC_CARD_DEVICE)
  387.         draw_switch_button(SMCBUTTON,COLOR_WHITE,COLOR_LBLUE,GUIREGION);
  388. }
  389. //draw default button and hilight the current select button
  390. void hilight_button(BYTE button_id)
  391. {
  392.     set_switch_button();
  393.     osd_DrawRegionString(1, button_id*8+6, show_string[button_id],COLOR_WHITE,COLOR_ORANGE,GUIREGION); 
  394. }
  395. void switch_gui_up(void)
  396. {
  397.     BYTE offset;
  398.     BYTE current_type;
  399.     offset = detect_type << (7-hilight_button_id);
  400.     if((media_type == MEDIA_CARD)&&(hilight_button_id <= CDBUTTON))
  401.         hilight_button_id = CDBUTTON;
  402.     else if((media_type == MEDIA_CD) && (hilight_button_id <= (CDBUTTON+1)))
  403.         hilight_button_id = CDBUTTON+1;
  404.     else if(offset > 0)
  405.     {
  406.         hilight_button_id--;
  407.         if(hilight_button_id > CDBUTTON)
  408.         {
  409.             #ifdef SUPPORT_USB
  410.             current_type = 0x01<<(hilight_button_id-1);
  411.             #else
  412.             current_type = 0x01<<(hilight_button_id);
  413.             #endif
  414.             if((current_type & detect_type) == 0)
  415.             {
  416.                 hilight_button_id--;
  417.                 if((media_type == MEDIA_CD) && (hilight_button_id == CDBUTTON))
  418.                 return;
  419.             }
  420.         }
  421.         hilight_button(hilight_button_id);
  422.     }
  423. }
  424. void switch_gui_down(void)
  425. {
  426.     BYTE offset;
  427.     BYTE current_type;
  428.     offset = detect_type>>hilight_button_id;
  429.     if(hilight_button_id>=SMCBUTTON)
  430.         hilight_button_id = SMCBUTTON;
  431.     #ifdef SUPPORT_USB
  432.     else if((detect_type>>hilight_button_id) > 0)
  433.     #else
  434.     else if((detect_type>>(hilight_button_id+1)) > 0)
  435.     #endif
  436.     {
  437.         hilight_button_id++;
  438.         #ifdef SUPPORT_USB
  439.         current_type = 0x01<<(hilight_button_id-1);
  440.         #else
  441.         current_type = 0x01<<(hilight_button_id);
  442.         #endif
  443.         if((current_type & detect_type) == 0)
  444.             hilight_button_id++;
  445.         hilight_button(hilight_button_id);
  446.     }
  447. }
  448. void switch_gui_select(void)
  449. {
  450.     BYTE current_type;
  451.     
  452.     AVD_SetMediaInterrupt();
  453.     
  454.     switch(hilight_button_id)
  455.     {
  456.         case CDBUTTON:
  457.             select_media_type = 0;
  458.             SwitchMedia(CARD2CD);
  459.             break;
  460.         #ifdef SUPPORT_USB
  461.         case USBBUTTON:
  462.             select_media_type = USB_DEVICE;
  463.             SwitchMedia(CD2CARD);
  464.             break;
  465.         #endif
  466.         case CFBUTTON:
  467.             select_media_type = CF_CARD_DEVICE;
  468.             SwitchMedia(CD2CARD);
  469.             break;
  470.         case SDBUTTON:
  471.             select_media_type = SD_CARD_DEVICE;
  472.             SwitchMedia(CD2CARD);
  473.             break;
  474.         case MSBUTTON:
  475.             select_media_type = MS_CARD_DEVICE;
  476.             SwitchMedia(CD2CARD);
  477.             break;
  478.         case SMCBUTTON:
  479.             select_media_type = SMC_CARD_DEVICE;
  480.             break;
  481.         default:
  482.             break;
  483.     }
  484. }
  485. void ircmd_switch_cd_card_usb(void)
  486. {
  487.     if(play_state == VCD_STATE_OPEN)
  488.         return;
  489.     if (full_scrn & SWITCH_GUI)
  490.     {
  491.         full_scrn &= (~SWITCH_GUI);
  492.         #ifdef CD_PLAYER 
  493.         if(cd_type_loaded==CDDA)
  494.         {
  495.             osd_init_cdplayer();
  496.         }else               
  497.             osd_init();
  498.         #else
  499.         osd_init();
  500.         #endif
  501.     }
  502.     else
  503.     {
  504.         if((full_scrn & MARK)||(full_scrn & GOTO))
  505.         {
  506.             invalid_key();
  507.             return;
  508.         }
  509.         full_scrn |= SWITCH_GUI;
  510.         show_switch_gui();
  511.         //Maoyong added for IR U/D/L/R/Sel proc func setting 2004-9-24 9:59
  512.         SetFullscrnCmdFuncPtr( switch_gui_up, switch_gui_down, ircmd_null,
  513.                                    ircmd_null, switch_gui_select);
  514.     }
  515. }
  516. #endif//#ifdef SWITCH_CD_CARD_USB
  517. //liweihua add 2004-11-11 21:19
  518. #ifdef FAT_FILE_MODE
  519. void ircmd_card_copy(void)
  520. {
  521.     if(fat_play_mode == 1)
  522.     {
  523.         if(pFsJpeg->ControlArea == CNT_AREA_CARD)
  524.         {
  525.             if(pFsJpeg->gifsState == FS_STATE_HDD)
  526.                 CardCopy();
  527.             else
  528.             {
  529.                 FATCopy();
  530.              }
  531.         }
  532.         else
  533.         {
  534.             invalid_key();
  535.             return;
  536.         }
  537.     }
  538. }
  539. void ircmd_card_delete(void)
  540. {
  541.     if(fat_play_mode == 1)
  542.     {
  543.         FATDelete();
  544.         return;
  545.     }
  546. }
  547. #endif
  548. #endif  //#if defined(SUPPORT_CARD_STORAGE)||defined(SUPPORT_USB)||defined(SPHE8202_CARD_STORAGE)