use VS1033(MP3 decoder) and UL024TF(TFTLCD)
Dependencies: FastIO SDFileSystem TFTLCDwithFastIO TouchPanel VS1033 mbed
Fork of 11U68_MP3Player with TFTLCD by
main.cpp@5:a493361aead2, 2015-07-16 (annotated)
- Committer:
- nameless129
- Date:
- Thu Jul 16 18:18:00 2015 +0000
- Revision:
- 5:a493361aead2
- Parent:
- 4:28900cff8f48
- Child:
- 6:74271fce2368
add vol control
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nameless129 | 0:5f0e931ae677 | 1 | #include "ili9328.h" |
nameless129 | 5:a493361aead2 | 2 | #include "stdio.h" |
nameless129 | 5:a493361aead2 | 3 | #include "string.h" |
nameless129 | 2:0090839c8276 | 4 | #include "SDFileSystem.h" |
nameless129 | 2:0090839c8276 | 5 | #include "VS1053.h" |
nameless129 | 3:67e97c846cec | 6 | #include "image.h" |
nameless129 | 3:67e97c846cec | 7 | #include "TouchPanel.h" |
nameless129 | 3:67e97c846cec | 8 | #include "mbed.h" |
nameless129 | 2:0090839c8276 | 9 | |
nameless129 | 0:5f0e931ae677 | 10 | // prepare the data bus for writing commands and pixel data |
nameless129 | 0:5f0e931ae677 | 11 | BusOut dataBus( P1_28,P2_3,P1_18,P1_24,P1_19,P1_26,P1_27,P1_25 ); // 16 pins |
nameless129 | 0:5f0e931ae677 | 12 | // create the lcd instance |
nameless129 | 0:5f0e931ae677 | 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) |
nameless129 | 0:5f0e931ae677 | 14 | ILI9328_LCD lcd( P0_12, P0_11, P0_13, P0_14, &dataBus, NC, P1_9 ); // control pins and data bus |
nameless129 | 2:0090839c8276 | 15 | |
nameless129 | 2:0090839c8276 | 16 | SDFileSystem sd(/*MOSI*/ P0_9, /*MISO*/ P0_8, /*SCK*/ P1_29, /*CS*/ P0_2, /*Mountpoint*/ "sd"); |
nameless129 | 2:0090839c8276 | 17 | VS1053 mp3(/*MOSI*/ P1_22 , /*MISO*/ P1_21, /*SCK*/ P1_20, /*CS*/ P1_23, |
nameless129 | 3:67e97c846cec | 18 | /*BSYNC*/ P2_17, /*DREQ*/ P2_16, /*RST*/ P2_18, /*SPI freq.*/ 10000000); |
nameless129 | 5:a493361aead2 | 19 | Ticker Int100ms; |
nameless129 | 3:67e97c846cec | 20 | |
nameless129 | 3:67e97c846cec | 21 | Serial pc(P0_19,P0_18); |
nameless129 | 3:67e97c846cec | 22 | #define SD_READ_BLOCK_SIZE (1024) |
nameless129 | 2:0090839c8276 | 23 | |
nameless129 | 3:67e97c846cec | 24 | #define BOTTON_PREV_XPOS (15) |
nameless129 | 3:67e97c846cec | 25 | #define BOTTON_PREV_YPOS (170) |
nameless129 | 3:67e97c846cec | 26 | #define BOTTON_PLAY_XPOS (91) |
nameless129 | 3:67e97c846cec | 27 | #define BOTTON_PLAY_YPOS (170) |
nameless129 | 3:67e97c846cec | 28 | #define BOTTON_STOP_XPOS (168) |
nameless129 | 3:67e97c846cec | 29 | #define BOTTON_STOP_YPOS (170) |
nameless129 | 3:67e97c846cec | 30 | #define BOTTON_NEXT_XPOS (245) |
nameless129 | 3:67e97c846cec | 31 | #define BOTTON_NEXT_YPOS (170) |
nameless129 | 3:67e97c846cec | 32 | #define BOTTON_VOLUP_XPOS (245) |
nameless129 | 3:67e97c846cec | 33 | #define BOTTON_VOLUP_YPOS (10) |
nameless129 | 3:67e97c846cec | 34 | #define BOTTON_VOLDOWN_XPOS (245) |
nameless129 | 3:67e97c846cec | 35 | #define BOTTON_VOLDOWN_YPOS (80) |
nameless129 | 3:67e97c846cec | 36 | |
nameless129 | 3:67e97c846cec | 37 | bool checkTouchBotton_prev(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 38 | { |
nameless129 | 3:67e97c846cec | 39 | bool result = 0; |
nameless129 | 3:67e97c846cec | 40 | if( (xpos >= BOTTON_PREV_XPOS && xpos <= (BOTTON_PREV_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 41 | (ypos >= BOTTON_PREV_YPOS && ypos <= (BOTTON_PREV_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 42 | { |
nameless129 | 3:67e97c846cec | 43 | result = 1; |
nameless129 | 3:67e97c846cec | 44 | } |
nameless129 | 3:67e97c846cec | 45 | return result; |
nameless129 | 3:67e97c846cec | 46 | } |
nameless129 | 3:67e97c846cec | 47 | |
nameless129 | 3:67e97c846cec | 48 | bool checkTouchBotton_play(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 49 | { |
nameless129 | 3:67e97c846cec | 50 | bool result = 0; |
nameless129 | 3:67e97c846cec | 51 | if( (xpos >= BOTTON_PLAY_XPOS && xpos <= (BOTTON_PLAY_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 52 | (ypos >= BOTTON_PLAY_YPOS && ypos <= (BOTTON_PLAY_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 53 | { |
nameless129 | 3:67e97c846cec | 54 | result = 1; |
nameless129 | 3:67e97c846cec | 55 | } |
nameless129 | 3:67e97c846cec | 56 | return result; |
nameless129 | 3:67e97c846cec | 57 | } |
nameless129 | 3:67e97c846cec | 58 | |
nameless129 | 3:67e97c846cec | 59 | bool checkTouchBotton_stop(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 60 | { |
nameless129 | 3:67e97c846cec | 61 | bool result = 0; |
nameless129 | 3:67e97c846cec | 62 | if( (xpos >= BOTTON_STOP_XPOS && xpos <= (BOTTON_STOP_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 63 | (ypos >= BOTTON_STOP_XPOS && ypos <= (BOTTON_STOP_XPOS+60)) ) |
nameless129 | 3:67e97c846cec | 64 | { |
nameless129 | 3:67e97c846cec | 65 | result = 1; |
nameless129 | 3:67e97c846cec | 66 | } |
nameless129 | 3:67e97c846cec | 67 | return result; |
nameless129 | 3:67e97c846cec | 68 | } |
nameless129 | 3:67e97c846cec | 69 | |
nameless129 | 3:67e97c846cec | 70 | bool checkTouchBotton_next(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 71 | { |
nameless129 | 3:67e97c846cec | 72 | bool result = 0; |
nameless129 | 3:67e97c846cec | 73 | if( (xpos >= BOTTON_NEXT_XPOS && xpos <= (BOTTON_NEXT_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 74 | (ypos >= BOTTON_NEXT_YPOS && ypos <= (BOTTON_NEXT_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 75 | { |
nameless129 | 3:67e97c846cec | 76 | result = 1; |
nameless129 | 3:67e97c846cec | 77 | } |
nameless129 | 3:67e97c846cec | 78 | return result; |
nameless129 | 3:67e97c846cec | 79 | } |
nameless129 | 3:67e97c846cec | 80 | |
nameless129 | 3:67e97c846cec | 81 | bool checkTouchBotton_volup(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 82 | { |
nameless129 | 3:67e97c846cec | 83 | bool result = 0; |
nameless129 | 3:67e97c846cec | 84 | if( (xpos >= BOTTON_VOLUP_XPOS && xpos <= (BOTTON_VOLUP_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 85 | (ypos >= BOTTON_VOLUP_YPOS && ypos <= (BOTTON_VOLUP_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 86 | { |
nameless129 | 3:67e97c846cec | 87 | result = 1; |
nameless129 | 3:67e97c846cec | 88 | } |
nameless129 | 3:67e97c846cec | 89 | return result; |
nameless129 | 3:67e97c846cec | 90 | } |
nameless129 | 3:67e97c846cec | 91 | |
nameless129 | 3:67e97c846cec | 92 | bool checkTouchBotton_voldown(int32_t xpos,int32_t ypos) |
nameless129 | 3:67e97c846cec | 93 | { |
nameless129 | 3:67e97c846cec | 94 | bool result = 0; |
nameless129 | 3:67e97c846cec | 95 | if( (xpos >= BOTTON_VOLDOWN_XPOS && xpos <= (BOTTON_VOLDOWN_XPOS+60) ) && |
nameless129 | 3:67e97c846cec | 96 | (ypos >= BOTTON_VOLDOWN_YPOS && ypos <= (BOTTON_VOLDOWN_YPOS+60)) ) |
nameless129 | 3:67e97c846cec | 97 | { |
nameless129 | 3:67e97c846cec | 98 | result = 1; |
nameless129 | 3:67e97c846cec | 99 | } |
nameless129 | 3:67e97c846cec | 100 | return result; |
nameless129 | 3:67e97c846cec | 101 | } |
nameless129 | 3:67e97c846cec | 102 | |
nameless129 | 5:a493361aead2 | 103 | uint8_t g_mp3Player_State = 0; |
nameless129 | 5:a493361aead2 | 104 | uint16_t g_mp3Player_Volume = 0; |
nameless129 | 5:a493361aead2 | 105 | bool gf_mp3Playwe_VolmeUpdate = 0; |
nameless129 | 5:a493361aead2 | 106 | bool gf_100ms = 0; |
nameless129 | 5:a493361aead2 | 107 | |
nameless129 | 5:a493361aead2 | 108 | void Int100msFunc() |
nameless129 | 5:a493361aead2 | 109 | { |
nameless129 | 5:a493361aead2 | 110 | gf_100ms = 1; |
nameless129 | 5:a493361aead2 | 111 | } |
nameless129 | 2:0090839c8276 | 112 | |
nameless129 | 0:5f0e931ae677 | 113 | int main() |
nameless129 | 0:5f0e931ae677 | 114 | { |
nameless129 | 2:0090839c8276 | 115 | static FILE *fp = NULL; |
nameless129 | 3:67e97c846cec | 116 | uint8_t SDFileOpenFailCnt = 0; |
nameless129 | 3:67e97c846cec | 117 | size_t mp3_ReadFileSize = 0; |
nameless129 | 3:67e97c846cec | 118 | size_t mp3_totalSizeSent=0; |
nameless129 | 3:67e97c846cec | 119 | size_t mp3_fileSize=0; |
nameless129 | 3:67e97c846cec | 120 | bool f_mp3Playwe_Playing = 0; |
nameless129 | 2:0090839c8276 | 121 | uint8_t buf[SD_READ_BLOCK_SIZE]; |
nameless129 | 3:67e97c846cec | 122 | char str[100]; |
nameless129 | 3:67e97c846cec | 123 | int32_t XReadPos = 0,YReadPos = 0; |
nameless129 | 5:a493361aead2 | 124 | static bool touchPanel_Touched = 0; |
nameless129 | 3:67e97c846cec | 125 | //Format,Xsize,Ysize,PixelData |
nameless129 | 3:67e97c846cec | 126 | const bitmap_t img_button_play = { RGB16, 60, 60, &bmp_button_play }; |
nameless129 | 3:67e97c846cec | 127 | const bitmap_t img_button_stop = { RGB16, 60, 60, &bmp_button_stop }; |
nameless129 | 3:67e97c846cec | 128 | const bitmap_t img_button_next = { RGB16, 60, 60, &bmp_button_next }; |
nameless129 | 3:67e97c846cec | 129 | const bitmap_t img_button_prev = { RGB16, 60, 60, &bmp_button_prev }; |
nameless129 | 3:67e97c846cec | 130 | const bitmap_t img_button_volup = { RGB16, 60, 60, &bmp_button_volup }; |
nameless129 | 3:67e97c846cec | 131 | const bitmap_t img_button_voldown = { RGB16, 60, 60, &bmp_button_voldown }; |
nameless129 | 5:a493361aead2 | 132 | |
nameless129 | 5:a493361aead2 | 133 | pc.baud(921600); |
nameless129 | 5:a493361aead2 | 134 | printf("Power ON\r\n"); |
nameless129 | 2:0090839c8276 | 135 | |
nameless129 | 5:a493361aead2 | 136 | Int100ms.attach_us(&Int100msFunc, 100000); |
nameless129 | 2:0090839c8276 | 137 | |
nameless129 | 3:67e97c846cec | 138 | //SD Init.(本来ならいらないけど、SDカードによっちゃもう1回リセットしないとダメポ |
nameless129 | 3:67e97c846cec | 139 | sd.disk_initialize(); |
nameless129 | 3:67e97c846cec | 140 | |
nameless129 | 2:0090839c8276 | 141 | //LCD Init. |
nameless129 | 0:5f0e931ae677 | 142 | lcd.Initialize(LANDSCAPE,RGB16); |
nameless129 | 2:0090839c8276 | 143 | |
nameless129 | 2:0090839c8276 | 144 | /* for sine test mode */ |
nameless129 | 2:0090839c8276 | 145 | // mp3.sine_test_activate(SineWave_10k); |
nameless129 | 2:0090839c8276 | 146 | // while(1); |
nameless129 | 3:67e97c846cec | 147 | |
nameless129 | 2:0090839c8276 | 148 | //MP3 decoder Init. |
nameless129 | 2:0090839c8276 | 149 | mp3.hardwareReset(); |
nameless129 | 2:0090839c8276 | 150 | mp3.sci_init(); |
nameless129 | 2:0090839c8276 | 151 | mp3.sdi_init(); |
nameless129 | 2:0090839c8276 | 152 | wait(0.1); |
nameless129 | 2:0090839c8276 | 153 | |
nameless129 | 2:0090839c8276 | 154 | printf("init CMPL.\r\n"); |
nameless129 | 2:0090839c8276 | 155 | |
nameless129 | 0:5f0e931ae677 | 156 | lcd.SetBackground(COLOR_BLUE); |
nameless129 | 0:5f0e931ae677 | 157 | lcd.FillScreen(-1); |
nameless129 | 5:a493361aead2 | 158 | lcd.SetFont( &TerminusBigFont ); |
nameless129 | 2:0090839c8276 | 159 | |
nameless129 | 5:a493361aead2 | 160 | //for Caliblation |
nameless129 | 5:a493361aead2 | 161 | while(0) |
nameless129 | 5:a493361aead2 | 162 | { |
nameless129 | 5:a493361aead2 | 163 | int32_t XReadPos = 0,YReadPos = 0; |
nameless129 | 5:a493361aead2 | 164 | lcd.DrawCircle(40,40,10,COLOR_WHITE); |
nameless129 | 5:a493361aead2 | 165 | lcd.DrawCircle(280,200,10,COLOR_WHITE); |
nameless129 | 5:a493361aead2 | 166 | XReadPos = getTouchPanelPosX(); |
nameless129 | 5:a493361aead2 | 167 | YReadPos = getTouchPanelPosY(); |
nameless129 | 5:a493361aead2 | 168 | printf("X:%d Y:%d\r\n",XReadPos,YReadPos); |
nameless129 | 5:a493361aead2 | 169 | wait_ms(500); |
nameless129 | 5:a493361aead2 | 170 | } |
nameless129 | 5:a493361aead2 | 171 | |
nameless129 | 3:67e97c846cec | 172 | //Xpos, Ypos, ImageData(type:bitmap_t), Scale |
nameless129 | 3:67e97c846cec | 173 | lcd.DrawBitmap( BOTTON_PREV_XPOS, BOTTON_PREV_YPOS, (const bitmap_t*)&img_button_prev, 1 ); |
nameless129 | 3:67e97c846cec | 174 | lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_play, 1 ); |
nameless129 | 3:67e97c846cec | 175 | lcd.DrawBitmap( BOTTON_STOP_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_stop, 1 ); |
nameless129 | 3:67e97c846cec | 176 | lcd.DrawBitmap( BOTTON_NEXT_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_next, 1 ); |
nameless129 | 3:67e97c846cec | 177 | lcd.DrawBitmap( BOTTON_VOLUP_XPOS, BOTTON_VOLUP_YPOS, (const bitmap_t*)&img_button_volup, 1 ); |
nameless129 | 3:67e97c846cec | 178 | lcd.DrawBitmap( BOTTON_VOLDOWN_XPOS, BOTTON_VOLDOWN_YPOS, (const bitmap_t*)&img_button_voldown, 1 ); |
nameless129 | 2:0090839c8276 | 179 | |
nameless129 | 5:a493361aead2 | 180 | //////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 181 | /* SDCard GetFileList Section */ |
nameless129 | 5:a493361aead2 | 182 | //////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 183 | #define SD_MAX_FILENAME_LENGTH (256) //MAX 256 |
nameless129 | 5:a493361aead2 | 184 | #define SD_MAX_FILE_COUNT (20) |
nameless129 | 5:a493361aead2 | 185 | |
nameless129 | 5:a493361aead2 | 186 | char SDFileList[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0}; |
nameless129 | 5:a493361aead2 | 187 | char SDFileList_short[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0}; |
nameless129 | 5:a493361aead2 | 188 | char SDFileList_cnt = 0; |
nameless129 | 5:a493361aead2 | 189 | char mp3PlayingFileName[SD_MAX_FILENAME_LENGTH]={0}; |
nameless129 | 5:a493361aead2 | 190 | uint8_t mp3PlayingFileNo = 0; |
nameless129 | 5:a493361aead2 | 191 | int i = 0; |
nameless129 | 5:a493361aead2 | 192 | DIR *d; |
nameless129 | 5:a493361aead2 | 193 | struct dirent *p; |
nameless129 | 5:a493361aead2 | 194 | |
nameless129 | 5:a493361aead2 | 195 | d = opendir("/sd"); |
nameless129 | 5:a493361aead2 | 196 | if ( d != NULL ) |
nameless129 | 5:a493361aead2 | 197 | { |
nameless129 | 5:a493361aead2 | 198 | while ( (p = readdir(d)) != NULL ) |
nameless129 | 5:a493361aead2 | 199 | { |
nameless129 | 5:a493361aead2 | 200 | char *ret; |
nameless129 | 5:a493361aead2 | 201 | ret = strstr(p->d_name,"System"); //System Vol..フォルダは除外 |
nameless129 | 5:a493361aead2 | 202 | if(ret == 0) |
nameless129 | 5:a493361aead2 | 203 | { |
nameless129 | 5:a493361aead2 | 204 | sprintf((char *)(SDFileList_short[i]+0),"%s",(const char *)p->d_name); |
nameless129 | 5:a493361aead2 | 205 | sprintf((char *)(SDFileList[i]+0),"/sd/%s",(const char *)p->d_name); |
nameless129 | 5:a493361aead2 | 206 | i+=1; |
nameless129 | 5:a493361aead2 | 207 | } |
nameless129 | 5:a493361aead2 | 208 | } |
nameless129 | 5:a493361aead2 | 209 | SDFileList_cnt = i; |
nameless129 | 5:a493361aead2 | 210 | } |
nameless129 | 5:a493361aead2 | 211 | closedir(d); |
nameless129 | 5:a493361aead2 | 212 | |
nameless129 | 5:a493361aead2 | 213 | for(i=0;i<SDFileList_cnt;i++) |
nameless129 | 5:a493361aead2 | 214 | { |
nameless129 | 5:a493361aead2 | 215 | sprintf(str,"%d:%s",i,SDFileList_short[i]); |
nameless129 | 5:a493361aead2 | 216 | lcd.Print( str, LEFT, i*28 ); // align text to center horizontally and use starndard colors |
nameless129 | 5:a493361aead2 | 217 | lcd.Print( "*", LEFT, 0 ); // align text to center horizontally and use starndard colors |
nameless129 | 5:a493361aead2 | 218 | } |
nameless129 | 5:a493361aead2 | 219 | |
nameless129 | 5:a493361aead2 | 220 | mp3PlayingFileNo = 0; |
nameless129 | 5:a493361aead2 | 221 | sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]); |
nameless129 | 5:a493361aead2 | 222 | |
nameless129 | 5:a493361aead2 | 223 | printf("file count=%d\r\n",SDFileList_cnt); |
nameless129 | 5:a493361aead2 | 224 | printf("FirstPlayFile:%s\r\n",mp3PlayingFileName); |
nameless129 | 5:a493361aead2 | 225 | g_mp3Player_State = 0; |
nameless129 | 5:a493361aead2 | 226 | f_mp3Playwe_Playing = 0; |
nameless129 | 5:a493361aead2 | 227 | while(1) |
nameless129 | 5:a493361aead2 | 228 | { |
nameless129 | 5:a493361aead2 | 229 | |
nameless129 | 5:a493361aead2 | 230 | ////////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 231 | /* TouchPanel GetStatas Section */ |
nameless129 | 5:a493361aead2 | 232 | ////////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 233 | if(gf_100ms == 1) |
nameless129 | 5:a493361aead2 | 234 | { |
nameless129 | 5:a493361aead2 | 235 | XReadPos = getTouchPanelPosX(); |
nameless129 | 5:a493361aead2 | 236 | YReadPos = getTouchPanelPosY(); |
nameless129 | 5:a493361aead2 | 237 | gf_100ms = 0; |
nameless129 | 5:a493361aead2 | 238 | } |
nameless129 | 5:a493361aead2 | 239 | |
nameless129 | 5:a493361aead2 | 240 | //g_mp3Player_Stateに対して↓ |
nameless129 | 3:67e97c846cec | 241 | #define MP3_STATE_STOPPING (0) |
nameless129 | 3:67e97c846cec | 242 | #define MP3_STATE_STOPREQ (1) |
nameless129 | 3:67e97c846cec | 243 | #define MP3_STATE_PLAYREQ (2) |
nameless129 | 3:67e97c846cec | 244 | #define MP3_STATE_PLAYING (3) |
nameless129 | 3:67e97c846cec | 245 | #define MP3_STATE_NEXTREQ (4) |
nameless129 | 3:67e97c846cec | 246 | #define MP3_STATE_PREVREQ (5) |
nameless129 | 3:67e97c846cec | 247 | #define MP3_STATE_VOLCHANGEREQ (6) |
nameless129 | 5:a493361aead2 | 248 | #define MP3_STATE_REPLAY (7) |
nameless129 | 5:a493361aead2 | 249 | #define MP3_STATE_FILECHANGE (8) |
nameless129 | 3:67e97c846cec | 250 | |
nameless129 | 3:67e97c846cec | 251 | if( checkTouchBotton_prev(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 252 | { |
nameless129 | 3:67e97c846cec | 253 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 254 | { |
nameless129 | 5:a493361aead2 | 255 | printf("prev touch\r\n"); |
nameless129 | 5:a493361aead2 | 256 | g_mp3Player_State = MP3_STATE_PREVREQ; |
nameless129 | 3:67e97c846cec | 257 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 258 | } |
nameless129 | 3:67e97c846cec | 259 | } |
nameless129 | 3:67e97c846cec | 260 | else if( checkTouchBotton_play(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 261 | { |
nameless129 | 3:67e97c846cec | 262 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 263 | { |
nameless129 | 5:a493361aead2 | 264 | printf("play touch\r\n"); |
nameless129 | 5:a493361aead2 | 265 | if( (g_mp3Player_State != MP3_STATE_PLAYING) && (g_mp3Player_State != MP3_STATE_PLAYREQ) ) |
nameless129 | 3:67e97c846cec | 266 | { |
nameless129 | 5:a493361aead2 | 267 | g_mp3Player_State = MP3_STATE_PLAYREQ; |
nameless129 | 3:67e97c846cec | 268 | } |
nameless129 | 3:67e97c846cec | 269 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 270 | } |
nameless129 | 3:67e97c846cec | 271 | } |
nameless129 | 3:67e97c846cec | 272 | else if( checkTouchBotton_stop(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 273 | { |
nameless129 | 3:67e97c846cec | 274 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 275 | { |
nameless129 | 5:a493361aead2 | 276 | printf("stop touch\r\n"); |
nameless129 | 5:a493361aead2 | 277 | if( (g_mp3Player_State != MP3_STATE_STOPPING) && (g_mp3Player_State != MP3_STATE_STOPREQ) ) |
nameless129 | 3:67e97c846cec | 278 | { |
nameless129 | 5:a493361aead2 | 279 | g_mp3Player_State = MP3_STATE_STOPREQ; |
nameless129 | 3:67e97c846cec | 280 | } |
nameless129 | 3:67e97c846cec | 281 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 282 | } |
nameless129 | 3:67e97c846cec | 283 | } |
nameless129 | 3:67e97c846cec | 284 | else if( checkTouchBotton_next(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 285 | { |
nameless129 | 3:67e97c846cec | 286 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 287 | { |
nameless129 | 5:a493361aead2 | 288 | printf("next touch\r\n"); |
nameless129 | 5:a493361aead2 | 289 | g_mp3Player_State = MP3_STATE_NEXTREQ; |
nameless129 | 3:67e97c846cec | 290 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 291 | } |
nameless129 | 3:67e97c846cec | 292 | } |
nameless129 | 3:67e97c846cec | 293 | else if( checkTouchBotton_volup(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 294 | { |
nameless129 | 3:67e97c846cec | 295 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 296 | { |
nameless129 | 5:a493361aead2 | 297 | printf("volup touch\r\n"); |
nameless129 | 5:a493361aead2 | 298 | if(g_mp3Player_Volume >= 6527) |
nameless129 | 3:67e97c846cec | 299 | { |
nameless129 | 5:a493361aead2 | 300 | g_mp3Player_Volume-=6527; |
nameless129 | 5:a493361aead2 | 301 | gf_mp3Playwe_VolmeUpdate = 1; |
nameless129 | 3:67e97c846cec | 302 | } |
nameless129 | 3:67e97c846cec | 303 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 304 | } |
nameless129 | 5:a493361aead2 | 305 | |
nameless129 | 3:67e97c846cec | 306 | } |
nameless129 | 3:67e97c846cec | 307 | else if( checkTouchBotton_voldown(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 308 | { |
nameless129 | 3:67e97c846cec | 309 | if(touchPanel_Touched == 0) |
nameless129 | 3:67e97c846cec | 310 | { |
nameless129 | 5:a493361aead2 | 311 | printf("voldown touch\r\n"); |
nameless129 | 5:a493361aead2 | 312 | if(g_mp3Player_Volume <= 0xE57F ) |
nameless129 | 3:67e97c846cec | 313 | { |
nameless129 | 5:a493361aead2 | 314 | g_mp3Player_Volume+=6527; |
nameless129 | 5:a493361aead2 | 315 | gf_mp3Playwe_VolmeUpdate = 1; |
nameless129 | 3:67e97c846cec | 316 | } |
nameless129 | 3:67e97c846cec | 317 | touchPanel_Touched = 1; |
nameless129 | 3:67e97c846cec | 318 | } |
nameless129 | 3:67e97c846cec | 319 | } |
nameless129 | 3:67e97c846cec | 320 | else //any botton not touched |
nameless129 | 3:67e97c846cec | 321 | { |
nameless129 | 3:67e97c846cec | 322 | touchPanel_Touched = 0; |
nameless129 | 3:67e97c846cec | 323 | } |
nameless129 | 5:a493361aead2 | 324 | |
nameless129 | 3:67e97c846cec | 325 | ////////////////////////////////////////////////////////////// |
nameless129 | 3:67e97c846cec | 326 | /* MP3 Player Control Section */ |
nameless129 | 3:67e97c846cec | 327 | ////////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 328 | if(g_mp3Player_State == MP3_STATE_PLAYREQ) |
nameless129 | 3:67e97c846cec | 329 | { |
nameless129 | 5:a493361aead2 | 330 | printf("FileOpen:%s\r\n",mp3PlayingFileName); |
nameless129 | 5:a493361aead2 | 331 | fp = fopen(mp3PlayingFileName, "rb"); |
nameless129 | 3:67e97c846cec | 332 | SDFileOpenFailCnt = 0; |
nameless129 | 3:67e97c846cec | 333 | while(!fp) |
nameless129 | 3:67e97c846cec | 334 | { |
nameless129 | 3:67e97c846cec | 335 | SDFileOpenFailCnt+=1; |
nameless129 | 3:67e97c846cec | 336 | if(SDFileOpenFailCnt >= 3) |
nameless129 | 3:67e97c846cec | 337 | { |
nameless129 | 3:67e97c846cec | 338 | printf("Fail SD init\r\n"); |
nameless129 | 3:67e97c846cec | 339 | printf("System Stop.\r\n"); |
nameless129 | 3:67e97c846cec | 340 | while(1); |
nameless129 | 3:67e97c846cec | 341 | } |
nameless129 | 3:67e97c846cec | 342 | printf("Fail file open n=%d\r\n",SDFileOpenFailCnt); |
nameless129 | 3:67e97c846cec | 343 | sd.disk_initialize(); |
nameless129 | 5:a493361aead2 | 344 | fp = fopen(mp3PlayingFileName, "rb"); |
nameless129 | 3:67e97c846cec | 345 | wait(1); |
nameless129 | 3:67e97c846cec | 346 | } |
nameless129 | 3:67e97c846cec | 347 | |
nameless129 | 3:67e97c846cec | 348 | //Get file size |
nameless129 | 3:67e97c846cec | 349 | fseek( fp, 0, SEEK_END ); |
nameless129 | 3:67e97c846cec | 350 | mp3_fileSize = ftell( fp ); |
nameless129 | 3:67e97c846cec | 351 | printf("FileOpen. size=%dbit\r\n",mp3_fileSize); |
nameless129 | 3:67e97c846cec | 352 | |
nameless129 | 3:67e97c846cec | 353 | //move file pointer to top. |
nameless129 | 3:67e97c846cec | 354 | rewind(fp); |
nameless129 | 3:67e97c846cec | 355 | clearerr(fp); |
nameless129 | 3:67e97c846cec | 356 | mp3_totalSizeSent = 0; |
nameless129 | 5:a493361aead2 | 357 | g_mp3Player_State = MP3_STATE_PLAYING; |
nameless129 | 3:67e97c846cec | 358 | } |
nameless129 | 5:a493361aead2 | 359 | if( g_mp3Player_State == MP3_STATE_PLAYING ) |
nameless129 | 3:67e97c846cec | 360 | { |
nameless129 | 5:a493361aead2 | 361 | // printf("totalSendSize:%d\r\n",mp3_totalSizeSent); |
nameless129 | 3:67e97c846cec | 362 | |
nameless129 | 3:67e97c846cec | 363 | if(mp3_totalSizeSent>=mp3_fileSize) //play song end |
nameless129 | 3:67e97c846cec | 364 | { |
nameless129 | 5:a493361aead2 | 365 | g_mp3Player_State = MP3_STATE_STOPREQ; |
nameless129 | 3:67e97c846cec | 366 | } |
nameless129 | 3:67e97c846cec | 367 | else //transmit from SDCard to VS1033 |
nameless129 | 3:67e97c846cec | 368 | { |
nameless129 | 3:67e97c846cec | 369 | mp3_ReadFileSize = fread(buf, sizeof(uint8_t), SD_READ_BLOCK_SIZE, fp); |
nameless129 | 3:67e97c846cec | 370 | mp3_totalSizeSent += mp3.sendDataBlock(buf, mp3_ReadFileSize); |
nameless129 | 3:67e97c846cec | 371 | f_mp3Playwe_Playing = 1; |
nameless129 | 3:67e97c846cec | 372 | } |
nameless129 | 3:67e97c846cec | 373 | } |
nameless129 | 5:a493361aead2 | 374 | if( (g_mp3Player_State == MP3_STATE_STOPREQ) || (g_mp3Player_State == MP3_STATE_REPLAY) ) |
nameless129 | 3:67e97c846cec | 375 | { |
nameless129 | 4:28900cff8f48 | 376 | uint16_t returnCode=0; |
nameless129 | 4:28900cff8f48 | 377 | uint16_t stopFailCnt = 0; |
nameless129 | 4:28900cff8f48 | 378 | do |
nameless129 | 4:28900cff8f48 | 379 | { |
nameless129 | 4:28900cff8f48 | 380 | returnCode = mp3.stop(); |
nameless129 | 4:28900cff8f48 | 381 | printf("STOP\r\nSTOP CODE:%d\r\n",returnCode); |
nameless129 | 4:28900cff8f48 | 382 | |
nameless129 | 4:28900cff8f48 | 383 | if(returnCode != 0) |
nameless129 | 4:28900cff8f48 | 384 | { |
nameless129 | 4:28900cff8f48 | 385 | stopFailCnt++; |
nameless129 | 4:28900cff8f48 | 386 | } |
nameless129 | 5:a493361aead2 | 387 | if(stopFailCnt >= 20) |
nameless129 | 4:28900cff8f48 | 388 | { |
nameless129 | 4:28900cff8f48 | 389 | printf("ERROR! impossible of stop\r\nSystem STOP\r\n"); |
nameless129 | 4:28900cff8f48 | 390 | while(1); |
nameless129 | 4:28900cff8f48 | 391 | } |
nameless129 | 4:28900cff8f48 | 392 | }while(returnCode != 0); |
nameless129 | 2:0090839c8276 | 393 | fclose(fp); |
nameless129 | 2:0090839c8276 | 394 | fp = NULL; |
nameless129 | 3:67e97c846cec | 395 | f_mp3Playwe_Playing = 0; |
nameless129 | 5:a493361aead2 | 396 | if(g_mp3Player_State == MP3_STATE_STOPREQ) |
nameless129 | 5:a493361aead2 | 397 | { |
nameless129 | 5:a493361aead2 | 398 | g_mp3Player_State = MP3_STATE_STOPPING; |
nameless129 | 5:a493361aead2 | 399 | } |
nameless129 | 5:a493361aead2 | 400 | if(g_mp3Player_State == MP3_STATE_REPLAY) |
nameless129 | 5:a493361aead2 | 401 | { |
nameless129 | 5:a493361aead2 | 402 | g_mp3Player_State = MP3_STATE_PLAYREQ; |
nameless129 | 5:a493361aead2 | 403 | } |
nameless129 | 2:0090839c8276 | 404 | } |
nameless129 | 5:a493361aead2 | 405 | |
nameless129 | 5:a493361aead2 | 406 | if( g_mp3Player_State == MP3_STATE_STOPPING ) |
nameless129 | 5:a493361aead2 | 407 | { |
nameless129 | 5:a493361aead2 | 408 | f_mp3Playwe_Playing = 0; |
nameless129 | 5:a493361aead2 | 409 | } |
nameless129 | 5:a493361aead2 | 410 | |
nameless129 | 5:a493361aead2 | 411 | if( g_mp3Player_State == MP3_STATE_NEXTREQ ) |
nameless129 | 2:0090839c8276 | 412 | { |
nameless129 | 5:a493361aead2 | 413 | if( mp3PlayingFileNo >= (SDFileList_cnt -1) ) |
nameless129 | 5:a493361aead2 | 414 | { |
nameless129 | 5:a493361aead2 | 415 | mp3PlayingFileNo = 0; |
nameless129 | 5:a493361aead2 | 416 | } |
nameless129 | 5:a493361aead2 | 417 | else |
nameless129 | 5:a493361aead2 | 418 | { |
nameless129 | 5:a493361aead2 | 419 | mp3PlayingFileNo+=1; |
nameless129 | 5:a493361aead2 | 420 | } |
nameless129 | 5:a493361aead2 | 421 | g_mp3Player_State = MP3_STATE_FILECHANGE; |
nameless129 | 3:67e97c846cec | 422 | } |
nameless129 | 3:67e97c846cec | 423 | |
nameless129 | 5:a493361aead2 | 424 | if( g_mp3Player_State == MP3_STATE_PREVREQ ) |
nameless129 | 5:a493361aead2 | 425 | { |
nameless129 | 5:a493361aead2 | 426 | if( mp3PlayingFileNo <= 0 ) |
nameless129 | 5:a493361aead2 | 427 | { |
nameless129 | 5:a493361aead2 | 428 | mp3PlayingFileNo = (SDFileList_cnt - 1); |
nameless129 | 5:a493361aead2 | 429 | } |
nameless129 | 5:a493361aead2 | 430 | else |
nameless129 | 5:a493361aead2 | 431 | { |
nameless129 | 5:a493361aead2 | 432 | mp3PlayingFileNo-=1; |
nameless129 | 5:a493361aead2 | 433 | } |
nameless129 | 5:a493361aead2 | 434 | g_mp3Player_State = MP3_STATE_FILECHANGE; |
nameless129 | 5:a493361aead2 | 435 | } |
nameless129 | 5:a493361aead2 | 436 | if( g_mp3Player_State == MP3_STATE_FILECHANGE ) |
nameless129 | 3:67e97c846cec | 437 | { |
nameless129 | 5:a493361aead2 | 438 | printf("next:%d,%s\r\n",mp3PlayingFileNo,SDFileList[mp3PlayingFileNo]); |
nameless129 | 5:a493361aead2 | 439 | sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]); |
nameless129 | 5:a493361aead2 | 440 | if(f_mp3Playwe_Playing == 1) |
nameless129 | 5:a493361aead2 | 441 | { |
nameless129 | 5:a493361aead2 | 442 | g_mp3Player_State = MP3_STATE_REPLAY; |
nameless129 | 5:a493361aead2 | 443 | } |
nameless129 | 5:a493361aead2 | 444 | else |
nameless129 | 5:a493361aead2 | 445 | { |
nameless129 | 5:a493361aead2 | 446 | g_mp3Player_State = MP3_STATE_STOPPING; |
nameless129 | 5:a493361aead2 | 447 | } |
nameless129 | 5:a493361aead2 | 448 | } |
nameless129 | 5:a493361aead2 | 449 | |
nameless129 | 5:a493361aead2 | 450 | if( gf_mp3Playwe_VolmeUpdate == 1 ) |
nameless129 | 5:a493361aead2 | 451 | { |
nameless129 | 5:a493361aead2 | 452 | mp3.VolControl(g_mp3Player_Volume); |
nameless129 | 5:a493361aead2 | 453 | gf_mp3Playwe_VolmeUpdate = 0; |
nameless129 | 5:a493361aead2 | 454 | printf("Vol:%d\r\n",g_mp3Player_Volume); |
nameless129 | 2:0090839c8276 | 455 | } |
nameless129 | 2:0090839c8276 | 456 | } |
nameless129 | 0:5f0e931ae677 | 457 | } |