sd_i2s+sd_vs_v3

This commit is contained in:
e2002
2022-12-16 12:43:53 +03:00
parent db34be117f
commit a2ba963027
8 changed files with 43 additions and 23 deletions

View File

@@ -14,6 +14,7 @@
#include "mp3_decoder/mp3_decoder.h" #include "mp3_decoder/mp3_decoder.h"
#include "aac_decoder/aac_decoder.h" #include "aac_decoder/aac_decoder.h"
#include "flac_decoder/flac_decoder.h" #include "flac_decoder/flac_decoder.h"
#include "../core/config.h"
#ifdef SDFATFS_USED #ifdef SDFATFS_USED
fs::SDFATFS SD_SDFAT; fs::SDFATFS SD_SDFAT;
@@ -311,11 +312,13 @@ void Audio::setDefaults() {
vector_clear_and_shrink(m_playlistURL); vector_clear_and_shrink(m_playlistURL);
vector_clear_and_shrink(m_playlistContent); vector_clear_and_shrink(m_playlistContent);
m_hashQueue.clear(); m_hashQueue.shrink_to_fit(); // uint32_t vector m_hashQueue.clear(); m_hashQueue.shrink_to_fit(); // uint32_t vector
if(config.store.play_mode!=PM_SDCARD){
client.stop(); client.stop();
client.flush(); // release memory client.flush(); // release memory
clientsecure.stop(); clientsecure.stop();
clientsecure.flush(); clientsecure.flush();
_client = static_cast<WiFiClient*>(&client); /* default to *something* so that no NULL deref can happen */ _client = static_cast<WiFiClient*>(&client); /* default to *something* so that no NULL deref can happen */
}
playI2Sremains(); playI2Sremains();
AUDIO_INFO("buffers freed, free Heap: %u bytes", ESP.getFreeHeap()); AUDIO_INFO("buffers freed, free Heap: %u bytes", ESP.getFreeHeap());

View File

@@ -10,6 +10,7 @@
#ifndef VS_PATCH_ENABLE #ifndef VS_PATCH_ENABLE
#define VS_PATCH_ENABLE true #define VS_PATCH_ENABLE true
#endif #endif
#include "../core/config.h"
#include "audioVS1053Ex.h" #include "audioVS1053Ex.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@@ -569,10 +570,11 @@ void Audio::showstreamtitle(const char* ml) {
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void Audio::cardLock(bool lock){ void Audio::cardLock(bool lock){
#if (TFT_CS!=255) || (SDC_CS!=255) #if (SDC_CS!=255)
if(lock){ if(lock){
xSemaphoreTake(mutex_pl, portMAX_DELAY); xSemaphoreTake(mutex_pl, portMAX_DELAY);
}else{ }else{
// digitalWrite(SDC_CS, HIGH);
xSemaphoreGive(mutex_pl); xSemaphoreGive(mutex_pl);
} }
#endif #endif
@@ -908,7 +910,6 @@ void Audio::processWebStream(){
InBuff.bytesWasRead(bytesDecoded); InBuff.bytesWasRead(bytesDecoded);
} }
stopSong(); // Correct close when play known length sound #74 and before callback #112 stopSong(); // Correct close when play known length sound #74 and before callback #112
if(m_f_tts){ if(m_f_tts){
sprintf(chbuf, "End of speech: \"%s\"", m_lastHost); sprintf(chbuf, "End of speech: \"%s\"", m_lastHost);
if(audio_info) audio_info(chbuf); if(audio_info) audio_info(chbuf);
@@ -1592,11 +1593,13 @@ void Audio::setDefaults(){
InBuff.resetBuffer(); InBuff.resetBuffer();
vector_clear_and_shrink(m_playlistURL); vector_clear_and_shrink(m_playlistURL);
vector_clear_and_shrink(m_playlistContent); vector_clear_and_shrink(m_playlistContent);
if(config.store.play_mode!=PM_SDCARD){
client.stop(); client.stop();
client.flush(); // release memory client.flush(); // release memory
clientsecure.stop(); clientsecure.stop();
clientsecure.flush(); clientsecure.flush();
_client = static_cast<WiFiClient*>(&client); /* default to *something* so that no NULL deref can happen */ _client = static_cast<WiFiClient*>(&client); /* default to *something* so that no NULL deref can happen */
}
m_f_ctseen=false; // Contents type not seen yet m_f_ctseen=false; // Contents type not seen yet
m_metaint=0; // No metaint yet m_metaint=0; // No metaint yet
m_LFcount=0; // For detection end of header m_LFcount=0; // For detection end of header
@@ -1908,23 +1911,24 @@ bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) {
sprintf(chbuf, "Reading file: \"%s\"", audioName); sprintf(chbuf, "Reading file: \"%s\"", audioName);
if(audio_info) {vTaskDelay(2); audio_info(chbuf);} if(audio_info) {vTaskDelay(2); audio_info(chbuf);}
if(audio_beginSDread) audio_beginSDread(); if(audio_beginSDread) audio_beginSDread();
cardLock(true); audiofile.close(); cardLock(false); cardLock(true);
audiofile.close();
if(fs.exists(audioName)) { if(fs.exists(audioName)) {
cardLock(true); audiofile = fs.open(audioName); cardLock(false); audiofile = fs.open(audioName);
} else { } else {
UTF8toASCII(audioName); UTF8toASCII(audioName);
if(fs.exists(audioName)) { if(fs.exists(audioName)) {
cardLock(true); audiofile = fs.open(audioName); cardLock(false); audiofile = fs.open(audioName);
} }
} }
if(!audiofile) { if(!audiofile) {
if(audio_info) {vTaskDelay(2); audio_info("Failed to open file for reading");} if(audio_info) {vTaskDelay(2); audio_info("Failed to open file for reading");}
cardLock(false);
return false; return false;
} }
m_f_localfile = true; m_f_localfile = true;
cardLock(true);
m_file_size = audiofile.size();//TEST loop m_file_size = audiofile.size();//TEST loop
char* afn = strdup(audiofile.name()); // audioFileName char* afn = strdup(audiofile.name()); // audioFileName

View File

@@ -6,7 +6,7 @@
Config config; Config config;
#if DSP_HSPI || TS_HSPI || VS_HSPI #if DSP_HSPI || TS_HSPI || VS_HSPI || SD_HSPI
SPIClass SPI2(HSPI); SPIClass SPI2(HSPI);
#endif #endif
//SPIClass SDSPI(VSPI); //SPIClass SDSPI(VSPI);
@@ -296,6 +296,13 @@ bool endsWith (const char* base, const char* str) {
return (strncmp(p, str, slen) == 0); return (strncmp(p, str, slen) == 0);
} }
bool Config::checkNoMedia(const char* path){
char nomedia[BUFLEN]= {0};
strlcat(nomedia, path, BUFLEN);
strlcat(nomedia, "/.nomedia", BUFLEN);
return SD.exists(nomedia);
}
void Config::listSD(File &plSDfile, File &plSDindex, const char * dirname, uint8_t levels){ void Config::listSD(File &plSDfile, File &plSDindex, const char * dirname, uint8_t levels){
File root = SD.open(dirname); File root = SD.open(dirname);
if(!root){ if(!root){
@@ -313,7 +320,7 @@ void Config::listSD(File &plSDfile, File &plSDindex, const char * dirname, uint8
while(file){ while(file){
if(file.isDirectory()){ if(file.isDirectory()){
if(levels){ if(levels && !checkNoMedia(file.path())){
listSD(plSDfile, plSDindex, file.path(), levels -1); listSD(plSDfile, plSDindex, file.path(), levels -1);
} }
} else { } else {

View File

@@ -33,6 +33,7 @@
#define REAL_INDEX store.play_mode==PM_WEB?INDEX_PATH:INDEX_SD_PATH #define REAL_INDEX store.play_mode==PM_WEB?INDEX_PATH:INDEX_SD_PATH
#define MAX_PLAY_MODE 1 #define MAX_PLAY_MODE 1
enum playMode_e : uint8_t { PM_WEB=0, PM_SDCARD=1 };
void u8fix(char *src); void u8fix(char *src);
@@ -179,9 +180,6 @@ class Config {
void setSmartStart(byte ss); void setSmartStart(byte ss);
void initPlaylist(); void initPlaylist();
void indexPlaylist(); void indexPlaylist();
void listSD(File &plSDfile, File &plSDindex, const char * dirname, uint8_t levels);
void initSDPlaylist();
void indexSDPlaylist();
void fillPlMenu(char plmenu[][40], int from, byte count, bool removeNum = false); void fillPlMenu(char plmenu[][40], int from, byte count, bool removeNum = false);
void setTimezone(int8_t tzh, int8_t tzm); void setTimezone(int8_t tzh, int8_t tzm);
void setTimezoneOffset(uint16_t tzo); void setTimezoneOffset(uint16_t tzo);
@@ -198,6 +196,10 @@ class Config {
Ticker _sleepTimer; Ticker _sleepTimer;
static void doSleep(); static void doSleep();
uint16_t color565(uint8_t r, uint8_t g, uint8_t b); uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
void listSD(File &plSDfile, File &plSDindex, const char * dirname, uint8_t levels);
void initSDPlaylist();
void indexSDPlaylist();
bool checkNoMedia(const char* path);
}; };
extern Config config; extern Config config;

View File

@@ -499,6 +499,7 @@ void onBtnClick(int id) {
break; break;
} }
case EVT_BTNMODE: { case EVT_BTNMODE: {
if(SDC_CS==255) break;
config.store.play_mode++; config.store.play_mode++;
if(config.store.play_mode > MAX_PLAY_MODE){ if(config.store.play_mode > MAX_PLAY_MODE){
config.store.play_mode=0; config.store.play_mode=0;

View File

@@ -484,6 +484,7 @@ void NetServer::getPlaylist(uint8_t clientId) {
} }
bool NetServer::importPlaylist() { bool NetServer::importPlaylist() {
if(config.store.play_mode==PM_SDCARD) return false;
File tempfile = SPIFFS.open(TMP_PATH, "r"); File tempfile = SPIFFS.open(TMP_PATH, "r");
if (!tempfile) { if (!tempfile) {
return false; return false;

View File

@@ -1,7 +1,7 @@
#ifndef options_h #ifndef options_h
#define options_h #define options_h
#define YOVERSION "0.8.800" #define YOVERSION "0.8.813"
/******************************************************* /*******************************************************
DO NOT EDIT THIS FILE. DO NOT EDIT THIS FILE.
@@ -121,6 +121,9 @@ The connection tables are located here https://github.com/e2002/yoradio#connecti
#ifndef SDC_CS #ifndef SDC_CS
#define SDC_CS 255 // SDCARD CS pin #define SDC_CS 255 // SDCARD CS pin
#endif #endif
#ifndef SD_HSPI
#define SD_HSPI false // use HSPI for SD (miso=12, mosi=13, clk=14) instead of VSPI (by default)
#endif
/* ENCODER */ /* ENCODER */
#ifndef ENC_BTNL #ifndef ENC_BTNL

View File

@@ -9,7 +9,6 @@
#endif #endif
enum audioMode_e { PLAYING, STOPPED }; enum audioMode_e { PLAYING, STOPPED };
enum playMode_e : uint8_t { PM_WEB=0, PM_SDCARD=1 };
struct audiorequest_t struct audiorequest_t
{ {