use VS1033(MP3 decoder) and UL024TF(TFTLCD)

Dependencies:   FastIO SDFileSystem TFTLCDwithFastIO TouchPanel VS1033 mbed

Fork of 11U68_MP3Player with TFTLCD by en 129

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #pragma O3
00002 
00003 #include "FastIO.h"
00004 #include "ili9328.h"
00005 #include "stdio.h"
00006 #include "string.h"
00007 #include "SDFileSystem.h"
00008 #include "VS1053.h"
00009 #include "image.h"
00010 #include "TouchPanel.h"
00011 #include "mbed.h"
00012 
00013 //(PinName CS, PinName RESET, PinName RS, PinName WR, BusOut *DATA_PORT, PinName BL=NC, PinName RD=NC, backlight_t blType=Constant, float defaultBackLightLevel=1.0)
00014 //LCDのバスピンはTFTLCDライブラリ内のili9328.cpp内に記述する改変をしている
00015 ILI9328_LCD lcd( P0_12, P0_11, P0_13, P0_14, NULL, NC, P1_9 ); // control pins and data bus
00016 
00017 SDFileSystem sd(/*MOSI*/ P0_9, /*MISO*/ P0_8, /*SCK*/ P1_29, /*CS*/ P0_2, /*Mountpoint*/ "sd", NC, SDFileSystem::SWITCH_NONE, 20000000);
00018 
00019 VS1053       mp3(/*MOSI*/ P1_22 , /*MISO*/ P1_21, /*SCK*/ P1_20, /*CS*/ P1_23,
00020                  /*BSYNC*/ P2_17, /*DREQ*/ P2_16, /*RST*/ P2_18, /*SPI freq.*/ 5000000);
00021 Ticker Int10ms;
00022 
00023 Serial pc(P0_19,P0_18);
00024 #define SD_READ_BLOCK_SIZE (256)
00025 
00026 //操作用ボタンの配置座標
00027 #define BOTTON_PREV_XPOS    (15)
00028 #define BOTTON_PREV_YPOS    (180)
00029 #define BOTTON_PLAY_XPOS    (91)
00030 #define BOTTON_PLAY_YPOS    (180)
00031 #define BOTTON_STOP_XPOS    (168)
00032 #define BOTTON_STOP_YPOS    (180)
00033 #define BOTTON_NEXT_XPOS    (245)
00034 #define BOTTON_NEXT_YPOS    (180)
00035 
00036 //prevボタンのタッチ判定関数
00037 bool checkTouchBotton_prev(int32_t xpos,int32_t ypos)
00038 {
00039     bool result = 0;
00040     if( ( (xpos >= BOTTON_PREV_XPOS+5) && (xpos <= BOTTON_PREV_XPOS+55) ) &&
00041         ( (ypos >= BOTTON_PREV_YPOS+5) && (ypos <= BOTTON_PREV_YPOS+55) ) )
00042      {
00043          result = 1;
00044      }
00045      return result;
00046 }
00047 
00048 //playボタンのタッチ判定関数
00049 bool checkTouchBotton_play(int32_t xpos,int32_t ypos)
00050 {
00051     bool result = 0;
00052     if( ( (xpos >= BOTTON_PLAY_XPOS+5) && (xpos <= BOTTON_PLAY_XPOS+55) ) &&
00053         ( (ypos >= BOTTON_PLAY_YPOS+5) && (ypos <= BOTTON_PLAY_YPOS+55) ) )
00054      {
00055          result = 1;
00056      }
00057      return result;
00058 }
00059 
00060 //stopボタンのタッチ判定関数
00061 bool checkTouchBotton_stop(int32_t xpos,int32_t ypos)
00062 {
00063     bool result = 0;
00064     if( ( (xpos >= BOTTON_STOP_XPOS+5) && (xpos <= BOTTON_STOP_XPOS+55) ) &&
00065         ( (ypos >= BOTTON_STOP_XPOS+5) && (ypos <= BOTTON_STOP_XPOS+55) ) )
00066      {
00067          result = 1;
00068      }
00069      return result;
00070 }
00071 
00072 //nextボタンのタッチ判定関数
00073 bool checkTouchBotton_next(int32_t xpos,int32_t ypos)
00074 {
00075     bool result = 0;
00076     if( ( (xpos >= BOTTON_NEXT_XPOS+5) && (xpos <= BOTTON_NEXT_XPOS+55) ) &&
00077         ( (ypos >= BOTTON_NEXT_YPOS+5) && (ypos <= BOTTON_NEXT_YPOS+55) ) )
00078      {
00079          result = 1;
00080      }
00081      return result;
00082 }
00083 
00084 //どのボタンが押されたかの定義
00085 #define TOUCHPANEL_BOTTON_TOUCH_STOP    (0)
00086 #define TOUCHPANEL_BOTTON_TOUCH_PLAY    (1)
00087 #define TOUCHPANEL_BOTTON_TOUCH_NEXT    (2)
00088 #define TOUCHPANEL_BOTTON_TOUCH_PREV    (3)
00089 #define TOUCHPANEL_BOTTON_TOUCH_VOLUP   (4)
00090 #define TOUCHPANEL_BOTTON_TOUCH_VOLDOWN (5)
00091 #define TOUCHPANEL_BOTTON_NOT_TOUCH     (-1)
00092 #define TOUCHPANEL_OTHER_TOUCH          (-2)
00093 
00094 //タッチ検出用関数
00095 int8_t detectTouchBotton(int32_t xpos,int32_t ypos)
00096 {
00097     int8_t         result = 0;
00098 
00099     if( checkTouchBotton_stop(xpos,ypos) )
00100     {
00101         result = TOUCHPANEL_BOTTON_TOUCH_STOP;
00102     }
00103     else if( checkTouchBotton_play(xpos,ypos) )
00104     {
00105         result = TOUCHPANEL_BOTTON_TOUCH_PLAY;
00106     }
00107     else if( checkTouchBotton_prev(xpos,ypos) )
00108     {
00109         result = TOUCHPANEL_BOTTON_TOUCH_PREV;
00110     }
00111     else if( checkTouchBotton_next(xpos,ypos) )
00112     {
00113         result = TOUCHPANEL_BOTTON_TOUCH_NEXT;
00114     }
00115     else if( (xpos == -1) || (ypos == -1) )
00116     {
00117         result = TOUCHPANEL_BOTTON_NOT_TOUCH;
00118     }
00119     else
00120     {
00121         result = TOUCHPANEL_OTHER_TOUCH;
00122     }
00123     
00124     return result;    
00125 }
00126 
00127 uint8_t     g_mp3Player_State = 0;
00128 uint16_t    g_mp3Player_Volume = 0;
00129 bool        gf_mp3Playwe_VolmeUpdate = 0;
00130 bool        gf_TimerInt = 0;
00131 
00132 void Int10msFunc()
00133 {
00134     gf_TimerInt = 1;
00135 }
00136 
00137 int main()
00138 {
00139     static FILE *fp = NULL;
00140     uint8_t     SDFileOpenFailCnt = 0;
00141     size_t      mp3_ReadFileSize = 0;
00142     size_t      mp3_totalSizeSent=0;
00143     size_t      mp3_fileSize=0;
00144     bool        f_mp3Playwe_Playing = 0;
00145     uint8_t     buf[SD_READ_BLOCK_SIZE];
00146     char        str[100];
00147     int32_t     XReadPos = 0,YReadPos = 0;
00148     uint32_t    aveXReadPos = 0,aveYReadPos = 0;
00149     uint8_t     c_TouchPanelAve = 0;
00150     bool        touchPanel_Touched = 0;
00151     uint32_t    totalPlay = 0;
00152     int         dot1_FileSize = 0;
00153     int         dot_XPos = 0,old_dot_XPos = 0;
00154     int         lcd_FileViewPage = 0,old_lcd_FileViewPage = 0;
00155     int         lcd_FileViewListEnd = 0;
00156 
00157                                           //Format,Xsize,Ysize,PixelData
00158     const bitmap_t img_button_play      = { RGB16, 60, 60, &bmp_button_play };
00159     const bitmap_t img_button_stop      = { RGB16, 60, 60, &bmp_button_stop };
00160     const bitmap_t img_button_next      = { RGB16, 60, 60, &bmp_button_next };
00161     const bitmap_t img_button_prev      = { RGB16, 60, 60, &bmp_button_prev };
00162     const bitmap_t img_button_pause     = { RGB16, 60, 60, &bmp_button_pause };
00163 
00164     pc.baud(921600);
00165     printf("Power ON\r\n");
00166 
00167     Int10ms.attach_us(&Int10msFunc, 10000);
00168 
00169     //SD Init.(本来ならいらないけど、SDカードによっちゃもう1回リセットしないとアクセスできない場合あり
00170     sd.disk_initialize();
00171     printf("SDCard inited.\r\n"); 
00172 
00173     //LCD Init.
00174     lcd.Initialize(LANDSCAPE,RGB16);
00175     printf("LCD inited.\r\n"); 
00176 
00177 /* for sine test mode */
00178 //    mp3.sine_test_activate(SineWave_10k);
00179 //    while(1);
00180 
00181     //MP3 decoder Init.
00182     mp3.hardwareReset();
00183     mp3.sci_init();
00184     mp3.sdi_init();
00185     wait(0.1);
00186     printf("VS1033 inited.\r\n"); 
00187     printf("init CMPL.\r\n"); 
00188 
00189     //バックスクリーン色を青色に指定し、画面全体をバックスクリーン色で塗りつぶし
00190     lcd.SetBackground(COLOR_BLUE);
00191     lcd.FillScreen(-1);
00192     //フォント指定
00193     lcd.SetFont( &TerminusBigFont );
00194 
00195   //for Caliblation
00196     while(0)
00197     {
00198         int32_t     XReadPos = 0,YReadPos = 0;
00199         lcd.DrawCircle(40,40,10,COLOR_WHITE);
00200         lcd.DrawCircle(280,200,10,COLOR_WHITE);
00201         XReadPos = getTouchPanelPosX();
00202         YReadPos = getTouchPanelPosY();
00203         printf("X:%d Y:%d\r\n",XReadPos,YReadPos);
00204         wait_ms(500);
00205     }
00206 
00207     //MP3プレイヤー操作用ボタンを配置
00208                     //Xpos, Ypos, ImageData(type:bitmap_t), Scale
00209     lcd.DrawBitmap( BOTTON_PREV_XPOS,    BOTTON_PREV_YPOS,    (const bitmap_t*)&img_button_prev, 1 );
00210     lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_play, 1 );
00211     lcd.DrawBitmap( BOTTON_STOP_XPOS,    BOTTON_STOP_YPOS,    (const bitmap_t*)&img_button_stop, 1 );
00212     lcd.DrawBitmap( BOTTON_NEXT_XPOS,    BOTTON_STOP_YPOS,    (const bitmap_t*)&img_button_next, 1 );
00213 
00214 ////////////////////////////////////////////////////////////
00215 /*  SDCard GetFileList Section                            */
00216 ////////////////////////////////////////////////////////////
00217 #define SD_MAX_FILENAME_LENGTH  (256)   //MAX 256
00218 #define SD_MAX_FILE_COUNT       (50)
00219 
00220     char SDFileList[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0};
00221     char SDFileList_short[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0};
00222     char SDFileList_cnt = 0;
00223     char mp3PlayingFileName[SD_MAX_FILENAME_LENGTH]={0};
00224     uint8_t mp3PlayingFileNo = 0;
00225     int i = 0;
00226     DIR *d;
00227     struct dirent *p;
00228 
00229     d = opendir("/sd");
00230     if ( d != NULL )
00231     {
00232         while ( (p = readdir(d)) != NULL )  //SDカード内のファイル一覧を取得
00233         {
00234             char *ret;
00235             ret = strstr(p->d_name,"System");   //System Vol..フォルダは除外
00236             if(ret == 0)
00237             {
00238                 sprintf((char *)(SDFileList_short[i]+0),"%s",(const char *)p->d_name);
00239                 sprintf((char *)(SDFileList[i]+0),"/sd/%s",(const char *)p->d_name);
00240                 printf("FileFound:%d,%s\r\n",i,SDFileList[i]);
00241                 i+=1;
00242             }
00243         }
00244         SDFileList_cnt = i;
00245     }
00246     closedir(d);
00247 
00248 //MP3プレイヤーの状態遷移定義
00249 //g_mp3Player_State変数にて使用
00250 #define MP3_STATE_STOPPING      (0)
00251 #define MP3_STATE_STOPREQ       (1)
00252 #define MP3_STATE_PLAYREQ       (2)
00253 #define MP3_STATE_PLAYING       (3)
00254 #define MP3_STATE_NEXTREQ       (4)
00255 #define MP3_STATE_PREVREQ       (5)
00256 #define MP3_STATE_VOLCHANGEREQ  (6)
00257 #define MP3_STATE_REPLAY        (7)
00258 #define MP3_STATE_FILECHANGE    (8)
00259 #define MP3_STATE_PAUSEREQ      (9)
00260 #define MP3_STATE_PAUSEING      (10)
00261 #define MP3_STATE_RESUMEREQ     (11)
00262     
00263     printf("file count=%d\r\n",SDFileList_cnt);
00264 
00265     mp3PlayingFileNo = 0;
00266     g_mp3Player_State = MP3_STATE_FILECHANGE;
00267     f_mp3Playwe_Playing = 0;
00268     lcd.Print("STOP      ",15,145);
00269     //プログレスバーの描画
00270     lcd.DrawRect(135,155,310,165,COLOR_WHITE);
00271     lcd.FillRect(136,156,309,164,COLOR_BLUE);
00272 
00273     while(1)
00274     {
00275 
00276 //////////////////////////////////////////////////////////////
00277 /*  TouchPanel GetStatas Section                            */
00278 //////////////////////////////////////////////////////////////
00279         if(gf_TimerInt == 1)    //10msタイマのフラグが立っていたらタッチパネル読み込みを行う
00280         {
00281             gf_TimerInt = 0;
00282 
00283             XReadPos = getTouchPanelPosX();
00284             YReadPos = getTouchPanelPosY();
00285 
00286             if( detectTouchBotton(XReadPos,YReadPos) == TOUCHPANEL_BOTTON_NOT_TOUCH )
00287             {
00288                 c_TouchPanelAve = 0;
00289                 touchPanel_Touched = 0;
00290                 aveXReadPos = 0;
00291                 aveYReadPos = 0;
00292             }
00293             #define TOUCHPANEL_AVERAGE_COUNT (5)        //5回読んだタッチパネル座標の平均値を取得
00294             else if(c_TouchPanelAve <= TOUCHPANEL_AVERAGE_COUNT)
00295             {
00296                 printf("X:%d Y:%d\r\n",XReadPos,YReadPos);
00297                 aveXReadPos = aveXReadPos + XReadPos;
00298                 aveYReadPos = aveYReadPos + YReadPos;
00299                 c_TouchPanelAve++;
00300             }
00301             if(c_TouchPanelAve == TOUCHPANEL_AVERAGE_COUNT)
00302             {
00303                 aveXReadPos = aveXReadPos/TOUCHPANEL_AVERAGE_COUNT;
00304                 aveYReadPos = aveYReadPos/TOUCHPANEL_AVERAGE_COUNT;
00305                 c_TouchPanelAve = (TOUCHPANEL_AVERAGE_COUNT+1);
00306                 printf("Xave:%d Yave:%d\r\n",aveXReadPos,aveYReadPos);
00307             }
00308             if(c_TouchPanelAve == (TOUCHPANEL_AVERAGE_COUNT+1) )    //平均値を元にどのボタンが押されたか判定
00309             {
00310                 switch( detectTouchBotton(aveXReadPos,aveYReadPos) )
00311                 {
00312                     case TOUCHPANEL_BOTTON_TOUCH_PREV:
00313                         if(touchPanel_Touched == 0)
00314                         {
00315                             printf("prev touch\r\n");
00316                             g_mp3Player_State = MP3_STATE_PREVREQ;
00317                             touchPanel_Touched = 1;
00318                         }
00319                         break;
00320                     case TOUCHPANEL_BOTTON_TOUCH_PLAY:
00321                         if(touchPanel_Touched == 0)
00322                         {
00323                             printf("play touch\r\n");
00324                             if( (g_mp3Player_State == MP3_STATE_STOPPING) )
00325                             {
00326                                 g_mp3Player_State = MP3_STATE_PLAYREQ;
00327                                 printf("MP3_STATE_PLAYREQ\r\n");
00328                             }
00329                             if( g_mp3Player_State == MP3_STATE_PLAYING )
00330                             {
00331                                 g_mp3Player_State = MP3_STATE_PAUSEREQ;
00332                                 printf("MP3_STATE_PAUSEREQ\r\n");
00333                             }
00334                             if( g_mp3Player_State == MP3_STATE_PAUSEING )
00335                             {
00336                                 g_mp3Player_State = MP3_STATE_RESUMEREQ;
00337                                 printf("MP3_STATE_RESUMEREQ\r\n");
00338                             }
00339     
00340                             touchPanel_Touched = 1;
00341                         }
00342                         break;
00343                     case TOUCHPANEL_BOTTON_TOUCH_STOP:
00344                         if(touchPanel_Touched == 0)
00345                         {
00346                             printf("stop touch\r\n");
00347                             if( (g_mp3Player_State != MP3_STATE_STOPPING) && (g_mp3Player_State != MP3_STATE_STOPREQ) )
00348                             {
00349                                 g_mp3Player_State = MP3_STATE_STOPREQ;
00350                             }
00351                             touchPanel_Touched = 1;
00352                         }
00353                         break;
00354                     case TOUCHPANEL_BOTTON_TOUCH_NEXT:
00355                         if(touchPanel_Touched == 0)
00356                         {
00357                             printf("next touch\r\n");
00358                             g_mp3Player_State = MP3_STATE_NEXTREQ;
00359                             touchPanel_Touched = 1;
00360                         }
00361                         break;
00362                     case TOUCHPANEL_OTHER_TOUCH:
00363                         //printf("otherTouch\r\n");
00364                         //printf("X:%d Y:%d\r\n",XReadPos,YReadPos);
00365                         break;
00366                     case TOUCHPANEL_BOTTON_NOT_TOUCH:
00367                         //printf("notTouch\r\n");
00368                         touchPanel_Touched = 0;
00369                         break;
00370                     default :
00371                         break;
00372                 }
00373             }
00374         }
00375 
00376 //////////////////////////////////////////////////////////////
00377 /*  MP3 Player Control Section                              */
00378 //////////////////////////////////////////////////////////////
00379         switch(g_mp3Player_State)
00380         {
00381             case MP3_STATE_PLAYREQ:
00382             {
00383                 printf("FileOpen:%s\r\n",mp3PlayingFileName);
00384                 fp = fopen(mp3PlayingFileName, "rb");
00385                 SDFileOpenFailCnt = 0;
00386                 while(!fp)
00387                 {
00388                     SDFileOpenFailCnt+=1;
00389                     if(SDFileOpenFailCnt >= 3)
00390                     {
00391                         printf("Fail SD init\r\n");
00392                         printf("System Stop.\r\n");
00393                         NVIC_SystemReset();
00394                     }
00395                     printf("Fail file open n=%d\r\n",SDFileOpenFailCnt);
00396                     sd.disk_initialize();
00397                     fp = fopen(mp3PlayingFileName, "rb");
00398                     wait(1);
00399                 }
00400     
00401                 //Get file size
00402                 fseek( fp, 0, SEEK_END );
00403                 mp3_fileSize = ftell( fp );
00404                 printf("FileOpen. size=%dbit\r\n",mp3_fileSize);
00405     
00406                 //move file pointer to top.
00407                 rewind(fp);
00408                 clearerr(fp);
00409                 mp3_totalSizeSent = 0;
00410                 lcd.Print("Playing   ",15,145);
00411     
00412                 lcd.DrawRect(135,155,310,165,COLOR_WHITE);
00413                 lcd.FillRect(136,156,309,164,COLOR_BLUE);
00414                 dot1_FileSize = mp3_fileSize/175;           
00415     
00416                 g_mp3Player_State = MP3_STATE_PLAYING;
00417                 lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_pause, 1 );
00418     
00419                 totalPlay++;
00420                 printf("PlayCount=%d\r\n",totalPlay);
00421                 break;
00422             }
00423             case MP3_STATE_PLAYING:
00424             {
00425                 if(mp3_totalSizeSent>=mp3_fileSize) //play song end
00426                 {
00427                     f_mp3Playwe_Playing = 1;
00428                     g_mp3Player_State = MP3_STATE_NEXTREQ;  //next song
00429                 }
00430                 else                                //transmit from SDCard to VS1033
00431                 {
00432                     if( mp3.checkDREQ() == 1 )
00433                     {                   
00434                         mp3_ReadFileSize = fread(buf, sizeof(uint8_t), SD_READ_BLOCK_SIZE, fp);
00435                         mp3_totalSizeSent += mp3.sendDataBlock(buf, mp3_ReadFileSize);
00436                         dot_XPos = mp3_totalSizeSent / dot1_FileSize;
00437                         if(old_dot_XPos != dot_XPos)
00438                         {
00439                             lcd.DrawLine(135+dot_XPos, 156, 135+dot_XPos, 164); //x1:135 y1:155 x2:310 y3:165
00440                         }
00441                         old_dot_XPos = dot_XPos;
00442                         //printf("SendedSize:%d LinePos:%d\r\n",mp3_totalSizeSent,dot_XPos);
00443                         //printf(" HDAT0:0x%x HDAT1:0x%x\r\n",mp3.readReg(mp3.SCI_HDAT0),mp3.readReg(mp3.SCI_HDAT1));
00444                     }
00445                     f_mp3Playwe_Playing = 1;
00446                 }
00447                 break;
00448             }
00449             case MP3_STATE_PAUSEREQ:
00450             {
00451                 lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_play, 1 );
00452                 g_mp3Player_State = MP3_STATE_PAUSEING;
00453                 break;
00454             }
00455             case MP3_STATE_PAUSEING:
00456             {
00457                 break;
00458             }
00459             case MP3_STATE_RESUMEREQ:
00460             {
00461                 lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_pause, 1 );
00462                 g_mp3Player_State = MP3_STATE_PLAYING;
00463                 break;
00464             }
00465         
00466             case MP3_STATE_STOPREQ:
00467             case MP3_STATE_REPLAY:
00468             {
00469                 uint16_t returnCode=0;
00470                 uint16_t stopFailCnt = 0;
00471                 uint16_t readHDAT0,readHDAT1;
00472     
00473                 lcd.Print("STOP      ",15,145);
00474                 lcd.DrawRect(135,155,310,165,COLOR_WHITE);
00475                 lcd.FillRect(136,156,309,164,COLOR_BLUE);
00476                 lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_play, 1 );
00477     
00478                 do
00479                 {
00480                     returnCode = mp3.stop();
00481                     readHDAT0 = mp3.readReg(mp3.SCI_HDAT0);
00482                     readHDAT1 = mp3.readReg(mp3.SCI_HDAT1);
00483                     returnCode = readHDAT0||readHDAT1;
00484     
00485                     printf("STOP\r\nSTOP CODE:%d\r\n",returnCode);
00486                     printf(" HDAT0:0x%x HDAT1:0x%x\r\n",readHDAT0,readHDAT1);
00487     
00488                     if(returnCode != 0 )
00489                     {
00490                         stopFailCnt++;
00491                     }
00492                     if(stopFailCnt >= 20)
00493                     {
00494                         printf("ERROR! impossible of stop\r\nVS1033 Reset\r\n");
00495                         mp3.hardwareReset();
00496                         mp3.sci_init();
00497                         mp3.sdi_init();
00498                         wait(1);
00499                         stopFailCnt = 0;
00500                         returnCode = 0;
00501                     }
00502                 }while(returnCode != 0);
00503     
00504                 fclose(fp);
00505                 fp = NULL;
00506                 f_mp3Playwe_Playing = 0;
00507     
00508                 if(g_mp3Player_State == MP3_STATE_STOPREQ)
00509                 {
00510                     g_mp3Player_State = MP3_STATE_STOPPING;
00511                 }
00512                 if(g_mp3Player_State == MP3_STATE_REPLAY)
00513                 {
00514                     g_mp3Player_State = MP3_STATE_PLAYREQ;
00515                 }
00516                 break;
00517             }
00518             case MP3_STATE_STOPPING:
00519             {
00520                 f_mp3Playwe_Playing = 0;
00521                 break;
00522             }
00523             case MP3_STATE_NEXTREQ:
00524             {
00525                 if( mp3PlayingFileNo >= (SDFileList_cnt -1) )
00526                 {
00527                     mp3PlayingFileNo = 0;
00528                 }
00529                 else
00530                 {
00531                     mp3PlayingFileNo+=1;
00532                 }
00533                 g_mp3Player_State = MP3_STATE_FILECHANGE;
00534                 break;
00535             }
00536             case MP3_STATE_PREVREQ:
00537             {
00538                 if( mp3PlayingFileNo <= 0 )
00539                 {
00540                     mp3PlayingFileNo = (SDFileList_cnt - 1);
00541                 }
00542                 else
00543                 {
00544                     mp3PlayingFileNo-=1;
00545                 }
00546                 g_mp3Player_State = MP3_STATE_FILECHANGE;
00547                 break;
00548             }
00549 
00550             case MP3_STATE_FILECHANGE:
00551             {
00552                 printf("next:%d,%s\r\n",mp3PlayingFileNo,SDFileList[mp3PlayingFileNo]);
00553     
00554                 lcd_FileViewPage = mp3PlayingFileNo/5;
00555                 if(old_lcd_FileViewPage != lcd_FileViewPage)
00556                 {
00557                     lcd.FillRect(0,0,320,140,COLOR_BLUE);
00558                 }
00559                 old_lcd_FileViewPage = lcd_FileViewPage;
00560     
00561                 if(SDFileList_cnt >= 5)
00562                 {
00563                     if( (SDFileList_cnt-(5*lcd_FileViewPage)) >= 5 )
00564                     {
00565                         lcd_FileViewListEnd = (5*lcd_FileViewPage+5);
00566     
00567                     }
00568                     else
00569                     {
00570                         lcd_FileViewListEnd = (5*lcd_FileViewPage+ ((SDFileList_cnt-(5*lcd_FileViewPage))%5) );
00571                     }
00572                     printf("FilePage:%d max:%d\r\n",lcd_FileViewPage, lcd_FileViewListEnd);
00573     
00574                     for(i=(5*lcd_FileViewPage); i<lcd_FileViewListEnd; i++)
00575                     {
00576                         sprintf(str,"%d:%s",i,SDFileList_short[i]);
00577                         lcd.Print( str, LEFT, (i%5)*28 ); // align text to center horizontally and use starndard colors
00578                     }
00579                 }
00580                 else
00581                 {
00582                     for(i=0;i<SDFileList_cnt;i++)
00583                     {
00584                         sprintf(str,"%d:%s",i,SDFileList_short[i]);
00585                         lcd.Print( str, LEFT, i*28 ); // align text to center horizontally and use starndard colors
00586                     }
00587                 }
00588 
00589                 sprintf(str,"%d:%s",mp3PlayingFileNo,SDFileList_short[mp3PlayingFileNo]);
00590                 lcd.Print( str, LEFT, 28*(mp3PlayingFileNo%5),COLOR_YELLOW,-1,0 ); // align text to center horizontally and use starndard colors
00591                 if(mp3PlayingFileNo >= 10)
00592                 {
00593                     lcd.Print( "**", LEFT, 28*(mp3PlayingFileNo%5),COLOR_YELLOW,-1,0); // align text to center horizontally and use starndard colors
00594                 }
00595                 else
00596                 {
00597                     lcd.Print( "*", LEFT, 28*(mp3PlayingFileNo%5),COLOR_YELLOW,-1,0 ); // align text to center horizontally and use starndard colors
00598                 }
00599                 
00600                 sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]);
00601                 if(f_mp3Playwe_Playing == 1)
00602                 {
00603                     g_mp3Player_State = MP3_STATE_REPLAY;
00604                 }
00605                 else
00606                 {
00607                     g_mp3Player_State = MP3_STATE_STOPPING;
00608                 }
00609                 break;
00610             }
00611             default:
00612             {
00613                 break;
00614             }
00615         }
00616     }    
00617 }