use VS1033(MP3 decoder) and UL024TF(TFTLCD)
Dependencies: FastIO SDFileSystem TFTLCDwithFastIO TouchPanel VS1033 mbed
Fork of 11U68_MP3Player with TFTLCD by
main.cpp@4:28900cff8f48, 2015-07-16 (annotated)
- Committer:
- nameless129
- Date:
- Thu Jul 16 12:43:08 2015 +0000
- Revision:
- 4:28900cff8f48
- Parent:
- 3:67e97c846cec
- Child:
- 5:a493361aead2
???????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nameless129 | 0:5f0e931ae677 | 1 | #include "ili9328.h" |
nameless129 | 2:0090839c8276 | 2 | #include <stdio.h> |
nameless129 | 2:0090839c8276 | 3 | #include "SDFileSystem.h" |
nameless129 | 2:0090839c8276 | 4 | #include "VS1053.h" |
nameless129 | 3:67e97c846cec | 5 | #include "image.h" |
nameless129 | 3:67e97c846cec | 6 | #include "TouchPanel.h" |
nameless129 | 3:67e97c846cec | 7 | #include "mbed.h" |
nameless129 | 2:0090839c8276 | 8 | |
nameless129 | 0:5f0e931ae677 | 9 | // prepare the data bus for writing commands and pixel data |
nameless129 | 0:5f0e931ae677 | 10 | BusOut dataBus( P1_28,P2_3,P1_18,P1_24,P1_19,P1_26,P1_27,P1_25 ); // 16 pins |
nameless129 | 0:5f0e931ae677 | 11 | // create the lcd instance |
nameless129 | 0:5f0e931ae677 | 12 | //(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) |
nameless129 | 0:5f0e931ae677 | 13 | ILI9328_LCD lcd( P0_12, P0_11, P0_13, P0_14, &dataBus, NC, P1_9 ); // control pins and data bus |
nameless129 | 2:0090839c8276 | 14 | |
nameless129 | 2:0090839c8276 | 15 | SDFileSystem sd(/*MOSI*/ P0_9, /*MISO*/ P0_8, /*SCK*/ P1_29, /*CS*/ P0_2, /*Mountpoint*/ "sd"); |
nameless129 | 2:0090839c8276 | 16 | VS1053 mp3(/*MOSI*/ P1_22 , /*MISO*/ P1_21, /*SCK*/ P1_20, /*CS*/ P1_23, |
nameless129 | 3:67e97c846cec | 17 | /*BSYNC*/ P2_17, /*DREQ*/ P2_16, /*RST*/ P2_18, /*SPI freq.*/ 10000000); |
nameless129 | 3:67e97c846cec | 18 | |
nameless129 | 3:67e97c846cec | 19 | Serial pc(P0_19,P0_18); |
nameless129 | 3:67e97c846cec | 20 | #define SD_READ_BLOCK_SIZE (1024) |
nameless129 | 2:0090839c8276 | 21 | |
nameless129 | 2:0090839c8276 | 22 | |
nameless129 | 3:67e97c846cec | 23 | #define BOTTON_PREV_XPOS (15) |
nameless129 | 3:67e97c846cec | 24 | #define BOTTON_PREV_YPOS (170) |
nameless129 | 3:67e97c846cec | 25 | #define BOTTON_PLAY_XPOS (91) |
nameless129 | 3:67e97c846cec | 26 | #define BOTTON_PLAY_YPOS (170) |
nameless129 | 3:67e97c846cec | 27 | #define BOTTON_STOP_XPOS (168) |
nameless129 | 3:67e97c846cec | 28 | #define BOTTON_STOP_YPOS (170) |
nameless129 | 3:67e97c846cec | 29 | #define BOTTON_NEXT_XPOS (245) |
nameless129 | 3:67e97c846cec | 30 | #define BOTTON_NEXT_YPOS (170) |
nameless129 | 3:67e97c846cec | 31 | #define BOTTON_VOLUP_XPOS (245) |
nameless129 | 3:67e97c846cec | 32 | #define BOTTON_VOLUP_YPOS (10) |
nameless129 | 3:67e97c846cec | 33 | #define BOTTON_VOLDOWN_XPOS (245) |
nameless129 | 3:67e97c846cec | 34 | #define BOTTON_VOLDOWN_YPOS (80) |
nameless129 | 3:67e97c846cec | 35 | |
nameless129 | 3:67e97c846cec | 36 | bool checkTouchBotton_prev(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 37 | { |
nameless129 | 3:67e97c846cec | 38 | bool result = 0; |
nameless129 | 3:67e97c846cec | 39 | if( (xpos >= BOTTON_PREV_XPOS && xpos <= (BOTTON_PREV_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 40 | (ypos >= BOTTON_PREV_YPOS && ypos <= (BOTTON_PREV_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 41 | { |
nameless129 | 3:67e97c846cec | 42 | result = 1; |
nameless129 | 3:67e97c846cec | 43 | } |
nameless129 | 3:67e97c846cec | 44 | return result; |
nameless129 | 3:67e97c846cec | 45 | } |
nameless129 | 3:67e97c846cec | 46 | |
nameless129 | 3:67e97c846cec | 47 | bool checkTouchBotton_play(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 48 | { |
nameless129 | 3:67e97c846cec | 49 | bool result = 0; |
nameless129 | 3:67e97c846cec | 50 | if( (xpos >= BOTTON_PLAY_XPOS && xpos <= (BOTTON_PLAY_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 51 | (ypos >= BOTTON_PLAY_YPOS && ypos <= (BOTTON_PLAY_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 52 | { |
nameless129 | 3:67e97c846cec | 53 | result = 1; |
nameless129 | 3:67e97c846cec | 54 | } |
nameless129 | 3:67e97c846cec | 55 | return result; |
nameless129 | 3:67e97c846cec | 56 | } |
nameless129 | 3:67e97c846cec | 57 | |
nameless129 | 3:67e97c846cec | 58 | bool checkTouchBotton_stop(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 59 | { |
nameless129 | 3:67e97c846cec | 60 | bool result = 0; |
nameless129 | 3:67e97c846cec | 61 | if( (xpos >= BOTTON_STOP_XPOS && xpos <= (BOTTON_STOP_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 62 | (ypos >= BOTTON_STOP_XPOS && ypos <= (BOTTON_STOP_XPOS+60)) ) |
nameless129 | 3:67e97c846cec | 63 | { |
nameless129 | 3:67e97c846cec | 64 | result = 1; |
nameless129 | 3:67e97c846cec | 65 | } |
nameless129 | 3:67e97c846cec | 66 | return result; |
nameless129 | 3:67e97c846cec | 67 | } |
nameless129 | 3:67e97c846cec | 68 | |
nameless129 | 3:67e97c846cec | 69 | bool checkTouchBotton_next(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 70 | { |
nameless129 | 3:67e97c846cec | 71 | bool result = 0; |
nameless129 | 3:67e97c846cec | 72 | if( (xpos >= BOTTON_NEXT_XPOS && xpos <= (BOTTON_NEXT_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 73 | (ypos >= BOTTON_NEXT_YPOS && ypos <= (BOTTON_NEXT_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 74 | { |
nameless129 | 3:67e97c846cec | 75 | result = 1; |
nameless129 | 3:67e97c846cec | 76 | } |
nameless129 | 3:67e97c846cec | 77 | return result; |
nameless129 | 3:67e97c846cec | 78 | } |
nameless129 | 3:67e97c846cec | 79 | |
nameless129 | 3:67e97c846cec | 80 | bool checkTouchBotton_volup(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 81 | { |
nameless129 | 3:67e97c846cec | 82 | bool result = 0; |
nameless129 | 3:67e97c846cec | 83 | if( (xpos >= BOTTON_VOLUP_XPOS && xpos <= (BOTTON_VOLUP_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 84 | (ypos >= BOTTON_VOLUP_YPOS && ypos <= (BOTTON_VOLUP_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 85 | { |
nameless129 | 3:67e97c846cec | 86 | result = 1; |
nameless129 | 3:67e97c846cec | 87 | } |
nameless129 | 3:67e97c846cec | 88 | return result; |
nameless129 | 3:67e97c846cec | 89 | } |
nameless129 | 3:67e97c846cec | 90 | |
nameless129 | 3:67e97c846cec | 91 | bool checkTouchBotton_voldown(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 92 | { |
nameless129 | 3:67e97c846cec | 93 | bool result = 0; |
nameless129 | 3:67e97c846cec | 94 | if( (xpos >= BOTTON_VOLDOWN_XPOS && xpos <= (BOTTON_VOLDOWN_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 95 | (ypos >= BOTTON_VOLDOWN_YPOS && ypos <= (BOTTON_VOLDOWN_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 96 | { |
nameless129 | 3:67e97c846cec | 97 | result = 1; |
nameless129 | 3:67e97c846cec | 98 | } |
nameless129 | 3:67e97c846cec | 99 | return result; |
nameless129 | 3:67e97c846cec | 100 | } |
nameless129 | 3:67e97c846cec | 101 | |
nameless129 | 2:0090839c8276 | 102 | |
nameless129 | 0:5f0e931ae677 | 103 | int main() |
nameless129 | 0:5f0e931ae677 | 104 | { |
nameless129 | 2:0090839c8276 | 105 | static FILE *fp = NULL; |
nameless129 | 3:67e97c846cec | 106 | uint8_t SDFileOpenFailCnt = 0; |
nameless129 | 3:67e97c846cec | 107 | size_t mp3_ReadFileSize = 0; |
nameless129 | 3:67e97c846cec | 108 | size_t mp3_totalSizeSent=0; |
nameless129 | 3:67e97c846cec | 109 | size_t mp3_fileSize=0; |
nameless129 | 3:67e97c846cec | 110 | uint8_t mp3Player_State = 0; |
nameless129 | 3:67e97c846cec | 111 | uint16_t mp3Player_Volume = 0; |
nameless129 | 3:67e97c846cec | 112 | bool f_mp3Playwe_VolmeUpdate = 0; |
nameless129 | 3:67e97c846cec | 113 | bool f_mp3Playwe_Playing = 0; |
nameless129 | 2:0090839c8276 | 114 | uint8_t buf[SD_READ_BLOCK_SIZE]; |
nameless129 | 3:67e97c846cec | 115 | char str[100]; |
nameless129 | 3:67e97c846cec | 116 | int32_t XReadPos = 0,YReadPos = 0; |
nameless129 | 3:67e97c846cec | 117 | bool touchPanel_Touched = 0; |
nameless129 | 3:67e97c846cec | 118 | //Format,Xsize,Ysize,PixelData |
nameless129 | 3:67e97c846cec | 119 | const bitmap_t img_button_play = { RGB16, 60, 60, &bmp_button_play }; |
nameless129 | 3:67e97c846cec | 120 | const bitmap_t img_button_stop = { RGB16, 60, 60, &bmp_button_stop }; |
nameless129 | 3:67e97c846cec | 121 | const bitmap_t img_button_next = { RGB16, 60, 60, &bmp_button_next }; |
nameless129 | 3:67e97c846cec | 122 | const bitmap_t img_button_prev = { RGB16, 60, 60, &bmp_button_prev }; |
nameless129 | 3:67e97c846cec | 123 | const bitmap_t img_button_volup = { RGB16, 60, 60, &bmp_button_volup }; |
nameless129 | 3:67e97c846cec | 124 | const bitmap_t img_button_voldown = { RGB16, 60, 60, &bmp_button_voldown }; |
nameless129 | 2:0090839c8276 | 125 | |
nameless129 | 3:67e97c846cec | 126 | pc.baud(115200); |
nameless129 | 2:0090839c8276 | 127 | printf("Power ON\r\n"); |
nameless129 | 2:0090839c8276 | 128 | |
nameless129 | 3:67e97c846cec | 129 | //SD Init.(本来ならいらないけど、SDカードによっちゃもう1回リセットしないとダメポ |
nameless129 | 3:67e97c846cec | 130 | sd.disk_initialize(); |
nameless129 | 3:67e97c846cec | 131 | |
nameless129 | 2:0090839c8276 | 132 | //LCD Init. |
nameless129 | 0:5f0e931ae677 | 133 | lcd.Initialize(LANDSCAPE,RGB16); |
nameless129 | 2:0090839c8276 | 134 | |
nameless129 | 2:0090839c8276 | 135 | /* for sine test mode */ |
nameless129 | 2:0090839c8276 | 136 | // mp3.sine_test_activate(SineWave_10k); |
nameless129 | 2:0090839c8276 | 137 | // while(1); |
nameless129 | 3:67e97c846cec | 138 | |
nameless129 | 2:0090839c8276 | 139 | //MP3 decoder Init. |
nameless129 | 2:0090839c8276 | 140 | mp3.hardwareReset(); |
nameless129 | 2:0090839c8276 | 141 | mp3.sci_init(); |
nameless129 | 2:0090839c8276 | 142 | mp3.sdi_init(); |
nameless129 | 2:0090839c8276 | 143 | wait(0.1); |
nameless129 | 2:0090839c8276 | 144 | |
nameless129 | 2:0090839c8276 | 145 | printf("init CMPL.\r\n"); |
nameless129 | 2:0090839c8276 | 146 | |
nameless129 | 0:5f0e931ae677 | 147 | lcd.SetBackground(COLOR_BLUE); |
nameless129 | 0:5f0e931ae677 | 148 | lcd.FillScreen(-1); |
nameless129 | 0:5f0e931ae677 | 149 | lcd.SetFont( &TerminusFont ); |
nameless129 | 2:0090839c8276 | 150 | |
nameless129 | 3:67e97c846cec | 151 | /* for Caliblation |
nameless129 | 3:67e97c846cec | 152 | lcd.DrawCircle(40,40,10,COLOR_WHITE); |
nameless129 | 3:67e97c846cec | 153 | lcd.DrawCircle(280,200,10,COLOR_WHITE); |
nameless129 | 3:67e97c846cec | 154 | */ |
nameless129 | 3:67e97c846cec | 155 | //Xpos, Ypos, ImageData(type:bitmap_t), Scale |
nameless129 | 3:67e97c846cec | 156 | lcd.DrawBitmap( BOTTON_PREV_XPOS, BOTTON_PREV_YPOS, (const bitmap_t*)&img_button_prev, 1 ); |
nameless129 | 3:67e97c846cec | 157 | lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_play, 1 ); |
nameless129 | 3:67e97c846cec | 158 | lcd.DrawBitmap( BOTTON_STOP_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_stop, 1 ); |
nameless129 | 3:67e97c846cec | 159 | lcd.DrawBitmap( BOTTON_NEXT_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_next, 1 ); |
nameless129 | 3:67e97c846cec | 160 | lcd.DrawBitmap( BOTTON_VOLUP_XPOS, BOTTON_VOLUP_YPOS, (const bitmap_t*)&img_button_volup, 1 ); |
nameless129 | 3:67e97c846cec | 161 | lcd.DrawBitmap( BOTTON_VOLDOWN_XPOS, BOTTON_VOLDOWN_YPOS, (const bitmap_t*)&img_button_voldown, 1 ); |
nameless129 | 2:0090839c8276 | 162 | |
nameless129 | 3:67e97c846cec | 163 | //mp3Player_Stateに対して↓ |
nameless129 | 3:67e97c846cec | 164 | #define MP3_STATE_STOPPING (0) |
nameless129 | 3:67e97c846cec | 165 | #define MP3_STATE_STOPREQ (1) |
nameless129 | 3:67e97c846cec | 166 | #define MP3_STATE_PLAYREQ (2) |
nameless129 | 3:67e97c846cec | 167 | #define MP3_STATE_PLAYING (3) |
nameless129 | 3:67e97c846cec | 168 | #define MP3_STATE_NEXTREQ (4) |
nameless129 | 3:67e97c846cec | 169 | #define MP3_STATE_PREVREQ (5) |
nameless129 | 3:67e97c846cec | 170 | #define MP3_STATE_VOLCHANGEREQ (6) |
nameless129 | 2:0090839c8276 | 171 | |
nameless129 | 2:0090839c8276 | 172 | while(1) |
nameless129 | 0:5f0e931ae677 | 173 | { |
nameless129 | 3:67e97c846cec | 174 | ////////////////////////////////////////////////////////////// |
nameless129 | 3:67e97c846cec | 175 | /* TouchPanel GetStatas Section */ |
nameless129 | 3:67e97c846cec | 176 | ////////////////////////////////////////////////////////////// |
nameless129 | 3:67e97c846cec | 177 | |
nameless129 | 3:67e97c846cec | 178 | XReadPos = getTouchPanelPosX(); |
nameless129 | 3:67e97c846cec | 179 | YReadPos = getTouchPanelPosY(); |
nameless129 | 3:67e97c846cec | 180 | |
nameless129 | 3:67e97c846cec | 181 | if( checkTouchBotton_prev(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 182 | { |
nameless129 | 3:67e97c846cec | 183 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 184 | { |
nameless129 | 3:67e97c846cec | 185 | mp3Player_State = MP3_STATE_PREVREQ; |
nameless129 | 3:67e97c846cec | 186 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 187 | } |
nameless129 | 3:67e97c846cec | 188 | } |
nameless129 | 3:67e97c846cec | 189 | else if( checkTouchBotton_play(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 190 | { |
nameless129 | 3:67e97c846cec | 191 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 192 | { |
nameless129 | 3:67e97c846cec | 193 | if( (mp3Player_State != MP3_STATE_PLAYING) && (mp3Player_State != MP3_STATE_PLAYREQ) ) |
nameless129 | 3:67e97c846cec | 194 | { |
nameless129 | 3:67e97c846cec | 195 | mp3Player_State = MP3_STATE_PLAYREQ; |
nameless129 | 3:67e97c846cec | 196 | } |
nameless129 | 3:67e97c846cec | 197 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 198 | } |
nameless129 | 3:67e97c846cec | 199 | } |
nameless129 | 3:67e97c846cec | 200 | else if( checkTouchBotton_stop(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 201 | { |
nameless129 | 3:67e97c846cec | 202 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 203 | { |
nameless129 | 3:67e97c846cec | 204 | if( (mp3Player_State != MP3_STATE_STOPPING) && (mp3Player_State != MP3_STATE_STOPREQ) ) |
nameless129 | 3:67e97c846cec | 205 | { |
nameless129 | 3:67e97c846cec | 206 | mp3Player_State = MP3_STATE_STOPREQ; |
nameless129 | 3:67e97c846cec | 207 | } |
nameless129 | 3:67e97c846cec | 208 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 209 | } |
nameless129 | 3:67e97c846cec | 210 | } |
nameless129 | 3:67e97c846cec | 211 | else if( checkTouchBotton_next(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 212 | { |
nameless129 | 3:67e97c846cec | 213 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 214 | { |
nameless129 | 3:67e97c846cec | 215 | mp3Player_State = MP3_STATE_NEXTREQ; |
nameless129 | 3:67e97c846cec | 216 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 217 | } |
nameless129 | 3:67e97c846cec | 218 | } |
nameless129 | 3:67e97c846cec | 219 | else if( checkTouchBotton_volup(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 220 | { |
nameless129 | 3:67e97c846cec | 221 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 222 | { |
nameless129 | 3:67e97c846cec | 223 | if(mp3Player_Volume >= 6527) |
nameless129 | 3:67e97c846cec | 224 | { |
nameless129 | 3:67e97c846cec | 225 | mp3Player_Volume-=6527; |
nameless129 | 3:67e97c846cec | 226 | f_mp3Playwe_VolmeUpdate = 1; |
nameless129 | 3:67e97c846cec | 227 | } |
nameless129 | 3:67e97c846cec | 228 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 229 | } |
nameless129 | 3:67e97c846cec | 230 | |
nameless129 | 3:67e97c846cec | 231 | } |
nameless129 | 3:67e97c846cec | 232 | else if( checkTouchBotton_voldown(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 233 | { |
nameless129 | 3:67e97c846cec | 234 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 235 | { |
nameless129 | 3:67e97c846cec | 236 | if(mp3Player_Volume <= 0xE57F ) |
nameless129 | 3:67e97c846cec | 237 | { |
nameless129 | 3:67e97c846cec | 238 | mp3Player_Volume+=6527; |
nameless129 | 3:67e97c846cec | 239 | f_mp3Playwe_VolmeUpdate = 1; |
nameless129 | 3:67e97c846cec | 240 | } |
nameless129 | 3:67e97c846cec | 241 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 242 | } |
nameless129 | 3:67e97c846cec | 243 | printf("VolDownTouched\r\n"); |
nameless129 | 3:67e97c846cec | 244 | } |
nameless129 | 3:67e97c846cec | 245 | else //any botton not touched |
nameless129 | 3:67e97c846cec | 246 | { |
nameless129 | 3:67e97c846cec | 247 | touchPanel_Touched = 0; |
nameless129 | 3:67e97c846cec | 248 | } |
nameless129 | 3:67e97c846cec | 249 | ////////////////////////////////////////////////////////////// |
nameless129 | 3:67e97c846cec | 250 | /* MP3 Player Control Section */ |
nameless129 | 3:67e97c846cec | 251 | ////////////////////////////////////////////////////////////// |
nameless129 | 3:67e97c846cec | 252 | if(mp3Player_State == MP3_STATE_PLAYREQ) |
nameless129 | 3:67e97c846cec | 253 | { |
nameless129 | 3:67e97c846cec | 254 | fp = fopen("/sd/1.mp3", "rb"); |
nameless129 | 3:67e97c846cec | 255 | SDFileOpenFailCnt = 0; |
nameless129 | 3:67e97c846cec | 256 | while(!fp) |
nameless129 | 3:67e97c846cec | 257 | { |
nameless129 | 3:67e97c846cec | 258 | SDFileOpenFailCnt+=1; |
nameless129 | 3:67e97c846cec | 259 | if(SDFileOpenFailCnt >= 3) |
nameless129 | 3:67e97c846cec | 260 | { |
nameless129 | 3:67e97c846cec | 261 | printf("Fail SD init\r\n"); |
nameless129 | 3:67e97c846cec | 262 | printf("System Stop.\r\n"); |
nameless129 | 3:67e97c846cec | 263 | while(1); |
nameless129 | 3:67e97c846cec | 264 | } |
nameless129 | 3:67e97c846cec | 265 | printf("Fail file open n=%d\r\n",SDFileOpenFailCnt); |
nameless129 | 3:67e97c846cec | 266 | sd.disk_initialize(); |
nameless129 | 3:67e97c846cec | 267 | fp = fopen("/sd/1.mp3", "rb"); |
nameless129 | 3:67e97c846cec | 268 | wait(1); |
nameless129 | 3:67e97c846cec | 269 | } |
nameless129 | 3:67e97c846cec | 270 | |
nameless129 | 3:67e97c846cec | 271 | //Get file size |
nameless129 | 3:67e97c846cec | 272 | fseek( fp, 0, SEEK_END ); |
nameless129 | 3:67e97c846cec | 273 | mp3_fileSize = ftell( fp ); |
nameless129 | 3:67e97c846cec | 274 | printf("FileOpen. size=%dbit\r\n",mp3_fileSize); |
nameless129 | 3:67e97c846cec | 275 | |
nameless129 | 3:67e97c846cec | 276 | //move file pointer to top. |
nameless129 | 3:67e97c846cec | 277 | rewind(fp); |
nameless129 | 3:67e97c846cec | 278 | clearerr(fp); |
nameless129 | 3:67e97c846cec | 279 | mp3_totalSizeSent = 0; |
nameless129 | 3:67e97c846cec | 280 | mp3Player_State = MP3_STATE_PLAYING; |
nameless129 | 3:67e97c846cec | 281 | } |
nameless129 | 3:67e97c846cec | 282 | if( mp3Player_State == MP3_STATE_PLAYING ) |
nameless129 | 3:67e97c846cec | 283 | { |
nameless129 | 3:67e97c846cec | 284 | printf("totalSendSize:%d\r\n",mp3_totalSizeSent); |
nameless129 | 3:67e97c846cec | 285 | |
nameless129 | 3:67e97c846cec | 286 | if(mp3_totalSizeSent>=mp3_fileSize) //play song end |
nameless129 | 3:67e97c846cec | 287 | { |
nameless129 | 3:67e97c846cec | 288 | mp3Player_State = MP3_STATE_STOPREQ; |
nameless129 | 3:67e97c846cec | 289 | } |
nameless129 | 3:67e97c846cec | 290 | else //transmit from SDCard to VS1033 |
nameless129 | 3:67e97c846cec | 291 | { |
nameless129 | 3:67e97c846cec | 292 | mp3_ReadFileSize = fread(buf, sizeof(uint8_t), SD_READ_BLOCK_SIZE, fp); |
nameless129 | 3:67e97c846cec | 293 | mp3_totalSizeSent += mp3.sendDataBlock(buf, mp3_ReadFileSize); |
nameless129 | 3:67e97c846cec | 294 | f_mp3Playwe_Playing = 1; |
nameless129 | 3:67e97c846cec | 295 | } |
nameless129 | 3:67e97c846cec | 296 | } |
nameless129 | 3:67e97c846cec | 297 | if( mp3Player_State == MP3_STATE_STOPREQ ) |
nameless129 | 3:67e97c846cec | 298 | { |
nameless129 | 4:28900cff8f48 | 299 | uint16_t returnCode=0; |
nameless129 | 4:28900cff8f48 | 300 | uint16_t stopFailCnt = 0; |
nameless129 | 4:28900cff8f48 | 301 | do |
nameless129 | 4:28900cff8f48 | 302 | { |
nameless129 | 4:28900cff8f48 | 303 | returnCode = mp3.stop(); |
nameless129 | 4:28900cff8f48 | 304 | printf("STOP\r\nSTOP CODE:%d\r\n",returnCode); |
nameless129 | 4:28900cff8f48 | 305 | |
nameless129 | 4:28900cff8f48 | 306 | if(returnCode != 0) |
nameless129 | 4:28900cff8f48 | 307 | { |
nameless129 | 4:28900cff8f48 | 308 | stopFailCnt++; |
nameless129 | 4:28900cff8f48 | 309 | } |
nameless129 | 4:28900cff8f48 | 310 | if(stopFailCnt >= 10) |
nameless129 | 4:28900cff8f48 | 311 | { |
nameless129 | 4:28900cff8f48 | 312 | printf("ERROR! impossible of stop\r\nSystem STOP\r\n"); |
nameless129 | 4:28900cff8f48 | 313 | while(1); |
nameless129 | 4:28900cff8f48 | 314 | } |
nameless129 | 4:28900cff8f48 | 315 | }while(returnCode != 0); |
nameless129 | 2:0090839c8276 | 316 | fclose(fp); |
nameless129 | 2:0090839c8276 | 317 | fp = NULL; |
nameless129 | 3:67e97c846cec | 318 | f_mp3Playwe_Playing = 0; |
nameless129 | 3:67e97c846cec | 319 | mp3Player_State = MP3_STATE_STOPPING; |
nameless129 | 2:0090839c8276 | 320 | } |
nameless129 | 3:67e97c846cec | 321 | if( mp3Player_State == MP3_STATE_STOPPING ) |
nameless129 | 2:0090839c8276 | 322 | { |
nameless129 | 3:67e97c846cec | 323 | } |
nameless129 | 3:67e97c846cec | 324 | |
nameless129 | 3:67e97c846cec | 325 | if( mp3Player_State == MP3_STATE_VOLCHANGEREQ ) |
nameless129 | 3:67e97c846cec | 326 | { |
nameless129 | 2:0090839c8276 | 327 | } |
nameless129 | 2:0090839c8276 | 328 | } |
nameless129 | 0:5f0e931ae677 | 329 | } |