use VS1033(MP3 decoder) and UL024TF(TFTLCD)
Dependencies: TFTLCDwithFastIO FastIO SDFileSystem TouchPanel VS1033 mbed
Diff: main.cpp
- Revision:
- 8:198b69e78c39
- Parent:
- 7:fc65d965a569
- Child:
- 9:96b053c0865e
--- a/main.cpp Fri Jul 24 11:06:18 2015 +0000 +++ b/main.cpp Thu Jul 30 02:36:18 2015 +0000 @@ -1,5 +1,6 @@ #pragma O3 +#include "FastIO.h" #include "ili9328.h" #include "stdio.h" #include "string.h" @@ -10,18 +11,17 @@ #include "mbed.h" // prepare the data bus for writing commands and pixel data -BusOut dataBus( P1_28,P2_3,P1_18,P1_24,P1_19,P1_26,P1_27,P1_25 ); // 16 pins // create the lcd instance //(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, &dataBus, NC, P1_9 ); // control pins and data bus +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"); +SDFileSystem sd(/*MOSI*/ P0_9, /*MISO*/ P0_8, /*SCK*/ P1_29, /*CS*/ P0_2, /*Mountpoint*/ "sd", NC, SDFileSystem::SWITCH_NONE, 10000000); 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 (1024) +#define SD_READ_BLOCK_SIZE (512) #define BOTTON_PREV_XPOS (15) #define BOTTON_PREV_YPOS (180) @@ -176,11 +176,16 @@ uint32_t totalPlay = 0; int dot1_FileSize = 0; int dot_XPos = 0,old_dot_XPos = 0; + int lcd_FileViewPage = 0,old_lcd_FileViewPage = 0; + int lcd_FileViewListEnd = 0; + //Format,Xsize,Ysize,PixelData const bitmap_t img_button_play = { RGB16, 60, 60, &bmp_button_play }; const bitmap_t img_button_stop = { RGB16, 60, 60, &bmp_button_stop }; const bitmap_t img_button_next = { RGB16, 60, 60, &bmp_button_next }; const bitmap_t img_button_prev = { RGB16, 60, 60, &bmp_button_prev }; + const bitmap_t img_button_pause = { RGB16, 60, 60, &bmp_button_pause }; + // const bitmap_t img_button_volup = { RGB16, 60, 60, &bmp_button_volup }; // const bitmap_t img_button_voldown = { RGB16, 60, 60, &bmp_button_voldown }; @@ -228,6 +233,7 @@ lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_play, 1 ); lcd.DrawBitmap( BOTTON_STOP_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_stop, 1 ); lcd.DrawBitmap( BOTTON_NEXT_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_next, 1 ); + // lcd.DrawBitmap( BOTTON_VOLUP_XPOS, BOTTON_VOLUP_YPOS, (const bitmap_t*)&img_button_volup, 1 ); // lcd.DrawBitmap( BOTTON_VOLDOWN_XPOS, BOTTON_VOLDOWN_YPOS, (const bitmap_t*)&img_button_voldown, 1 ); @@ -235,7 +241,7 @@ /* SDCard GetFileList Section */ //////////////////////////////////////////////////////////// #define SD_MAX_FILENAME_LENGTH (256) //MAX 256 -#define SD_MAX_FILE_COUNT (20) +#define SD_MAX_FILE_COUNT (50) char SDFileList[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0}; char SDFileList_short[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0}; @@ -257,6 +263,7 @@ { sprintf((char *)(SDFileList_short[i]+0),"%s",(const char *)p->d_name); sprintf((char *)(SDFileList[i]+0),"/sd/%s",(const char *)p->d_name); + printf("FileFound:%d,%s\r\n",i,SDFileList[i]); i+=1; } } @@ -274,6 +281,9 @@ #define MP3_STATE_VOLCHANGEREQ (6) #define MP3_STATE_REPLAY (7) #define MP3_STATE_FILECHANGE (8) +#define MP3_STATE_PAUSEREQ (9) +#define MP3_STATE_PAUSEING (10) +#define MP3_STATE_RESUMEREQ (11) printf("file count=%d\r\n",SDFileList_cnt); mp3PlayingFileNo = 0; @@ -305,10 +315,22 @@ if(touchPanel_Touched == 0) { printf("play touch\r\n"); - if( (g_mp3Player_State != MP3_STATE_PLAYING) && (g_mp3Player_State != MP3_STATE_PLAYREQ) ) + 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; } break; @@ -380,9 +402,10 @@ lcd.DrawRect(135,155,310,165,COLOR_WHITE); lcd.FillRect(136,156,309,164,COLOR_BLUE); - dot1_FileSize = mp3_fileSize/175; + 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); @@ -407,7 +430,7 @@ 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("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)); } @@ -415,6 +438,20 @@ 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) ) { uint16_t returnCode=0; @@ -423,6 +460,7 @@ { 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) { @@ -437,7 +475,6 @@ wait(1); stopFailCnt = 0; returnCode = 0; - g_mp3Player_State = MP3_STATE_STOPPING; } }while(returnCode != 0); @@ -489,13 +526,49 @@ if( g_mp3Player_State == MP3_STATE_FILECHANGE ) { printf("next:%d,%s\r\n",mp3PlayingFileNo,SDFileList[mp3PlayingFileNo]); - - for(i=0;i<SDFileList_cnt;i++) + + 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) { - sprintf(str,"%d:%s",i,SDFileList_short[i]); - lcd.Print( str, LEFT, i*28 ); // align text to center horizontally and use starndard colors + 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 + } } - lcd.Print( "*", LEFT, 28*mp3PlayingFileNo ); // 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 + } + } + if(mp3PlayingFileNo >= 10) + { + 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 + } sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]); if(f_mp3Playwe_Playing == 1) @@ -507,12 +580,5 @@ g_mp3Player_State = MP3_STATE_STOPPING; } } - - if( gf_mp3Playwe_VolmeUpdate == 1 ) - { - mp3.VolControl(g_mp3Player_Volume); - gf_mp3Playwe_VolmeUpdate = 0; - printf("Vol:%d\r\n",g_mp3Player_Volume); - } } }