acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

M5Core2.ino (3496B)

      1 //**********************************************************************************************************
      2 //*    audioI2S-- I2S audiodecoder for M5Stack Core2                                                       *
      3 //**********************************************************************************************************
      4 //
      5 // first release on May.12/2021
      6 //
      7 //
      8 // THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT.
      9 // FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
     10 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR
     11 // OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     12 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
     13 //
     14 
     15 #include <M5Core2.h>
     16 #include "Audio.h"
     17 
     18 // Digital I/O used
     19 #define SD_CS          4
     20 #define SD_MOSI       23
     21 #define SD_MISO       38
     22 #define SD_SCK        18
     23 #define I2S_DOUT       2
     24 #define I2S_BCLK      12
     25 #define I2S_LRC        0
     26 
     27 Audio audio;
     28 String ssid =     "xxxxxx";
     29 String password = "xxxxxx";
     30 
     31 
     32 void setup() {
     33   M5.begin(true, true, true, true);
     34   M5.Axp.SetSpkEnable(true);
     35   M5.Lcd.fillScreen(BLACK);
     36   M5.Lcd.setTextColor(WHITE);
     37   M5.Lcd.setTextSize(2);
     38     
     39   pinMode(SD_CS, OUTPUT);
     40   digitalWrite(SD_CS, HIGH);
     41   SPI.begin(SD_SCK, SD_MISO, SD_MOSI);
     42   SPI.setFrequency(1000000);
     43   SD.begin(SD_CS);
     44 
     45   audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
     46   audio.setVolume(15); // 0...21
     47   
     48   WiFi.mode(WIFI_STA);
     49   WiFi.begin(ssid.c_str(), password.c_str());
     50   while (!WiFi.isConnected()) {
     51     delay(10);
     52   }
     53   ESP_LOGI(TAG, "Connected");
     54   ESP_LOGI(TAG, "Starting MP3...\n");
     55 
     56 //  audio.connecttoFS(SD, "/320k_test.mp3");
     57 //  audio.connecttoFS(SD, "test.wav");
     58   audio.connecttohost("http://air.ofr.fm:8008/jazz/mp3/128");
     59 //  audio.connecttospeech("Миска вареників з картоплею та шкварками, змащених салом!", "uk-UA");
     60 }
     61 
     62 void loop() {
     63     audio.loop();
     64     if(Serial.available()){ // put streamURL in serial monitor
     65         audio.stopSong();
     66         String r=Serial.readString(); 
     67         r.trim();
     68         if(r.length()>5) audio.connecttohost(r.c_str());
     69         log_i("free heap=%i", ESP.getFreeHeap());
     70     }
     71 }
     72 
     73 // optional
     74 void audio_info(const char *info){
     75     Serial.print("info        "); Serial.println(info);
     76 }
     77 void audio_id3data(const char *info){  //id3 metadata
     78     Serial.print("id3data     ");Serial.println(info);
     79 }
     80 void audio_eof_mp3(const char *info){  //end of file
     81     Serial.print("eof_mp3     ");Serial.println(info);
     82 }
     83 void audio_showstation(const char *info){
     84     Serial.print("station     ");Serial.println(info);
     85 }
     86 void audio_showstreamtitle(const char *info){
     87     Serial.print("streamtitle ");Serial.println(info);
     88 }
     89 void audio_bitrate(const char *info){
     90     Serial.print("bitrate     ");Serial.println(info);
     91 }
     92 void audio_commercial(const char *info){  //duration in sec
     93     Serial.print("commercial  ");Serial.println(info);
     94 }
     95 void audio_icyurl(const char *info){  //homepage
     96     Serial.print("icyurl      ");Serial.println(info);
     97 }
     98 void audio_lasthost(const char *info){  //stream URL played
     99     Serial.print("lasthost    ");Serial.println(info);
    100 }
    101 void audio_eof_speech(const char *info){
    102     Serial.print("eof_speech  ");Serial.println(info);
    103 }