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_ES8388.ino (3752B)
1 // the pin assignment matches the Olimex ADF board 2 3 #include "Arduino.h" 4 #include "WiFi.h" 5 #include "SPI.h" 6 #include "SD.h" 7 #include "FS.h" 8 #include "Wire.h" 9 #include "ES8388.h" // https://github.com/maditnerd/es8388 10 #include "Audio.h" // https://github.com/schreibfaul1/ESP32-audioI2S 11 12 13 #define SD_CS 21 14 15 // GPIOs for SPI 16 #define SPI_MOSI 13 17 #define SPI_MISO 12 18 #define SPI_SCK 14 19 20 // I2S GPIOs 21 #define I2S_SDOUT 26 22 #define I2S_BCLK 5 23 #define I2S_LRCK 25 24 #define I2S_MCLK 0 25 26 // I2C GPIOs 27 #define IIC_CLK 23 28 #define IIC_DATA 18 29 30 // Amplifier enable 31 #define GPIO_PA_EN 19 32 33 char ssid[] = "xxxxxxxxx"; 34 char password[] = "xxxxxxxxx"; 35 36 37 int volume = 80; // 0...100 38 39 ES8388 es; 40 Audio audio; 41 42 //---------------------------------------------------------------------------------------------------------------------- 43 44 void setup() 45 { 46 Serial.begin(115200); 47 Serial.println("\r\nReset"); 48 Serial.printf_P(PSTR("Free mem=%d\n"), ESP.getFreeHeap()); 49 50 SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI); 51 SPI.setFrequency(1000000); 52 53 SD.begin(SD_CS); 54 55 WiFi.mode(WIFI_STA); 56 WiFi.begin(ssid, password); 57 58 while(WiFi.status() != WL_CONNECTED) { 59 Serial.print("."); 60 delay(100); 61 } 62 63 Serial.printf_P(PSTR("Connected\r\nRSSI: ")); 64 Serial.print(WiFi.RSSI()); 65 Serial.print(" IP: "); 66 Serial.println(WiFi.localIP()); 67 68 Serial.printf("Connect to ES8388 codec... "); 69 while (not es.begin(IIC_DATA, IIC_CLK)) 70 { 71 Serial.printf("Failed!\n"); 72 delay(1000); 73 } 74 Serial.printf("OK\n"); 75 76 es.volume(ES8388::ES_MAIN, volume); 77 es.volume(ES8388::ES_OUT1, volume); 78 es.volume(ES8388::ES_OUT2, volume); 79 es.mute(ES8388::ES_OUT1, false); 80 es.mute(ES8388::ES_OUT2, false); 81 es.mute(ES8388::ES_MAIN, false); 82 83 // Enable amplifier 84 pinMode(GPIO_PA_EN, OUTPUT); 85 digitalWrite(GPIO_PA_EN, HIGH); 86 87 audio.setPinout(I2S_BCLK, I2S_LRCK, I2S_SDOUT); 88 audio.i2s_mclk_pin_select(I2S_MCLK); 89 audio.setVolume(21); // 0...21 90 91 audio.connecttohost("http://mp3channels.webradio.antenne.de:80/oldies-but-goldies"); 92 // audio.connecttoFS(SD, "320k_test.mp3"); 93 // audio.connecttospeech("Wenn die Hunde schlafen, kann der Wolf gut Schafe stehlen.", "de"); 94 } 95 //---------------------------------------------------------------------------------------------------------------------- 96 void loop() 97 { 98 audio.loop(); 99 } 100 //---------------------------------------------------------------------------------------------------------------------- 101 102 // optional 103 void audio_info(const char *info){ 104 Serial.print("info "); Serial.println(info); 105 } 106 void audio_id3data(const char *info){ //id3 metadata 107 Serial.print("id3data ");Serial.println(info); 108 } 109 void audio_eof_mp3(const char *info){ //end of file 110 Serial.print("eof_mp3 ");Serial.println(info); 111 } 112 void audio_showstation(const char *info){ 113 Serial.print("station ");Serial.println(info); 114 } 115 void audio_showstreaminfo(const char *info){ 116 Serial.print("streaminfo ");Serial.println(info); 117 } 118 void audio_showstreamtitle(const char *info){ 119 Serial.print("streamtitle ");Serial.println(info); 120 } 121 void audio_bitrate(const char *info){ 122 Serial.print("bitrate ");Serial.println(info); 123 } 124 void audio_commercial(const char *info){ //duration in sec 125 Serial.print("commercial ");Serial.println(info); 126 } 127 void audio_icyurl(const char *info){ //homepage 128 Serial.print("icyurl ");Serial.println(info); 129 } 130 void audio_lasthost(const char *info){ //stream URL played 131 Serial.print("lasthost ");Serial.println(info); 132 } 133 void audio_eof_speech(const char *info){ 134 Serial.print("eof_speech ");Serial.println(info); 135 } 136 137