use VS1033(MP3 decoder) and UL024TF(TFTLCD)

Dependencies:   FastIO SDFileSystem TFTLCDwithFastIO TouchPanel VS1033 mbed

Fork of 11U68_MP3Player with TFTLCD by en 129

Revision:
9:96b053c0865e
Parent:
8:198b69e78c39
Child:
10:93267d24ad1a
--- a/main.cpp	Thu Jul 30 02:36:18 2015 +0000
+++ b/main.cpp	Thu Jul 30 06:54:23 2015 +0000
@@ -15,13 +15,13 @@
 //(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)
 ILI9328_LCD lcd( P0_12, P0_11, P0_13, P0_14, NULL, NC, P1_9 ); // control pins and data bus
 
-SDFileSystem sd(/*MOSI*/ P0_9, /*MISO*/ P0_8, /*SCK*/ P1_29, /*CS*/ P0_2, /*Mountpoint*/ "sd", NC, SDFileSystem::SWITCH_NONE, 10000000);
+SDFileSystem sd(/*MOSI*/ P0_9, /*MISO*/ P0_8, /*SCK*/ P1_29, /*CS*/ P0_2, /*Mountpoint*/ "sd", NC, SDFileSystem::SWITCH_NONE, 20000000);
 VS1053       mp3(/*MOSI*/ P1_22 , /*MISO*/ P1_21, /*SCK*/ P1_20, /*CS*/ P1_23,
                  /*BSYNC*/ P2_17, /*DREQ*/ P2_16, /*RST*/ P2_18, /*SPI freq.*/ 5000000);
 Ticker Int100ms;
 
 Serial pc(P0_19,P0_18);
-#define SD_READ_BLOCK_SIZE (512)
+#define SD_READ_BLOCK_SIZE (256)
 
 #define BOTTON_PREV_XPOS    (15)
 #define BOTTON_PREV_YPOS    (180)
@@ -172,6 +172,8 @@
     uint8_t     buf[SD_READ_BLOCK_SIZE];
     char        str[100];
     int32_t     XReadPos = 0,YReadPos = 0;
+    uint32_t    aveXReadPos = 0,aveYReadPos = 0;
+    uint8_t     c_TouchPanelAve = 0;
     bool        touchPanel_Touched = 0;
     uint32_t    totalPlay = 0;
     int         dot1_FileSize = 0;
@@ -188,17 +190,20 @@
 
 //    const bitmap_t img_button_volup     = { RGB16, 60, 60, &bmp_button_volup };
 //    const bitmap_t img_button_voldown   = { RGB16, 60, 60, &bmp_button_voldown };
-    
+
+
     pc.baud(921600);
     printf("Power ON\r\n");
 
-    Int100ms.attach_us(&Int100msFunc, 100000);
+    Int100ms.attach_us(&Int100msFunc, 10000);
 
     //SD Init.(本来ならいらないけど、SDカードによっちゃもう1回リセットしないとダメポ
     sd.disk_initialize();
+    printf("SDCard inited.\r\n"); 
 
     //LCD Init.
     lcd.Initialize(LANDSCAPE,RGB16);
+    printf("LCD inited.\r\n"); 
 
 /* for sine test mode */
 //    mp3.sine_test_activate(SineWave_10k);
@@ -209,7 +214,7 @@
     mp3.sci_init();
     mp3.sdi_init();
     wait(0.1);
-
+    printf("VS1033 inited.\r\n"); 
     printf("init CMPL.\r\n"); 
 
     lcd.SetBackground(COLOR_BLUE);
@@ -286,9 +291,13 @@
 #define MP3_STATE_RESUMEREQ     (11)
     
     printf("file count=%d\r\n",SDFileList_cnt);
+
     mp3PlayingFileNo = 0;
     g_mp3Player_State = MP3_STATE_FILECHANGE;
     f_mp3Playwe_Playing = 0;
+    lcd.Print("STOP      ",15,145);
+    lcd.DrawRect(135,155,310,165,COLOR_WHITE);
+    lcd.FillRect(136,156,309,164,COLOR_BLUE);
 
     while(1)
     {
@@ -298,286 +307,339 @@
 //////////////////////////////////////////////////////////////
         if(gf_TimerInt == 1)
         {
+            gf_TimerInt = 0;
+
             XReadPos = getTouchPanelPosX();
             YReadPos = getTouchPanelPosY();
-//            printf("X:%d Y:%d\r\n",XReadPos,YReadPos);
-            switch( detectTouchBotton(XReadPos,YReadPos) )
+
+            if( detectTouchBotton(XReadPos,YReadPos) == TOUCHPANEL_BOTTON_NOT_TOUCH )
+            {
+                c_TouchPanelAve = 0;
+                touchPanel_Touched = 0;
+                aveXReadPos = 0;
+                aveYReadPos = 0;
+            }
+            #define TOUCHPANEL_AVERAGE_COUNT (5)
+            else if(c_TouchPanelAve <= TOUCHPANEL_AVERAGE_COUNT)
             {
-                case TOUCHPANEL_BOTTON_TOUCH_PREV:
-                    if(touchPanel_Touched == 0)
-                    {
-                        printf("prev touch\r\n");
-                        g_mp3Player_State = MP3_STATE_PREVREQ;
-                        touchPanel_Touched = 1;
-                    }
-                    break;
-                case TOUCHPANEL_BOTTON_TOUCH_PLAY:
-                    if(touchPanel_Touched == 0)
-                    {
-                        printf("play touch\r\n");
-                        if( (g_mp3Player_State == MP3_STATE_STOPPING) )
+                printf("X:%d Y:%d\r\n",XReadPos,YReadPos);
+                aveXReadPos = aveXReadPos + XReadPos;
+                aveYReadPos = aveYReadPos + YReadPos;
+                c_TouchPanelAve++;
+            }
+            if(c_TouchPanelAve == TOUCHPANEL_AVERAGE_COUNT)
+            {
+                aveXReadPos = aveXReadPos/TOUCHPANEL_AVERAGE_COUNT;
+                aveYReadPos = aveYReadPos/TOUCHPANEL_AVERAGE_COUNT;
+                c_TouchPanelAve = (TOUCHPANEL_AVERAGE_COUNT+1);
+                printf("Xave:%d Yave:%d\r\n",aveXReadPos,aveYReadPos);
+            }
+            if(c_TouchPanelAve == (TOUCHPANEL_AVERAGE_COUNT+1) )
+            {
+                switch( detectTouchBotton(aveXReadPos,aveYReadPos) )
+                {
+                    case TOUCHPANEL_BOTTON_TOUCH_PREV:
+                        if(touchPanel_Touched == 0)
                         {
-                            g_mp3Player_State = MP3_STATE_PLAYREQ;
-                            printf("MP3_STATE_PLAYREQ\r\n");
-                        }
-                        if( g_mp3Player_State == MP3_STATE_PLAYING )
-                        {
-                            g_mp3Player_State = MP3_STATE_PAUSEREQ;
-                            printf("MP3_STATE_PAUSEREQ\r\n");
-                        }
-                        if( g_mp3Player_State == MP3_STATE_PAUSEING )
-                        {
-                            g_mp3Player_State = MP3_STATE_RESUMEREQ;
-                            printf("MP3_STATE_RESUMEREQ\r\n");
+                            printf("prev touch\r\n");
+                            g_mp3Player_State = MP3_STATE_PREVREQ;
+                            touchPanel_Touched = 1;
                         }
-
-                        touchPanel_Touched = 1;
-                    }
-                    break;
-                case TOUCHPANEL_BOTTON_TOUCH_STOP:
-                    if(touchPanel_Touched == 0)
-                    {
-                        printf("stop touch\r\n");
-                        if( (g_mp3Player_State != MP3_STATE_STOPPING) && (g_mp3Player_State != MP3_STATE_STOPREQ) )
+                        break;
+                    case TOUCHPANEL_BOTTON_TOUCH_PLAY:
+                        if(touchPanel_Touched == 0)
                         {
-                            g_mp3Player_State = MP3_STATE_STOPREQ;
+                            printf("play touch\r\n");
+                            if( (g_mp3Player_State == MP3_STATE_STOPPING) )
+                            {
+                                g_mp3Player_State = MP3_STATE_PLAYREQ;
+                                printf("MP3_STATE_PLAYREQ\r\n");
+                            }
+                            if( g_mp3Player_State == MP3_STATE_PLAYING )
+                            {
+                                g_mp3Player_State = MP3_STATE_PAUSEREQ;
+                                printf("MP3_STATE_PAUSEREQ\r\n");
+                            }
+                            if( g_mp3Player_State == MP3_STATE_PAUSEING )
+                            {
+                                g_mp3Player_State = MP3_STATE_RESUMEREQ;
+                                printf("MP3_STATE_RESUMEREQ\r\n");
+                            }
+    
+                            touchPanel_Touched = 1;
                         }
-                        touchPanel_Touched = 1;
-                    }
-                    break;
-                case TOUCHPANEL_BOTTON_TOUCH_NEXT:
-                    if(touchPanel_Touched == 0)
-                    {
-                        printf("next touch\r\n");
-                        g_mp3Player_State = MP3_STATE_NEXTREQ;
-                        touchPanel_Touched = 1;
-                    }
-                    break;
-                case TOUCHPANEL_OTHER_TOUCH:
-                    printf("otherTouch\r\n");
-                    printf("X:%d Y:%d\r\n",XReadPos,YReadPos);
-                    break;
-                case TOUCHPANEL_BOTTON_NOT_TOUCH:
-//                    printf("notTouch\r\n");
-                    touchPanel_Touched = 0;
-                    break;
-                default :
-                    break;
+                        break;
+                    case TOUCHPANEL_BOTTON_TOUCH_STOP:
+                        if(touchPanel_Touched == 0)
+                        {
+                            printf("stop touch\r\n");
+                            if( (g_mp3Player_State != MP3_STATE_STOPPING) && (g_mp3Player_State != MP3_STATE_STOPREQ) )
+                            {
+                                g_mp3Player_State = MP3_STATE_STOPREQ;
+                            }
+                            touchPanel_Touched = 1;
+                        }
+                        break;
+                    case TOUCHPANEL_BOTTON_TOUCH_NEXT:
+                        if(touchPanel_Touched == 0)
+                        {
+                            printf("next touch\r\n");
+                            g_mp3Player_State = MP3_STATE_NEXTREQ;
+                            touchPanel_Touched = 1;
+                        }
+                        break;
+                    case TOUCHPANEL_OTHER_TOUCH:
+                        //printf("otherTouch\r\n");
+                        //printf("X:%d Y:%d\r\n",XReadPos,YReadPos);
+                        break;
+                    case TOUCHPANEL_BOTTON_NOT_TOUCH:
+                        //printf("notTouch\r\n");
+                        touchPanel_Touched = 0;
+                        break;
+                    default :
+                        break;
+                }
             }
         }
 
 //////////////////////////////////////////////////////////////
 /*  MP3 Player Control Section                              */
 //////////////////////////////////////////////////////////////
-        if(g_mp3Player_State == MP3_STATE_PLAYREQ)
-        {
-            printf("FileOpen:%s\r\n",mp3PlayingFileName);
-            fp = fopen(mp3PlayingFileName, "rb");
-            SDFileOpenFailCnt = 0;
-            while(!fp)
-            {
-                SDFileOpenFailCnt+=1;
-                if(SDFileOpenFailCnt >= 3)
-                {
-                    printf("Fail SD init\r\n");
-                    printf("System Stop.\r\n");
-                    NVIC_SystemReset();
-                }
-                printf("Fail file open n=%d\r\n",SDFileOpenFailCnt);
-                sd.disk_initialize();
-                fp = fopen(mp3PlayingFileName, "rb");
-                wait(1);
-            }
-
-            //Get file size
-            fseek( fp, 0, SEEK_END );
-            mp3_fileSize = ftell( fp );
-            printf("FileOpen. size=%dbit\r\n",mp3_fileSize);
-
-            //move file pointer to top.
-            rewind(fp);
-            clearerr(fp);
-            mp3_totalSizeSent = 0;
-            lcd.Print("Playing   ",15,145);
-
-            lcd.DrawRect(135,155,310,165,COLOR_WHITE);
-            lcd.FillRect(136,156,309,164,COLOR_BLUE);
-            dot1_FileSize = mp3_fileSize/175;           
-
-            g_mp3Player_State = MP3_STATE_PLAYING;
-            lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_pause, 1 );
-
-            totalPlay++;
-            printf("PlayCount=%d\r\n",totalPlay);
-        }
-        if( g_mp3Player_State == MP3_STATE_PLAYING )
-        {
-
-            if(mp3_totalSizeSent>=mp3_fileSize) //play song end
-            {
-                f_mp3Playwe_Playing = 1;
-                g_mp3Player_State = MP3_STATE_NEXTREQ;  //next song
-            }
-            else                                //transmit from SDCard to VS1033
-            {
-                if( mp3.checkDREQ() == 1 )
-                {                   
-                    mp3_ReadFileSize = fread(buf, sizeof(uint8_t), SD_READ_BLOCK_SIZE, fp);
-                    mp3_totalSizeSent += mp3.sendDataBlock(buf, mp3_ReadFileSize);
-                    dot_XPos = mp3_totalSizeSent / dot1_FileSize;
-                    if(old_dot_XPos != dot_XPos)
-                    {
-                        lcd.DrawLine(135+dot_XPos, 156, 135+dot_XPos, 164); //x1:135 y1:155 x2:310 y3:165
-                    }
-                    old_dot_XPos = dot_XPos;
-//                    printf("SendedSize:%d LinePos:%d\r\n",mp3_totalSizeSent,dot_XPos);
-//                    printf(" HDAT0:0x%x HDAT1:0x%x\r\n",mp3.readReg(mp3.SCI_HDAT0),mp3.readReg(mp3.SCI_HDAT1));
-
-                }
-
-                f_mp3Playwe_Playing = 1;
-            }
-        }
-
-        if( g_mp3Player_State == MP3_STATE_PAUSEREQ )
-        {
-            lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_play, 1 );
-            g_mp3Player_State = MP3_STATE_PAUSEING;
-        }
-        if( g_mp3Player_State == MP3_STATE_PAUSEING )
-        {
-        }
-        if( g_mp3Player_State == MP3_STATE_RESUMEREQ )
-        {
-            lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_pause, 1 );
-            g_mp3Player_State = MP3_STATE_PLAYING;
-        }
-        if( (g_mp3Player_State == MP3_STATE_STOPREQ) || (g_mp3Player_State == MP3_STATE_REPLAY) )
+        switch(g_mp3Player_State)
         {
-            uint16_t returnCode=0;
-            uint16_t stopFailCnt = 0;
-            do
+            case MP3_STATE_PLAYREQ:
             {
-                returnCode = mp3.stop();
-                printf("STOP\r\nSTOP CODE:%d\r\n",returnCode);
-                printf(" HDAT0:0x%x HDAT1:0x%x\r\n",mp3.readReg(mp3.SCI_HDAT0),mp3.readReg(mp3.SCI_HDAT1));
-
-                if(returnCode != 0)
-                {
-                    stopFailCnt++;
-                }
-                if(stopFailCnt >= 20)
+                printf("FileOpen:%s\r\n",mp3PlayingFileName);
+                fp = fopen(mp3PlayingFileName, "rb");
+                SDFileOpenFailCnt = 0;
+                while(!fp)
                 {
-                    printf("ERROR! impossible of stop\r\nVS1033 Reset\r\n");
-                    mp3.hardwareReset();
-                    mp3.sci_init();
-                    mp3.sdi_init();
+                    SDFileOpenFailCnt+=1;
+                    if(SDFileOpenFailCnt >= 3)
+                    {
+                        printf("Fail SD init\r\n");
+                        printf("System Stop.\r\n");
+                        NVIC_SystemReset();
+                    }
+                    printf("Fail file open n=%d\r\n",SDFileOpenFailCnt);
+                    sd.disk_initialize();
+                    fp = fopen(mp3PlayingFileName, "rb");
                     wait(1);
-                    stopFailCnt = 0;
-                    returnCode = 0;
                 }
-            }while(returnCode != 0);
-
-            fclose(fp);
-            fp = NULL;
-            f_mp3Playwe_Playing = 0;
-            lcd.Print("STOP      ",15,145);
-
-            if(g_mp3Player_State == MP3_STATE_STOPREQ)
+    
+                //Get file size
+                fseek( fp, 0, SEEK_END );
+                mp3_fileSize = ftell( fp );
+                printf("FileOpen. size=%dbit\r\n",mp3_fileSize);
+    
+                //move file pointer to top.
+                rewind(fp);
+                clearerr(fp);
+                mp3_totalSizeSent = 0;
+                lcd.Print("Playing   ",15,145);
+    
+                lcd.DrawRect(135,155,310,165,COLOR_WHITE);
+                lcd.FillRect(136,156,309,164,COLOR_BLUE);
+                dot1_FileSize = mp3_fileSize/175;           
+    
+                g_mp3Player_State = MP3_STATE_PLAYING;
+                lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_pause, 1 );
+    
+                totalPlay++;
+                printf("PlayCount=%d\r\n",totalPlay);
+                break;
+            }
+            case MP3_STATE_PLAYING:
             {
-                g_mp3Player_State = MP3_STATE_STOPPING;
+                if(mp3_totalSizeSent>=mp3_fileSize) //play song end
+                {
+                    f_mp3Playwe_Playing = 1;
+                    g_mp3Player_State = MP3_STATE_NEXTREQ;  //next song
+                }
+                else                                //transmit from SDCard to VS1033
+                {
+                    if( mp3.checkDREQ() == 1 )
+                    {                   
+                        mp3_ReadFileSize = fread(buf, sizeof(uint8_t), SD_READ_BLOCK_SIZE, fp);
+                        mp3_totalSizeSent += mp3.sendDataBlock(buf, mp3_ReadFileSize);
+                        dot_XPos = mp3_totalSizeSent / dot1_FileSize;
+                        if(old_dot_XPos != dot_XPos)
+                        {
+                            lcd.DrawLine(135+dot_XPos, 156, 135+dot_XPos, 164); //x1:135 y1:155 x2:310 y3:165
+                        }
+                        old_dot_XPos = dot_XPos;
+                        //printf("SendedSize:%d LinePos:%d\r\n",mp3_totalSizeSent,dot_XPos);
+                        //printf(" HDAT0:0x%x HDAT1:0x%x\r\n",mp3.readReg(mp3.SCI_HDAT0),mp3.readReg(mp3.SCI_HDAT1));
+                    }
+                    f_mp3Playwe_Playing = 1;
+                }
+                break;
             }
-            if(g_mp3Player_State == MP3_STATE_REPLAY)
+            case MP3_STATE_PAUSEREQ:
             {
-                g_mp3Player_State = MP3_STATE_PLAYREQ;
+                lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_play, 1 );
+                g_mp3Player_State = MP3_STATE_PAUSEING;
+                break;
             }
-        }
-
-        if( g_mp3Player_State == MP3_STATE_STOPPING )
-        {
-            f_mp3Playwe_Playing = 0;
-        }
-
-        if( g_mp3Player_State == MP3_STATE_NEXTREQ )
-        {
-            if( mp3PlayingFileNo >= (SDFileList_cnt -1) )
+            case MP3_STATE_PAUSEING:
+            {
+                break;
+            }
+            case MP3_STATE_RESUMEREQ:
             {
-                mp3PlayingFileNo = 0;
-            }
-            else
-            {
-                mp3PlayingFileNo+=1;
+                lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_pause, 1 );
+                g_mp3Player_State = MP3_STATE_PLAYING;
+                break;
             }
-            g_mp3Player_State = MP3_STATE_FILECHANGE;
-        }
-
-        if( g_mp3Player_State == MP3_STATE_PREVREQ )
-        {
-            if( mp3PlayingFileNo <= 0 )
+        
+            case MP3_STATE_STOPREQ:
+            case MP3_STATE_REPLAY:
             {
-                mp3PlayingFileNo = (SDFileList_cnt - 1);
-            }
-            else
-            {
-                mp3PlayingFileNo-=1;
+                uint16_t returnCode=0;
+                uint16_t stopFailCnt = 0;
+                uint16_t readHDAT0,readHDAT1;
+    
+                lcd.Print("STOP      ",15,145);
+                lcd.DrawRect(135,155,310,165,COLOR_WHITE);
+                lcd.FillRect(136,156,309,164,COLOR_BLUE);
+                lcd.DrawBitmap( BOTTON_PLAY_XPOS,    BOTTON_PLAY_YPOS,    (const bitmap_t*)&img_button_play, 1 );
+    
+                do
+                {
+                    returnCode = mp3.stop();
+                    readHDAT0 = mp3.readReg(mp3.SCI_HDAT0);
+                    readHDAT1 = mp3.readReg(mp3.SCI_HDAT1);
+                    returnCode = readHDAT0||readHDAT1;
+    
+                    printf("STOP\r\nSTOP CODE:%d\r\n",returnCode);
+                    printf(" HDAT0:0x%x HDAT1:0x%x\r\n",readHDAT0,readHDAT1);
+    
+                    if(returnCode != 0 )
+                    {
+                        stopFailCnt++;
+                    }
+                    if(stopFailCnt >= 20)
+                    {
+                        printf("ERROR! impossible of stop\r\nVS1033 Reset\r\n");
+                        mp3.hardwareReset();
+                        mp3.sci_init();
+                        mp3.sdi_init();
+                        wait(1);
+                        stopFailCnt = 0;
+                        returnCode = 0;
+                    }
+                }while(returnCode != 0);
+    
+                fclose(fp);
+                fp = NULL;
+                f_mp3Playwe_Playing = 0;
+    
+                if(g_mp3Player_State == MP3_STATE_STOPREQ)
+                {
+                    g_mp3Player_State = MP3_STATE_STOPPING;
+                }
+                if(g_mp3Player_State == MP3_STATE_REPLAY)
+                {
+                    g_mp3Player_State = MP3_STATE_PLAYREQ;
+                }
+                break;
             }
-            g_mp3Player_State = MP3_STATE_FILECHANGE;
-        }
-        if( g_mp3Player_State == MP3_STATE_FILECHANGE )
-        {
-            printf("next:%d,%s\r\n",mp3PlayingFileNo,SDFileList[mp3PlayingFileNo]);
-
-            lcd_FileViewPage = mp3PlayingFileNo/5;
-            if(old_lcd_FileViewPage != lcd_FileViewPage)
+            case MP3_STATE_STOPPING:
             {
-                lcd.FillRect(0,0,320,140,COLOR_BLUE);
+                f_mp3Playwe_Playing = 0;
+                break;
             }
-            old_lcd_FileViewPage = lcd_FileViewPage;
-
-            if(SDFileList_cnt >= 5)
+            case MP3_STATE_NEXTREQ:
             {
-                if( (SDFileList_cnt-(5*lcd_FileViewPage)) >= 5 )
+                if( mp3PlayingFileNo >= (SDFileList_cnt -1) )
                 {
-                    lcd_FileViewListEnd = (5*lcd_FileViewPage+5);
-
+                    mp3PlayingFileNo = 0;
                 }
                 else
                 {
-                    lcd_FileViewListEnd = (5*lcd_FileViewPage+ ((SDFileList_cnt-(5*lcd_FileViewPage))%5) );
-                }
-                printf("FilePage:%d max:%d\r\n",lcd_FileViewPage, lcd_FileViewListEnd);
-
-                for(i=(5*lcd_FileViewPage); i<lcd_FileViewListEnd; i++)
-                {
-                    sprintf(str,"%d:%s",i,SDFileList_short[i]);
-                    lcd.Print( str, LEFT, (i%5)*28 ); // align text to center horizontally and use starndard colors
+                    mp3PlayingFileNo+=1;
                 }
+                g_mp3Player_State = MP3_STATE_FILECHANGE;
+                break;
             }
-            else
+            case MP3_STATE_PREVREQ:
             {
-                for(i=0;i<SDFileList_cnt;i++)
+                if( mp3PlayingFileNo <= 0 )
                 {
-                    sprintf(str,"%d:%s",i,SDFileList_short[i]);
-                    lcd.Print( str, LEFT, i*28 ); // align text to center horizontally and use starndard colors
+                    mp3PlayingFileNo = (SDFileList_cnt - 1);
                 }
+                else
+                {
+                    mp3PlayingFileNo-=1;
+                }
+                g_mp3Player_State = MP3_STATE_FILECHANGE;
+                break;
             }
-            if(mp3PlayingFileNo >= 10)
+
+            case MP3_STATE_FILECHANGE:
             {
-                lcd.Print( "**", LEFT, 28*(mp3PlayingFileNo%5) ); // align text to center horizontally and use starndard colors
-            }
-            else
-            {
-                lcd.Print( "*", LEFT, 28*(mp3PlayingFileNo%5) ); // align text to center horizontally and use starndard colors
+                printf("next:%d,%s\r\n",mp3PlayingFileNo,SDFileList[mp3PlayingFileNo]);
+    
+                lcd_FileViewPage = mp3PlayingFileNo/5;
+                if(old_lcd_FileViewPage != lcd_FileViewPage)
+                {
+                    lcd.FillRect(0,0,320,140,COLOR_BLUE);
+                }
+                old_lcd_FileViewPage = lcd_FileViewPage;
+    
+                if(SDFileList_cnt >= 5)
+                {
+                    if( (SDFileList_cnt-(5*lcd_FileViewPage)) >= 5 )
+                    {
+                        lcd_FileViewListEnd = (5*lcd_FileViewPage+5);
+    
+                    }
+                    else
+                    {
+                        lcd_FileViewListEnd = (5*lcd_FileViewPage+ ((SDFileList_cnt-(5*lcd_FileViewPage))%5) );
+                    }
+                    printf("FilePage:%d max:%d\r\n",lcd_FileViewPage, lcd_FileViewListEnd);
+    
+                    for(i=(5*lcd_FileViewPage); i<lcd_FileViewListEnd; i++)
+                    {
+                        sprintf(str,"%d:%s",i,SDFileList_short[i]);
+                        lcd.Print( str, LEFT, (i%5)*28 ); // align text to center horizontally and use starndard colors
+                    }
+                }
+                else
+                {
+                    for(i=0;i<SDFileList_cnt;i++)
+                    {
+                        sprintf(str,"%d:%s",i,SDFileList_short[i]);
+                        lcd.Print( str, LEFT, i*28 ); // align text to center horizontally and use starndard colors
+                    }
+                }
+
+                sprintf(str,"%d:%s",mp3PlayingFileNo,SDFileList_short[mp3PlayingFileNo]);
+                lcd.Print( str, LEFT, 28*(mp3PlayingFileNo%5),COLOR_YELLOW,-1,0 ); // align text to center horizontally and use starndard colors
+                if(mp3PlayingFileNo >= 10)
+                {
+                    lcd.Print( "**", LEFT, 28*(mp3PlayingFileNo%5),COLOR_YELLOW,-1,0); // align text to center horizontally and use starndard colors
+                }
+                else
+                {
+                    lcd.Print( "*", LEFT, 28*(mp3PlayingFileNo%5),COLOR_YELLOW,-1,0 ); // align text to center horizontally and use starndard colors
+                }
+                
+                sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]);
+                if(f_mp3Playwe_Playing == 1)
+                {
+                    g_mp3Player_State = MP3_STATE_REPLAY;
+                }
+                else
+                {
+                    g_mp3Player_State = MP3_STATE_STOPPING;
+                }
+                break;
             }
-            
-            sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]);
-            if(f_mp3Playwe_Playing == 1)
+            default:
             {
-                g_mp3Player_State = MP3_STATE_REPLAY;
-            }
-            else
-            {
-                g_mp3Player_State = MP3_STATE_STOPPING;
+                break;
             }
         }
     }