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 |
ESP32_A1S.ino (4311B)
1 // found this sketch on https://www.mikrocontroller.net/topic/474383 2 // thanks to Michael U. (amiga) 3 4 #include "Arduino.h" 5 #include "WiFi.h" 6 #include "SPI.h" 7 #include "SD.h" 8 #include "FS.h" 9 #include "Wire.h" 10 #include "AC101.h" //https://github.com/schreibfaul1/AC101 11 // #include "ES8388.h" // https://github.com/maditnerd/es8388 12 #include "Audio.h" //https://github.com/schreibfaul1/ESP32-audioI2S 13 14 15 // SPI GPIOs 16 #define SD_CS 13 17 #define SPI_MOSI 15 18 #define SPI_MISO 2 19 #define SPI_SCK 14 20 21 // I2S GPIOs, the names refer on AC101, AS1 Audio Kit V2.2 2379 22 #define I2S_DSIN 25 23 #define I2S_BCLK 27 24 #define I2S_LRC 26 25 #define I2S_MCLK 0 26 #define I2S_DOUT 35 27 28 // I2S GPIOs, the names refer on ES8388, AS1 Audio Kit V2.2 3378 29 //#define I2S_DSIN 35 30 //#define I2S_BCLK 27 31 //#define I2S_LRC 25 32 //#define I2S_MCLK 0 33 //#define I2S_DOUT 26 34 35 // I2C GPIOs 36 #define IIC_CLK 32 37 #define IIC_DATA 33 38 39 // buttons 40 // #define BUTTON_2_PIN 13 // shared mit SPI_CS 41 #define BUTTON_3_PIN 19 42 #define BUTTON_4_PIN 23 43 #define BUTTON_5_PIN 18 // Stop 44 #define BUTTON_6_PIN 5 // Play 45 46 // amplifier enable 47 #define GPIO_PA_EN 21 48 49 //Switch S1: 1-OFF, 2-ON, 3-ON, 4-OFF, 5-OFF 50 51 String ssid = "xxxxxxxxx"; 52 String password = "xxxxxxxxx"; 53 54 static AC101 dac; // AC101 55 // ES8388 dac; // ES8388 (new board) 56 int volume = 40; // 0...100 57 58 Audio audio; 59 60 //##################################################################### 61 62 void setup() 63 { 64 Serial.begin(115200); 65 Serial.println("\r\nReset"); 66 Serial.printf_P(PSTR("Free mem=%d\n"), ESP.getFreeHeap()); 67 68 pinMode(SD_CS, OUTPUT); 69 digitalWrite(SD_CS, HIGH); 70 SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI); 71 SPI.setFrequency(1000000); 72 73 SD.begin(SD_CS); 74 75 WiFi.mode(WIFI_STA); 76 WiFi.begin(ssid.c_str(), password.c_str()); 77 78 while (WiFi.status() != WL_CONNECTED) 79 { 80 Serial.print("."); 81 delay(100); 82 } 83 84 Serial.printf_P(PSTR("Connected\r\nRSSI: ")); 85 Serial.print(WiFi.RSSI()); 86 Serial.print(" IP: "); 87 Serial.println(WiFi.localIP()); 88 89 Serial.printf("Connect to DAC codec... "); 90 while (not dac.begin(IIC_DATA, IIC_CLK)) 91 { 92 Serial.printf("Failed!\n"); 93 delay(1000); 94 } 95 Serial.printf("OK\n"); 96 97 dac.SetVolumeSpeaker(volume); 98 dac.SetVolumeHeadphone(volume); 99 // ac.DumpRegisters(); 100 101 // Enable amplifier 102 pinMode(GPIO_PA_EN, OUTPUT); 103 digitalWrite(GPIO_PA_EN, HIGH); 104 105 // set I2S_MasterClock 106 audio.i2s_mclk_pin_select(I2S_MCLK); 107 108 audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DSIN); 109 audio.setVolume(10); // 0...21 110 111 audio.connecttoFS(SD, "/320k_test.mp3"); 112 // audio.connecttoSD("/Banana Boat Song - Harry Belafonte.mp3"); 113 // audio.connecttohost("http://mp3channels.webradio.antenne.de:80/oldies-but-goldies"); 114 // audio.connecttohost("http://dg-rbb-http-dus-dtag-cdn.cast.addradio.de/rbb/antennebrandenburg/live/mp3/128/stream.mp3"); 115 // audio.connecttospeech("Wenn die Hunde schlafen, kann der Wolf gut Schafe stehlen.", "de"); 116 117 } 118 119 //----------------------------------------------------------------------- 120 121 void loop() 122 { 123 audio.loop(); 124 } 125 126 // optional 127 void audio_info(const char *info){ 128 Serial.print("info "); Serial.println(info); 129 } 130 void audio_id3data(const char *info){ //id3 metadata 131 Serial.print("id3data ");Serial.println(info); 132 } 133 void audio_eof_mp3(const char *info){ //end of file 134 Serial.print("eof_mp3 ");Serial.println(info); 135 } 136 void audio_showstation(const char *info){ 137 Serial.print("station ");Serial.println(info); 138 } 139 void audio_showstreamtitle(const char *info){ 140 Serial.print("streamtitle ");Serial.println(info); 141 } 142 void audio_bitrate(const char *info){ 143 Serial.print("bitrate ");Serial.println(info); 144 } 145 void audio_commercial(const char *info){ //duration in sec 146 Serial.print("commercial ");Serial.println(info); 147 } 148 void audio_icyurl(const char *info){ //homepage 149 Serial.print("icyurl ");Serial.println(info); 150 } 151 void audio_lasthost(const char *info){ //stream URL played 152 Serial.print("lasthost ");Serial.println(info); 153 } 154 void audio_eof_speech(const char *info){ 155 Serial.print("eof_speech ");Serial.println(info); 156 }