WIZnet / Mbed 2 deprecated MP3Decoding_VS1002_WIZwiki-W7500

Dependencies:   FTPClient javakysSDFileSystem2 WIZnetInterface mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "SDFileSystem.h"
00004 #include <stdio.h>
00005 #include <string.h>
00006 
00007 #include "FTPClient.h"
00008 #include "VS1002.h" 
00009 #include "SSD1306.h"
00010 
00011 #define MAC     "\x00\x08\xDC\x11\x34\x78"
00012 #define IP      "192.168.0.20"
00013 #define MASK    "255.255.255.0"
00014 #define GATEWAY "192.168.0.1"
00015 
00016 #define FTP_SERVER_IP "192.168.0.10"
00017 
00018 #define _MAX_FNAME_LEN_   127
00019 #define _FTP_UPDATE_TIME_  10
00020 
00021 
00022 Serial uart(USBTX, USBRX);
00023 AnalogIn   ain(A5);
00024 //SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD
00025 //SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD
00026 //SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // K64F
00027 //SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 
00028 
00029 EthernetInterface eth;
00030 InterruptIn K_VU(D3); // Volume UP Key
00031 InterruptIn K_VD(D7); // Volume Down Key
00032 InterruptIn K_FW(D4); // Foward Key
00033 InterruptIn K_BW(D6); // Backward Key
00034 InterruptIn K_ONOFF(D5); //Play/Resume or Pause Key
00035 VS1002 mp3(PB_3, PB_2, PB_1, PB_0,"sdc",D11, D12 ,D13, PC_12, PC_15, PC_14, PC_13);  //Setup Audio decoder. Name is VS1002 even though VS1053 is used.
00036 
00037 FTPClient myFTP("/sdc");  // mountname in MySeeedStudioTFTv2
00038 
00039 //Ticker ledTick;
00040 
00041 /* Global Variables to store Status*/
00042 int new_song_number=2;  //Variable to store the Song Number
00043 int volume_set=-20;     //Variable to store the Volume
00044 int previous_volume;    //Variable to store the volume when muted
00045 bool pause=false;       //Variable to store the status of Pause button 
00046 bool mute=false;        //Variable to store the status of mute button
00047 
00048 int check=0;    //Capacitative touch generates interrupt on both press and release. This variable tracks this and updates only on press.
00049 //char *song_name[9]={"Good Day","Leong","Sponsor","I'm So Sexy","My Life","Oh My god","Wonderful bar","Whale Hunting","Love"}; //Array of song names entered manually
00050 
00051 uint32_t ftp_time_1s = 0;
00052 
00053 char myfilelist[MAX_SS] = {0,};
00054 
00055 /*void ledTickfunc()
00056 {
00057     if(ftp_time_1s)
00058     {
00059         //printf("enter ftp_time_1s:%d\r\n", ftp_time_1s);
00060         if(ftp_time_1s++ > _FTP_UPDATE_TIME_) ftp_time_1s = 0;
00061     }
00062 }*/
00063 
00064 /** Volume UP
00065  *
00066  * @param 
00067  */
00068 void Volume_Up() 
00069 {
00070     volume_set+=3; // Volume Up
00071     if(volume_set>=0)
00072         volume_set=0;
00073 }
00074 
00075 /** Volume Down
00076  *
00077  * @param 
00078  */ 
00079 void Volume_Down() 
00080 {
00081     volume_set-=3;  //Volume Down
00082     if(volume_set<-55)
00083         volume_set=-55;
00084 }
00085 
00086 /** Song_Forward
00087  *
00088  * @param 
00089  */ 
00090 void Song_Forward()
00091 {
00092     new_song_number += 1;
00093     if(new_song_number == 10)
00094         new_song_number = 1;
00095 }
00096 
00097 /** Song_Backward
00098  *
00099  * @param 
00100  */ 
00101 void Song_Backward()
00102 {
00103     if(new_song_number == 1)
00104         new_song_number = 9;
00105     else
00106         new_song_number -= 1;
00107 }
00108 
00109 /** Play_Pressed
00110  *
00111  * @param 
00112  */ 
00113 void Play_Pressed()
00114 {
00115     pause = !pause;
00116 }
00117 
00118 int main (void)
00119 {
00120     *(volatile uint32_t *)(0x41001014) = 0x0060100;
00121 //    *(volatile uint32_t *)(0x41003000) = 0x10;    //D6
00122 //    *(volatile uint32_t *)(0x41003004) = 0x10;    //D5
00123 //    *(volatile uint32_t *)(0x41003008) = 0x10;    //D4
00124 //    *(volatile uint32_t *)(0x41003080) = 0x10;    //D3
00125 //    *(volatile uint32_t *)(0x41003098) = 0x10;    //D7
00126     
00127     unsigned int update_count_s=6;
00128     unsigned int update_count_ms=0;
00129     unsigned int ain_temp=0;
00130     //char* my_text = "GIF2015";
00131     /*char* tok = NULL;
00132     char* lasts = NULL;
00133     char filename[_MAX_FNAME_LEN_];
00134     FILE* fp;*/
00135     
00136     init();
00137     cls();
00138     //OLED_DrawBMP(0,0,128,8,(unsigned char *)GIF2015);
00139     //OLED_ShowStr(0,0,my_text,2);
00140 //    OLED_DrawBMP(0,0,128,8,(unsigned char *)wiznet);
00141     //LED_P23x32Str(0, 0, my_text);
00142 //    Serial Interface eth;
00143     uart.baud(115200);
00144     uart.printf("Initializing\r\n");
00145 
00146 //    EthernetInterface eth;
00147     uart.printf("Initializing Ethernet\r\n");
00148 
00149     //eth.init(); //Use DHCP
00150     eth.init((uint8_t*)MAC,IP,MASK,GATEWAY);  //IP,mask,Gateway
00151     uart.printf("Connecting\r\n");
00152     eth.connect();
00153     uart.printf("IP Address is %s\r\n", eth.getIPAddress());
00154 
00155 //    Check File System
00156     uart.printf("Checking File System\r\n");
00157     DIR *d = opendir("/sdc/");
00158     if (d != NULL) {
00159         uart.printf("SD Card Present\r\n");
00160         closedir(d);
00161     } else {
00162         uart.printf("SD Card Root Directory Not Found\r\n");
00163     }
00164 
00165     *(volatile uint32_t *)(0x41003000) = 0x00000002; //D6
00166     *(volatile uint32_t *)(0x41003004) = 0x00000002; //D5
00167     *(volatile uint32_t *)(0x41003008) = 0x00000002;  //D4
00168     *(volatile uint32_t *)(0x41003080) = 0x00000002;  //D3
00169     *(volatile uint32_t *)(0x41003098) = 0x00000002;  //D7
00170 
00171    
00172     //ledTick.attach(&ledTickfunc,2);
00173    /* UI Button setup */
00174     K_VU.fall(&Volume_Up);
00175 //    K_VU.mode(PullUp);
00176     K_VD.fall(&Volume_Down);
00177 //    K_VD.mode(PullUp);
00178     K_ONOFF.fall(&Play_Pressed);
00179  //   K_ONOFF.mode(PullUp);
00180     K_FW.fall(&Song_Forward);
00181  //   K_FW.mode(PullUp);
00182     K_BW.fall(&Song_Backward);
00183  //   K_BW.mode(PullUp);
00184     
00185    
00186     while(1)
00187     {
00188 /*        
00189         update_count_ms++;
00190         if(update_count_ms>5000)
00191         {
00192             printf("update_count_ms count : %d\r\n", update_count_s);
00193             update_count_ms=0;
00194             update_count_s++;
00195         }
00196         //printf("ftp_time_1s:%d\r\n", ftp_time_1s);
00197         //if(ftp_time_1s == 0)
00198         if(update_count_s>=5)
00199         {
00200             //Configure the display driver
00201             update_count_s = 0;
00202             
00203             printf(" UPDATING MP3\r\n");
00204             printf("==================\n\r\n");
00205         
00206             if(myFTP.open("192.168.0.10", 21, "user", "pass"))
00207             {
00208                 printf("Connect Success to FTPServer\r\n");
00209                 printf("Connected to FTP Server\r\n");
00210                 
00211                 myFTP.getfile("1.mp3");
00212                 myFTP.getfile("2.mp3");
00213                 myFTP.getfile("3.mp3");
00214            
00215                 printf("\n UPDATE DONE\n\r\n");
00216                 myFTP.quit();
00217             }
00218             else
00219             {
00220                 printf(" Can't connect to FTP Server\r\n");
00221                 printf(" UPDATE FAIL\r\n");
00222             }
00223             printf("==================\n");
00224         }
00225 */
00226         
00227         /*============================================================ 
00228          * MP3 Initialising 
00229          *==========================================================*/
00230 
00231         mp3._RST = 1; 
00232         mp3.cs_high();                                  //chip disabled 
00233         mp3.sci_initialise();                           //initialise MBED
00234         mp3.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF)); 
00235         mp3.sci_write(0x03, 0x9800); 
00236         mp3.sdi_initialise();
00237 
00238         ain_temp = ain.read_u16();
00239         //printf("normalized: %d \n\r", ain_temp);
00240         
00241 //        if (pause)
00242 //        {
00243             printf("enter song\r\n");
00244             printf("song number: %d\r\n", new_song_number);
00245             mp3.play_song(new_song_number);
00246 //        }
00247     }    
00248 }