use VS1033(MP3 decoder) and UL024TF(TFTLCD)
Dependencies: FastIO SDFileSystem TFTLCDwithFastIO TouchPanel VS1033 mbed
Fork of 11U68_MP3Player with TFTLCD by
main.cpp@6:74271fce2368, 2015-07-17 (annotated)
- Committer:
- nameless129
- Date:
- Fri Jul 17 21:35:57 2015 +0000
- Revision:
- 6:74271fce2368
- Parent:
- 5:a493361aead2
- Child:
- 7:fc65d965a569
?????????????; ??????????; ????????
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 | 6:74271fce2368 | 40 | if( ( (xpos >= BOTTON_PREV_XPOS+5) && (xpos <= BOTTON_PREV_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 41 | ( (ypos >= BOTTON_PREV_YPOS+5) && (ypos <= BOTTON_PREV_YPOS+55) ) ) |
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 | 6:74271fce2368 | 51 | if( ( (xpos >= BOTTON_PLAY_XPOS+5) && (xpos <= BOTTON_PLAY_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 52 | ( (ypos >= BOTTON_PLAY_YPOS+5) && (ypos <= BOTTON_PLAY_YPOS+55) ) ) |
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 | 6:74271fce2368 | 62 | if( ( (xpos >= BOTTON_STOP_XPOS+5) && (xpos <= BOTTON_STOP_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 63 | ( (ypos >= BOTTON_STOP_XPOS+5) && (ypos <= BOTTON_STOP_XPOS+55) ) ) |
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 | 6:74271fce2368 | 73 | if( ( (xpos >= BOTTON_NEXT_XPOS+5) && (xpos <= BOTTON_NEXT_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 74 | ( (ypos >= BOTTON_NEXT_YPOS+5) && (ypos <= BOTTON_NEXT_YPOS+55) ) ) |
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 | 6:74271fce2368 | 84 | if( ( (xpos >= BOTTON_VOLUP_XPOS+5) && (xpos <= BOTTON_VOLUP_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 85 | ( (ypos >= BOTTON_VOLUP_YPOS+5) && (ypos <= BOTTON_VOLUP_YPOS+55) ) ) |
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 | 6:74271fce2368 | 95 | if( ( (xpos >= BOTTON_VOLDOWN_XPOS+5) && (xpos <= BOTTON_VOLDOWN_XPOS+55) ) && |
nameless129 | 6:74271fce2368 | 96 | ( (ypos >= BOTTON_VOLDOWN_YPOS+5) && (ypos <= BOTTON_VOLDOWN_YPOS+55) ) ) |
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 | 6:74271fce2368 | 103 | #define TOUCHPANEL_BOTTON_TOUCH_STOP (0) |
nameless129 | 6:74271fce2368 | 104 | #define TOUCHPANEL_BOTTON_TOUCH_PLAY (1) |
nameless129 | 6:74271fce2368 | 105 | #define TOUCHPANEL_BOTTON_TOUCH_NEXT (2) |
nameless129 | 6:74271fce2368 | 106 | #define TOUCHPANEL_BOTTON_TOUCH_PREV (3) |
nameless129 | 6:74271fce2368 | 107 | #define TOUCHPANEL_BOTTON_TOUCH_VOLUP (4) |
nameless129 | 6:74271fce2368 | 108 | #define TOUCHPANEL_BOTTON_TOUCH_VOLDOWN (5) |
nameless129 | 6:74271fce2368 | 109 | #define TOUCHPANEL_BOTTON_NOT_TOUCH (-1) |
nameless129 | 6:74271fce2368 | 110 | #define TOUCHPANEL_OTHER_TOUCH (-2) |
nameless129 | 6:74271fce2368 | 111 | |
nameless129 | 6:74271fce2368 | 112 | int8_t detectTouchBotton(int32_t xpos,int32_t ypos) |
nameless129 | 6:74271fce2368 | 113 | { |
nameless129 | 6:74271fce2368 | 114 | int8_t result = 0; |
nameless129 | 6:74271fce2368 | 115 | |
nameless129 | 6:74271fce2368 | 116 | if( checkTouchBotton_stop(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 117 | { |
nameless129 | 6:74271fce2368 | 118 | result = TOUCHPANEL_BOTTON_TOUCH_STOP; |
nameless129 | 6:74271fce2368 | 119 | } |
nameless129 | 6:74271fce2368 | 120 | else if( checkTouchBotton_play(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 121 | { |
nameless129 | 6:74271fce2368 | 122 | result = TOUCHPANEL_BOTTON_TOUCH_PLAY; |
nameless129 | 6:74271fce2368 | 123 | } |
nameless129 | 6:74271fce2368 | 124 | else if( checkTouchBotton_prev(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 125 | { |
nameless129 | 6:74271fce2368 | 126 | result = TOUCHPANEL_BOTTON_TOUCH_PREV; |
nameless129 | 6:74271fce2368 | 127 | } |
nameless129 | 6:74271fce2368 | 128 | else if( checkTouchBotton_next(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 129 | { |
nameless129 | 6:74271fce2368 | 130 | result = TOUCHPANEL_BOTTON_TOUCH_NEXT; |
nameless129 | 6:74271fce2368 | 131 | } |
nameless129 | 6:74271fce2368 | 132 | else if( checkTouchBotton_volup(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 133 | { |
nameless129 | 6:74271fce2368 | 134 | result = TOUCHPANEL_BOTTON_TOUCH_VOLUP; |
nameless129 | 6:74271fce2368 | 135 | } |
nameless129 | 6:74271fce2368 | 136 | else if( checkTouchBotton_voldown(xpos,ypos) ) |
nameless129 | 6:74271fce2368 | 137 | { |
nameless129 | 6:74271fce2368 | 138 | result = TOUCHPANEL_BOTTON_TOUCH_VOLDOWN; |
nameless129 | 6:74271fce2368 | 139 | } |
nameless129 | 6:74271fce2368 | 140 | else if( (xpos == -1) || (ypos == -1) ) |
nameless129 | 6:74271fce2368 | 141 | { |
nameless129 | 6:74271fce2368 | 142 | result = TOUCHPANEL_BOTTON_NOT_TOUCH; |
nameless129 | 6:74271fce2368 | 143 | } |
nameless129 | 6:74271fce2368 | 144 | else |
nameless129 | 6:74271fce2368 | 145 | { |
nameless129 | 6:74271fce2368 | 146 | result = TOUCHPANEL_OTHER_TOUCH; |
nameless129 | 6:74271fce2368 | 147 | } |
nameless129 | 6:74271fce2368 | 148 | |
nameless129 | 6:74271fce2368 | 149 | return result; |
nameless129 | 6:74271fce2368 | 150 | } |
nameless129 | 6:74271fce2368 | 151 | |
nameless129 | 5:a493361aead2 | 152 | uint8_t g_mp3Player_State = 0; |
nameless129 | 5:a493361aead2 | 153 | uint16_t g_mp3Player_Volume = 0; |
nameless129 | 5:a493361aead2 | 154 | bool gf_mp3Playwe_VolmeUpdate = 0; |
nameless129 | 6:74271fce2368 | 155 | bool gf_TimerInt = 0; |
nameless129 | 5:a493361aead2 | 156 | |
nameless129 | 5:a493361aead2 | 157 | void Int100msFunc() |
nameless129 | 5:a493361aead2 | 158 | { |
nameless129 | 6:74271fce2368 | 159 | gf_TimerInt = 1; |
nameless129 | 5:a493361aead2 | 160 | } |
nameless129 | 2:0090839c8276 | 161 | |
nameless129 | 0:5f0e931ae677 | 162 | int main() |
nameless129 | 0:5f0e931ae677 | 163 | { |
nameless129 | 2:0090839c8276 | 164 | static FILE *fp = NULL; |
nameless129 | 3:67e97c846cec | 165 | uint8_t SDFileOpenFailCnt = 0; |
nameless129 | 3:67e97c846cec | 166 | size_t mp3_ReadFileSize = 0; |
nameless129 | 3:67e97c846cec | 167 | size_t mp3_totalSizeSent=0; |
nameless129 | 3:67e97c846cec | 168 | size_t mp3_fileSize=0; |
nameless129 | 3:67e97c846cec | 169 | bool f_mp3Playwe_Playing = 0; |
nameless129 | 2:0090839c8276 | 170 | uint8_t buf[SD_READ_BLOCK_SIZE]; |
nameless129 | 3:67e97c846cec | 171 | char str[100]; |
nameless129 | 3:67e97c846cec | 172 | int32_t XReadPos = 0,YReadPos = 0; |
nameless129 | 6:74271fce2368 | 173 | bool touchPanel_Touched = 0; |
nameless129 | 3:67e97c846cec | 174 | //Format,Xsize,Ysize,PixelData |
nameless129 | 3:67e97c846cec | 175 | const bitmap_t img_button_play = { RGB16, 60, 60, &bmp_button_play }; |
nameless129 | 3:67e97c846cec | 176 | const bitmap_t img_button_stop = { RGB16, 60, 60, &bmp_button_stop }; |
nameless129 | 3:67e97c846cec | 177 | const bitmap_t img_button_next = { RGB16, 60, 60, &bmp_button_next }; |
nameless129 | 3:67e97c846cec | 178 | const bitmap_t img_button_prev = { RGB16, 60, 60, &bmp_button_prev }; |
nameless129 | 6:74271fce2368 | 179 | // const bitmap_t img_button_volup = { RGB16, 60, 60, &bmp_button_volup }; |
nameless129 | 6:74271fce2368 | 180 | // const bitmap_t img_button_voldown = { RGB16, 60, 60, &bmp_button_voldown }; |
nameless129 | 5:a493361aead2 | 181 | |
nameless129 | 5:a493361aead2 | 182 | pc.baud(921600); |
nameless129 | 5:a493361aead2 | 183 | printf("Power ON\r\n"); |
nameless129 | 2:0090839c8276 | 184 | |
nameless129 | 5:a493361aead2 | 185 | Int100ms.attach_us(&Int100msFunc, 100000); |
nameless129 | 2:0090839c8276 | 186 | |
nameless129 | 3:67e97c846cec | 187 | //SD Init.(本来ならいらないけど、SDカードによっちゃもう1回リセットしないとダメポ |
nameless129 | 3:67e97c846cec | 188 | sd.disk_initialize(); |
nameless129 | 3:67e97c846cec | 189 | |
nameless129 | 2:0090839c8276 | 190 | //LCD Init. |
nameless129 | 0:5f0e931ae677 | 191 | lcd.Initialize(LANDSCAPE,RGB16); |
nameless129 | 2:0090839c8276 | 192 | |
nameless129 | 2:0090839c8276 | 193 | /* for sine test mode */ |
nameless129 | 2:0090839c8276 | 194 | // mp3.sine_test_activate(SineWave_10k); |
nameless129 | 2:0090839c8276 | 195 | // while(1); |
nameless129 | 3:67e97c846cec | 196 | |
nameless129 | 2:0090839c8276 | 197 | //MP3 decoder Init. |
nameless129 | 2:0090839c8276 | 198 | mp3.hardwareReset(); |
nameless129 | 2:0090839c8276 | 199 | mp3.sci_init(); |
nameless129 | 2:0090839c8276 | 200 | mp3.sdi_init(); |
nameless129 | 2:0090839c8276 | 201 | wait(0.1); |
nameless129 | 2:0090839c8276 | 202 | |
nameless129 | 2:0090839c8276 | 203 | printf("init CMPL.\r\n"); |
nameless129 | 2:0090839c8276 | 204 | |
nameless129 | 0:5f0e931ae677 | 205 | lcd.SetBackground(COLOR_BLUE); |
nameless129 | 0:5f0e931ae677 | 206 | lcd.FillScreen(-1); |
nameless129 | 5:a493361aead2 | 207 | lcd.SetFont( &TerminusBigFont ); |
nameless129 | 2:0090839c8276 | 208 | |
nameless129 | 5:a493361aead2 | 209 | //for Caliblation |
nameless129 | 5:a493361aead2 | 210 | while(0) |
nameless129 | 5:a493361aead2 | 211 | { |
nameless129 | 5:a493361aead2 | 212 | int32_t XReadPos = 0,YReadPos = 0; |
nameless129 | 5:a493361aead2 | 213 | lcd.DrawCircle(40,40,10,COLOR_WHITE); |
nameless129 | 5:a493361aead2 | 214 | lcd.DrawCircle(280,200,10,COLOR_WHITE); |
nameless129 | 5:a493361aead2 | 215 | XReadPos = getTouchPanelPosX(); |
nameless129 | 5:a493361aead2 | 216 | YReadPos = getTouchPanelPosY(); |
nameless129 | 5:a493361aead2 | 217 | printf("X:%d Y:%d\r\n",XReadPos,YReadPos); |
nameless129 | 5:a493361aead2 | 218 | wait_ms(500); |
nameless129 | 5:a493361aead2 | 219 | } |
nameless129 | 5:a493361aead2 | 220 | |
nameless129 | 3:67e97c846cec | 221 | //Xpos, Ypos, ImageData(type:bitmap_t), Scale |
nameless129 | 3:67e97c846cec | 222 | lcd.DrawBitmap( BOTTON_PREV_XPOS, BOTTON_PREV_YPOS, (const bitmap_t*)&img_button_prev, 1 ); |
nameless129 | 3:67e97c846cec | 223 | lcd.DrawBitmap( BOTTON_PLAY_XPOS, BOTTON_PLAY_YPOS, (const bitmap_t*)&img_button_play, 1 ); |
nameless129 | 3:67e97c846cec | 224 | lcd.DrawBitmap( BOTTON_STOP_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_stop, 1 ); |
nameless129 | 3:67e97c846cec | 225 | lcd.DrawBitmap( BOTTON_NEXT_XPOS, BOTTON_STOP_YPOS, (const bitmap_t*)&img_button_next, 1 ); |
nameless129 | 6:74271fce2368 | 226 | // lcd.DrawBitmap( BOTTON_VOLUP_XPOS, BOTTON_VOLUP_YPOS, (const bitmap_t*)&img_button_volup, 1 ); |
nameless129 | 6:74271fce2368 | 227 | // lcd.DrawBitmap( BOTTON_VOLDOWN_XPOS, BOTTON_VOLDOWN_YPOS, (const bitmap_t*)&img_button_voldown, 1 ); |
nameless129 | 2:0090839c8276 | 228 | |
nameless129 | 5:a493361aead2 | 229 | //////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 230 | /* SDCard GetFileList Section */ |
nameless129 | 5:a493361aead2 | 231 | //////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 232 | #define SD_MAX_FILENAME_LENGTH (256) //MAX 256 |
nameless129 | 5:a493361aead2 | 233 | #define SD_MAX_FILE_COUNT (20) |
nameless129 | 5:a493361aead2 | 234 | |
nameless129 | 5:a493361aead2 | 235 | char SDFileList[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0}; |
nameless129 | 5:a493361aead2 | 236 | char SDFileList_short[SD_MAX_FILE_COUNT][SD_MAX_FILENAME_LENGTH]={0}; |
nameless129 | 5:a493361aead2 | 237 | char SDFileList_cnt = 0; |
nameless129 | 5:a493361aead2 | 238 | char mp3PlayingFileName[SD_MAX_FILENAME_LENGTH]={0}; |
nameless129 | 5:a493361aead2 | 239 | uint8_t mp3PlayingFileNo = 0; |
nameless129 | 5:a493361aead2 | 240 | int i = 0; |
nameless129 | 5:a493361aead2 | 241 | DIR *d; |
nameless129 | 5:a493361aead2 | 242 | struct dirent *p; |
nameless129 | 5:a493361aead2 | 243 | |
nameless129 | 5:a493361aead2 | 244 | d = opendir("/sd"); |
nameless129 | 5:a493361aead2 | 245 | if ( d != NULL ) |
nameless129 | 5:a493361aead2 | 246 | { |
nameless129 | 5:a493361aead2 | 247 | while ( (p = readdir(d)) != NULL ) |
nameless129 | 5:a493361aead2 | 248 | { |
nameless129 | 5:a493361aead2 | 249 | char *ret; |
nameless129 | 5:a493361aead2 | 250 | ret = strstr(p->d_name,"System"); //System Vol..フォルダは除外 |
nameless129 | 5:a493361aead2 | 251 | if(ret == 0) |
nameless129 | 5:a493361aead2 | 252 | { |
nameless129 | 5:a493361aead2 | 253 | sprintf((char *)(SDFileList_short[i]+0),"%s",(const char *)p->d_name); |
nameless129 | 5:a493361aead2 | 254 | sprintf((char *)(SDFileList[i]+0),"/sd/%s",(const char *)p->d_name); |
nameless129 | 5:a493361aead2 | 255 | i+=1; |
nameless129 | 5:a493361aead2 | 256 | } |
nameless129 | 5:a493361aead2 | 257 | } |
nameless129 | 5:a493361aead2 | 258 | SDFileList_cnt = i; |
nameless129 | 5:a493361aead2 | 259 | } |
nameless129 | 5:a493361aead2 | 260 | closedir(d); |
nameless129 | 5:a493361aead2 | 261 | |
nameless129 | 5:a493361aead2 | 262 | //g_mp3Player_Stateに対して↓ |
nameless129 | 3:67e97c846cec | 263 | #define MP3_STATE_STOPPING (0) |
nameless129 | 3:67e97c846cec | 264 | #define MP3_STATE_STOPREQ (1) |
nameless129 | 3:67e97c846cec | 265 | #define MP3_STATE_PLAYREQ (2) |
nameless129 | 3:67e97c846cec | 266 | #define MP3_STATE_PLAYING (3) |
nameless129 | 3:67e97c846cec | 267 | #define MP3_STATE_NEXTREQ (4) |
nameless129 | 3:67e97c846cec | 268 | #define MP3_STATE_PREVREQ (5) |
nameless129 | 3:67e97c846cec | 269 | #define MP3_STATE_VOLCHANGEREQ (6) |
nameless129 | 5:a493361aead2 | 270 | #define MP3_STATE_REPLAY (7) |
nameless129 | 5:a493361aead2 | 271 | #define MP3_STATE_FILECHANGE (8) |
nameless129 | 6:74271fce2368 | 272 | |
nameless129 | 6:74271fce2368 | 273 | printf("file count=%d\r\n",SDFileList_cnt); |
nameless129 | 6:74271fce2368 | 274 | mp3PlayingFileNo = 0; |
nameless129 | 6:74271fce2368 | 275 | g_mp3Player_State = MP3_STATE_FILECHANGE; |
nameless129 | 6:74271fce2368 | 276 | f_mp3Playwe_Playing = 0; |
nameless129 | 3:67e97c846cec | 277 | |
nameless129 | 6:74271fce2368 | 278 | while(1) |
nameless129 | 6:74271fce2368 | 279 | { |
nameless129 | 6:74271fce2368 | 280 | |
nameless129 | 6:74271fce2368 | 281 | ////////////////////////////////////////////////////////////// |
nameless129 | 6:74271fce2368 | 282 | /* TouchPanel GetStatas Section */ |
nameless129 | 6:74271fce2368 | 283 | ////////////////////////////////////////////////////////////// |
nameless129 | 6:74271fce2368 | 284 | if(gf_TimerInt == 1) |
nameless129 | 3:67e97c846cec | 285 | { |
nameless129 | 6:74271fce2368 | 286 | XReadPos = getTouchPanelPosX(); |
nameless129 | 6:74271fce2368 | 287 | YReadPos = getTouchPanelPosY(); |
nameless129 | 6:74271fce2368 | 288 | // printf("X:%d Y:%d\r\n",XReadPos,YReadPos); |
nameless129 | 6:74271fce2368 | 289 | switch( detectTouchBotton(XReadPos,YReadPos) ) |
nameless129 | 3:67e97c846cec | 290 | { |
nameless129 | 6:74271fce2368 | 291 | case TOUCHPANEL_BOTTON_TOUCH_PREV: |
nameless129 | 6:74271fce2368 | 292 | if(touchPanel_Touched == 0) |
nameless129 | 6:74271fce2368 | 293 | { |
nameless129 | 6:74271fce2368 | 294 | printf("prev touch\r\n"); |
nameless129 | 6:74271fce2368 | 295 | g_mp3Player_State = MP3_STATE_PREVREQ; |
nameless129 | 6:74271fce2368 | 296 | touchPanel_Touched = 1; |
nameless129 | 6:74271fce2368 | 297 | } |
nameless129 | 6:74271fce2368 | 298 | break; |
nameless129 | 6:74271fce2368 | 299 | case TOUCHPANEL_BOTTON_TOUCH_PLAY: |
nameless129 | 6:74271fce2368 | 300 | if(touchPanel_Touched == 0) |
nameless129 | 6:74271fce2368 | 301 | { |
nameless129 | 6:74271fce2368 | 302 | printf("play touch\r\n"); |
nameless129 | 6:74271fce2368 | 303 | if( (g_mp3Player_State != MP3_STATE_PLAYING) && (g_mp3Player_State != MP3_STATE_PLAYREQ) ) |
nameless129 | 6:74271fce2368 | 304 | { |
nameless129 | 6:74271fce2368 | 305 | g_mp3Player_State = MP3_STATE_PLAYREQ; |
nameless129 | 6:74271fce2368 | 306 | } |
nameless129 | 6:74271fce2368 | 307 | touchPanel_Touched = 1; |
nameless129 | 6:74271fce2368 | 308 | } |
nameless129 | 6:74271fce2368 | 309 | break; |
nameless129 | 6:74271fce2368 | 310 | case TOUCHPANEL_BOTTON_TOUCH_STOP: |
nameless129 | 6:74271fce2368 | 311 | if(touchPanel_Touched == 0) |
nameless129 | 6:74271fce2368 | 312 | { |
nameless129 | 6:74271fce2368 | 313 | printf("stop touch\r\n"); |
nameless129 | 6:74271fce2368 | 314 | if( (g_mp3Player_State != MP3_STATE_STOPPING) && (g_mp3Player_State != MP3_STATE_STOPREQ) ) |
nameless129 | 6:74271fce2368 | 315 | { |
nameless129 | 6:74271fce2368 | 316 | g_mp3Player_State = MP3_STATE_STOPREQ; |
nameless129 | 6:74271fce2368 | 317 | } |
nameless129 | 6:74271fce2368 | 318 | touchPanel_Touched = 1; |
nameless129 | 6:74271fce2368 | 319 | } |
nameless129 | 6:74271fce2368 | 320 | break; |
nameless129 | 6:74271fce2368 | 321 | case TOUCHPANEL_BOTTON_TOUCH_NEXT: |
nameless129 | 6:74271fce2368 | 322 | if(touchPanel_Touched == 0) |
nameless129 | 6:74271fce2368 | 323 | { |
nameless129 | 6:74271fce2368 | 324 | printf("next touch\r\n"); |
nameless129 | 6:74271fce2368 | 325 | g_mp3Player_State = MP3_STATE_NEXTREQ; |
nameless129 | 6:74271fce2368 | 326 | touchPanel_Touched = 1; |
nameless129 | 6:74271fce2368 | 327 | } |
nameless129 | 6:74271fce2368 | 328 | break; |
nameless129 | 6:74271fce2368 | 329 | case TOUCHPANEL_OTHER_TOUCH: |
nameless129 | 6:74271fce2368 | 330 | printf("otherTouch\r\n"); |
nameless129 | 6:74271fce2368 | 331 | printf("X:%d Y:%d\r\n",XReadPos,YReadPos); |
nameless129 | 6:74271fce2368 | 332 | break; |
nameless129 | 6:74271fce2368 | 333 | case TOUCHPANEL_BOTTON_NOT_TOUCH: |
nameless129 | 6:74271fce2368 | 334 | // printf("notTouch\r\n"); |
nameless129 | 6:74271fce2368 | 335 | touchPanel_Touched = 0; |
nameless129 | 6:74271fce2368 | 336 | break; |
nameless129 | 6:74271fce2368 | 337 | default : |
nameless129 | 6:74271fce2368 | 338 | break; |
nameless129 | 3:67e97c846cec | 339 | } |
nameless129 | 3:67e97c846cec | 340 | } |
nameless129 | 5:a493361aead2 | 341 | |
nameless129 | 3:67e97c846cec | 342 | ////////////////////////////////////////////////////////////// |
nameless129 | 3:67e97c846cec | 343 | /* MP3 Player Control Section */ |
nameless129 | 3:67e97c846cec | 344 | ////////////////////////////////////////////////////////////// |
nameless129 | 5:a493361aead2 | 345 | if(g_mp3Player_State == MP3_STATE_PLAYREQ) |
nameless129 | 3:67e97c846cec | 346 | { |
nameless129 | 5:a493361aead2 | 347 | printf("FileOpen:%s\r\n",mp3PlayingFileName); |
nameless129 | 5:a493361aead2 | 348 | fp = fopen(mp3PlayingFileName, "rb"); |
nameless129 | 3:67e97c846cec | 349 | SDFileOpenFailCnt = 0; |
nameless129 | 3:67e97c846cec | 350 | while(!fp) |
nameless129 | 3:67e97c846cec | 351 | { |
nameless129 | 3:67e97c846cec | 352 | SDFileOpenFailCnt+=1; |
nameless129 | 3:67e97c846cec | 353 | if(SDFileOpenFailCnt >= 3) |
nameless129 | 3:67e97c846cec | 354 | { |
nameless129 | 3:67e97c846cec | 355 | printf("Fail SD init\r\n"); |
nameless129 | 3:67e97c846cec | 356 | printf("System Stop.\r\n"); |
nameless129 | 6:74271fce2368 | 357 | NVIC_SystemReset(); |
nameless129 | 3:67e97c846cec | 358 | } |
nameless129 | 3:67e97c846cec | 359 | printf("Fail file open n=%d\r\n",SDFileOpenFailCnt); |
nameless129 | 3:67e97c846cec | 360 | sd.disk_initialize(); |
nameless129 | 5:a493361aead2 | 361 | fp = fopen(mp3PlayingFileName, "rb"); |
nameless129 | 3:67e97c846cec | 362 | wait(1); |
nameless129 | 3:67e97c846cec | 363 | } |
nameless129 | 3:67e97c846cec | 364 | |
nameless129 | 3:67e97c846cec | 365 | //Get file size |
nameless129 | 3:67e97c846cec | 366 | fseek( fp, 0, SEEK_END ); |
nameless129 | 3:67e97c846cec | 367 | mp3_fileSize = ftell( fp ); |
nameless129 | 3:67e97c846cec | 368 | printf("FileOpen. size=%dbit\r\n",mp3_fileSize); |
nameless129 | 3:67e97c846cec | 369 | |
nameless129 | 3:67e97c846cec | 370 | //move file pointer to top. |
nameless129 | 3:67e97c846cec | 371 | rewind(fp); |
nameless129 | 3:67e97c846cec | 372 | clearerr(fp); |
nameless129 | 3:67e97c846cec | 373 | mp3_totalSizeSent = 0; |
nameless129 | 6:74271fce2368 | 374 | lcd.DrawRect(15,150,305,160); //Playing Bar |
nameless129 | 5:a493361aead2 | 375 | g_mp3Player_State = MP3_STATE_PLAYING; |
nameless129 | 3:67e97c846cec | 376 | } |
nameless129 | 5:a493361aead2 | 377 | if( g_mp3Player_State == MP3_STATE_PLAYING ) |
nameless129 | 3:67e97c846cec | 378 | { |
nameless129 | 5:a493361aead2 | 379 | // printf("totalSendSize:%d\r\n",mp3_totalSizeSent); |
nameless129 | 3:67e97c846cec | 380 | if(mp3_totalSizeSent>=mp3_fileSize) //play song end |
nameless129 | 3:67e97c846cec | 381 | { |
nameless129 | 6:74271fce2368 | 382 | f_mp3Playwe_Playing = 1; |
nameless129 | 6:74271fce2368 | 383 | g_mp3Player_State = MP3_STATE_NEXTREQ; //next song |
nameless129 | 3:67e97c846cec | 384 | } |
nameless129 | 3:67e97c846cec | 385 | else //transmit from SDCard to VS1033 |
nameless129 | 3:67e97c846cec | 386 | { |
nameless129 | 3:67e97c846cec | 387 | mp3_ReadFileSize = fread(buf, sizeof(uint8_t), SD_READ_BLOCK_SIZE, fp); |
nameless129 | 3:67e97c846cec | 388 | mp3_totalSizeSent += mp3.sendDataBlock(buf, mp3_ReadFileSize); |
nameless129 | 6:74271fce2368 | 389 | lcd.FillRect(15,150,15+290*mp3_totalSizeSent/mp3_fileSize,160,-2); |
nameless129 | 6:74271fce2368 | 390 | |
nameless129 | 3:67e97c846cec | 391 | f_mp3Playwe_Playing = 1; |
nameless129 | 3:67e97c846cec | 392 | } |
nameless129 | 3:67e97c846cec | 393 | } |
nameless129 | 5:a493361aead2 | 394 | if( (g_mp3Player_State == MP3_STATE_STOPREQ) || (g_mp3Player_State == MP3_STATE_REPLAY) ) |
nameless129 | 3:67e97c846cec | 395 | { |
nameless129 | 4:28900cff8f48 | 396 | uint16_t returnCode=0; |
nameless129 | 4:28900cff8f48 | 397 | uint16_t stopFailCnt = 0; |
nameless129 | 4:28900cff8f48 | 398 | do |
nameless129 | 4:28900cff8f48 | 399 | { |
nameless129 | 4:28900cff8f48 | 400 | returnCode = mp3.stop(); |
nameless129 | 4:28900cff8f48 | 401 | printf("STOP\r\nSTOP CODE:%d\r\n",returnCode); |
nameless129 | 4:28900cff8f48 | 402 | |
nameless129 | 4:28900cff8f48 | 403 | if(returnCode != 0) |
nameless129 | 4:28900cff8f48 | 404 | { |
nameless129 | 4:28900cff8f48 | 405 | stopFailCnt++; |
nameless129 | 4:28900cff8f48 | 406 | } |
nameless129 | 5:a493361aead2 | 407 | if(stopFailCnt >= 20) |
nameless129 | 4:28900cff8f48 | 408 | { |
nameless129 | 6:74271fce2368 | 409 | printf("ERROR! impossible of stop\r\nVS1033 Reset\r\n"); |
nameless129 | 6:74271fce2368 | 410 | mp3.hardwareReset(); |
nameless129 | 6:74271fce2368 | 411 | mp3.sci_init(); |
nameless129 | 6:74271fce2368 | 412 | mp3.sdi_init(); |
nameless129 | 6:74271fce2368 | 413 | stopFailCnt = 0; |
nameless129 | 4:28900cff8f48 | 414 | } |
nameless129 | 4:28900cff8f48 | 415 | }while(returnCode != 0); |
nameless129 | 2:0090839c8276 | 416 | fclose(fp); |
nameless129 | 2:0090839c8276 | 417 | fp = NULL; |
nameless129 | 3:67e97c846cec | 418 | f_mp3Playwe_Playing = 0; |
nameless129 | 5:a493361aead2 | 419 | if(g_mp3Player_State == MP3_STATE_STOPREQ) |
nameless129 | 5:a493361aead2 | 420 | { |
nameless129 | 5:a493361aead2 | 421 | g_mp3Player_State = MP3_STATE_STOPPING; |
nameless129 | 5:a493361aead2 | 422 | } |
nameless129 | 5:a493361aead2 | 423 | if(g_mp3Player_State == MP3_STATE_REPLAY) |
nameless129 | 5:a493361aead2 | 424 | { |
nameless129 | 5:a493361aead2 | 425 | g_mp3Player_State = MP3_STATE_PLAYREQ; |
nameless129 | 5:a493361aead2 | 426 | } |
nameless129 | 2:0090839c8276 | 427 | } |
nameless129 | 5:a493361aead2 | 428 | |
nameless129 | 5:a493361aead2 | 429 | if( g_mp3Player_State == MP3_STATE_STOPPING ) |
nameless129 | 5:a493361aead2 | 430 | { |
nameless129 | 5:a493361aead2 | 431 | f_mp3Playwe_Playing = 0; |
nameless129 | 5:a493361aead2 | 432 | } |
nameless129 | 5:a493361aead2 | 433 | |
nameless129 | 5:a493361aead2 | 434 | if( g_mp3Player_State == MP3_STATE_NEXTREQ ) |
nameless129 | 2:0090839c8276 | 435 | { |
nameless129 | 5:a493361aead2 | 436 | if( mp3PlayingFileNo >= (SDFileList_cnt -1) ) |
nameless129 | 5:a493361aead2 | 437 | { |
nameless129 | 5:a493361aead2 | 438 | mp3PlayingFileNo = 0; |
nameless129 | 5:a493361aead2 | 439 | } |
nameless129 | 5:a493361aead2 | 440 | else |
nameless129 | 5:a493361aead2 | 441 | { |
nameless129 | 5:a493361aead2 | 442 | mp3PlayingFileNo+=1; |
nameless129 | 5:a493361aead2 | 443 | } |
nameless129 | 5:a493361aead2 | 444 | g_mp3Player_State = MP3_STATE_FILECHANGE; |
nameless129 | 3:67e97c846cec | 445 | } |
nameless129 | 3:67e97c846cec | 446 | |
nameless129 | 5:a493361aead2 | 447 | if( g_mp3Player_State == MP3_STATE_PREVREQ ) |
nameless129 | 5:a493361aead2 | 448 | { |
nameless129 | 5:a493361aead2 | 449 | if( mp3PlayingFileNo <= 0 ) |
nameless129 | 5:a493361aead2 | 450 | { |
nameless129 | 5:a493361aead2 | 451 | mp3PlayingFileNo = (SDFileList_cnt - 1); |
nameless129 | 5:a493361aead2 | 452 | } |
nameless129 | 5:a493361aead2 | 453 | else |
nameless129 | 5:a493361aead2 | 454 | { |
nameless129 | 5:a493361aead2 | 455 | mp3PlayingFileNo-=1; |
nameless129 | 5:a493361aead2 | 456 | } |
nameless129 | 5:a493361aead2 | 457 | g_mp3Player_State = MP3_STATE_FILECHANGE; |
nameless129 | 5:a493361aead2 | 458 | } |
nameless129 | 5:a493361aead2 | 459 | if( g_mp3Player_State == MP3_STATE_FILECHANGE ) |
nameless129 | 3:67e97c846cec | 460 | { |
nameless129 | 5:a493361aead2 | 461 | printf("next:%d,%s\r\n",mp3PlayingFileNo,SDFileList[mp3PlayingFileNo]); |
nameless129 | 6:74271fce2368 | 462 | |
nameless129 | 6:74271fce2368 | 463 | for(i=0;i<SDFileList_cnt;i++) |
nameless129 | 6:74271fce2368 | 464 | { |
nameless129 | 6:74271fce2368 | 465 | sprintf(str,"%d:%s",i,SDFileList_short[i]); |
nameless129 | 6:74271fce2368 | 466 | lcd.Print( str, LEFT, i*28 ); // align text to center horizontally and use starndard colors |
nameless129 | 6:74271fce2368 | 467 | } |
nameless129 | 6:74271fce2368 | 468 | lcd.Print( "*", LEFT, 28*mp3PlayingFileNo ); // align text to center horizontally and use starndard colors |
nameless129 | 6:74271fce2368 | 469 | |
nameless129 | 5:a493361aead2 | 470 | sprintf(mp3PlayingFileName,"%s",SDFileList[mp3PlayingFileNo]); |
nameless129 | 5:a493361aead2 | 471 | if(f_mp3Playwe_Playing == 1) |
nameless129 | 5:a493361aead2 | 472 | { |
nameless129 | 5:a493361aead2 | 473 | g_mp3Player_State = MP3_STATE_REPLAY; |
nameless129 | 5:a493361aead2 | 474 | } |
nameless129 | 5:a493361aead2 | 475 | else |
nameless129 | 5:a493361aead2 | 476 | { |
nameless129 | 5:a493361aead2 | 477 | g_mp3Player_State = MP3_STATE_STOPPING; |
nameless129 | 5:a493361aead2 | 478 | } |
nameless129 | 5:a493361aead2 | 479 | } |
nameless129 | 5:a493361aead2 | 480 | |
nameless129 | 5:a493361aead2 | 481 | if( gf_mp3Playwe_VolmeUpdate == 1 ) |
nameless129 | 5:a493361aead2 | 482 | { |
nameless129 | 5:a493361aead2 | 483 | mp3.VolControl(g_mp3Player_Volume); |
nameless129 | 5:a493361aead2 | 484 | gf_mp3Playwe_VolmeUpdate = 0; |
nameless129 | 5:a493361aead2 | 485 | printf("Vol:%d\r\n",g_mp3Player_Volume); |
nameless129 | 2:0090839c8276 | 486 | } |
nameless129 | 2:0090839c8276 | 487 | } |
nameless129 | 0:5f0e931ae677 | 488 | } |