use VS1033(MP3 decoder) and UL024TF(TFTLCD)
Dependencies: FastIO SDFileSystem TFTLCDwithFastIO TouchPanel VS1033 mbed
Fork of 11U68_MP3Player with TFTLCD by
Diff: main.cpp
- Revision:
- 7:fc65d965a569
- Parent:
- 6:74271fce2368
- Child:
- 8:198b69e78c39
--- a/main.cpp Fri Jul 17 21:35:57 2015 +0000 +++ b/main.cpp Fri Jul 24 11:06:18 2015 +0000 @@ -1,3 +1,5 @@ +#pragma O3 + #include "ili9328.h" #include "stdio.h" #include "string.h" @@ -15,20 +17,20 @@ SDFileSystem sd(/*MOSI*/ P0_9, /*MISO*/ P0_8, /*SCK*/ P1_29, /*CS*/ P0_2, /*Mountpoint*/ "sd"); 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.*/ 10000000); + /*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 BOTTON_PREV_XPOS (15) -#define BOTTON_PREV_YPOS (170) +#define BOTTON_PREV_YPOS (180) #define BOTTON_PLAY_XPOS (91) -#define BOTTON_PLAY_YPOS (170) +#define BOTTON_PLAY_YPOS (180) #define BOTTON_STOP_XPOS (168) -#define BOTTON_STOP_YPOS (170) +#define BOTTON_STOP_YPOS (180) #define BOTTON_NEXT_XPOS (245) -#define BOTTON_NEXT_YPOS (170) +#define BOTTON_NEXT_YPOS (180) #define BOTTON_VOLUP_XPOS (245) #define BOTTON_VOLUP_YPOS (10) #define BOTTON_VOLDOWN_XPOS (245) @@ -171,6 +173,9 @@ char str[100]; int32_t XReadPos = 0,YReadPos = 0; bool touchPanel_Touched = 0; + uint32_t totalPlay = 0; + int dot1_FileSize = 0; + int dot_XPos = 0,old_dot_XPos = 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 }; @@ -366,17 +371,25 @@ 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); + clearerr(fp); mp3_totalSizeSent = 0; - lcd.DrawRect(15,150,305,160); //Playing Bar + 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; + + totalPlay++; + printf("PlayCount=%d\r\n",totalPlay); } if( g_mp3Player_State == MP3_STATE_PLAYING ) { -// printf("totalSendSize:%d\r\n",mp3_totalSizeSent); + if(mp3_totalSizeSent>=mp3_fileSize) //play song end { f_mp3Playwe_Playing = 1; @@ -384,9 +397,20 @@ } else //transmit from SDCard to VS1033 { - mp3_ReadFileSize = fread(buf, sizeof(uint8_t), SD_READ_BLOCK_SIZE, fp); - mp3_totalSizeSent += mp3.sendDataBlock(buf, mp3_ReadFileSize); - lcd.FillRect(15,150,15+290*mp3_totalSizeSent/mp3_fileSize,160,-2); + 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; } @@ -410,12 +434,18 @@ mp3.hardwareReset(); mp3.sci_init(); mp3.sdi_init(); + wait(1); stopFailCnt = 0; + returnCode = 0; + g_mp3Player_State = MP3_STATE_STOPPING; } }while(returnCode != 0); + fclose(fp); fp = NULL; f_mp3Playwe_Playing = 0; + lcd.Print("STOP ",15,145); + if(g_mp3Player_State == MP3_STATE_STOPREQ) { g_mp3Player_State = MP3_STATE_STOPPING;