diff --git a/components/_override/CMakeLists.txt b/components/_override/CMakeLists.txt index ffd2b067..7de1484f 100644 --- a/components/_override/CMakeLists.txt +++ b/components/_override/CMakeLists.txt @@ -3,4 +3,5 @@ idf_component_register( SRCS ${srcs} INCLUDE_DIRS ${IDF_PATH}/components/driver ) -message("overriding ${srcs} !! THIS MUST BE REQUIRED BY MAIN !!") \ No newline at end of file +# CMake is just a pile of crap +message("overriding ${srcs} !! THIS MUST BE REQUIRED BY ONE COMPONENT BUT NO MAIN !!") \ No newline at end of file diff --git a/components/_override/spi_master.c b/components/_override/spi_master.c index 50d3550e..9e7a109a 100644 --- a/components/_override/spi_master.c +++ b/components/_override/spi_master.c @@ -125,6 +125,7 @@ We have two bits to control the interrupt: #include "esp_log.h" #include "freertos/task.h" #include "freertos/queue.h" +#include "freertos/semphr.h" #include "soc/soc_memory_layout.h" #include "driver/gpio.h" #include "hal/spi_hal.h" @@ -158,6 +159,10 @@ typedef struct { //debug information bool polling; //in process of a polling, avoid of queue new transactions into ISR + +// PATCH + SemaphoreHandle_t mutex; + int count; } spi_host_t; struct spi_device_t { @@ -391,6 +396,12 @@ esp_err_t spi_bus_add_device(spi_host_device_t host_id, const spi_device_interfa if (dev_config->spics_io_num >= 0) { spicommon_cs_initialize(host_id, dev_config->spics_io_num, freecs, use_gpio); } + + // create a mutex if we have more than one client + if (host->count++) { + ESP_LOGI(SPI_TAG, "More than one device on SPI %d => creating mutex", host_id); + host->mutex = xSemaphoreCreateMutex(); + } //save a pointer to device in spi_host_t host->device[freecs] = dev; @@ -982,17 +993,15 @@ esp_err_t SPI_MASTER_ISR_ATTR spi_device_polling_end(spi_device_handle_t handle, esp_err_t SPI_MASTER_ISR_ATTR spi_device_polling_transmit(spi_device_handle_t handle, spi_transaction_t* trans_desc) { esp_err_t ret; - static SemaphoreHandle_t mutex; - if (!mutex) mutex = xSemaphoreCreateMutex(); - xSemaphoreTake(mutex, portMAX_DELAY); +if (handle->host->mutex) xSemaphoreTake(handle->host->mutex, portMAX_DELAY); ret = spi_device_polling_start(handle, trans_desc, portMAX_DELAY); if (ret != ESP_OK) { - xSemaphoreGive(mutex); + if (handle->host->mutex) xSemaphoreGive(handle->host->mutex); return ret; } ret = spi_device_polling_end(handle, portMAX_DELAY); - xSemaphoreGive(mutex); + if (handle->host->mutex) xSemaphoreGive(handle->host->mutex); return ret; } diff --git a/components/services/CMakeLists.txt b/components/services/CMakeLists.txt index cccd0f86..6cce2c49 100644 --- a/components/services/CMakeLists.txt +++ b/components/services/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register(SRC_DIRS . - INCLUDE_DIRS . ${IDF_PATH}/components/driver + INCLUDE_DIRS . REQUIRES json tools platform_config display wifi-manager PRIV_REQUIRES soc esp32 ) diff --git a/components/spotify/cspot/bell/nanopb/extra/FindNanopb.cmake b/components/spotify/cspot/bell/nanopb/extra/FindNanopb.cmake index 798120b5..3f82b7b8 100644 --- a/components/spotify/cspot/bell/nanopb/extra/FindNanopb.cmake +++ b/components/spotify/cspot/bell/nanopb/extra/FindNanopb.cmake @@ -262,8 +262,7 @@ function(NANOPB_GENERATE_CPP SRCS HDRS) execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --version OUTPUT_VARIABLE PROTOC_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE) string(REGEX MATCH "[(0-9)].*.[(0-9)].*.[(0-9)].*$" PROTOC_VERSION "${PROTOC_VERSION_STRING}") - #if(PROTOC_VERSION VERSION_LESS "3.6.0") - if(0) + if(PROTOC_VERSION AND PROTOC_VERSION VERSION_LESS "3.6.0") #try to use the older way string(REGEX MATCH ":" HAS_COLON_IN_PATH ${NANOPB_PLUGIN_OPTIONS} ${NANOPB_OUT}) if(HAS_COLON_IN_PATH) diff --git a/components/spotify/cspot/protobuf/metadata.options b/components/spotify/cspot/protobuf/metadata.options index be207b4e..7504a906 100644 --- a/components/spotify/cspot/protobuf/metadata.options +++ b/components/spotify/cspot/protobuf/metadata.options @@ -13,5 +13,6 @@ Episode.gid type:FT_POINTER Episode.name type:FT_POINTER ImageGroup.image type:FT_POINTER Episode.audio type:FT_POINTER +Episode.covers type:FT_POINTER Restriction.countries_allowed type:FT_POINTER Restriction.countries_forbidden type:FT_POINTER \ No newline at end of file diff --git a/components/spotify/cspot/protobuf/metadata.proto b/components/spotify/cspot/protobuf/metadata.proto index ebe382ab..2e5ae222 100644 --- a/components/spotify/cspot/protobuf/metadata.proto +++ b/components/spotify/cspot/protobuf/metadata.proto @@ -45,6 +45,7 @@ message Episode { optional string name = 2; optional sint32 duration = 7; repeated AudioFile audio = 12; + optional ImageGroup covers = 0x44; } enum AudioFormat { diff --git a/components/spotify/cspot/src/AudioChunkManager.cpp b/components/spotify/cspot/src/AudioChunkManager.cpp index f2cdcf8e..5b263c02 100644 --- a/components/spotify/cspot/src/AudioChunkManager.cpp +++ b/components/spotify/cspot/src/AudioChunkManager.cpp @@ -3,7 +3,7 @@ #include "Logger.h" AudioChunkManager::AudioChunkManager() - : bell::Task("AudioChunkManager", 4 * 1024, +0, 0) { + : bell::Task("AudioChunkManager", 4 * 1024, +1, 0) { this->chunks = std::vector>(); startTask(); } @@ -96,11 +96,7 @@ void AudioChunkManager::runTask() { break; default: - // printf("ID: %d: Got data chunk!\n", seqId); - // 2 first bytes are size so we skip it - // printf("(_)--- Free memory %d\n", - // esp_get_free_heap_size()); - if (chunk == nullptr) { + if (chunk.get() == nullptr) { return; } auto actualData = std::vector( @@ -114,7 +110,7 @@ void AudioChunkManager::runTask() { } catch (...) { } } else { -// usleep(100*1000); + usleep(100); } } diff --git a/components/spotify/cspot/src/MercuryManager.cpp b/components/spotify/cspot/src/MercuryManager.cpp index 1eecdaaa..0564ded2 100644 --- a/components/spotify/cspot/src/MercuryManager.cpp +++ b/components/spotify/cspot/src/MercuryManager.cpp @@ -30,7 +30,7 @@ MercuryManager::MercuryManager(std::unique_ptr session): bell::Task("me MercuryManager::~MercuryManager() { - pbFree(Header_fields, &tempMercuryHeader); + pb_release(Header_fields, tempMercuryHeader); } bool MercuryManager::timeoutHandler() diff --git a/components/spotify/cspot/src/MercuryResponse.cpp b/components/spotify/cspot/src/MercuryResponse.cpp index 6ff7c51f..1bda5d4e 100644 --- a/components/spotify/cspot/src/MercuryResponse.cpp +++ b/components/spotify/cspot/src/MercuryResponse.cpp @@ -9,7 +9,7 @@ MercuryResponse::MercuryResponse(std::vector &data) } MercuryResponse::~MercuryResponse() { - pbFree(Header_fields, &mercuryHeader); + pb_release(Header_fields, mercuryHeader); } void MercuryResponse::parseResponse(std::vector &data) diff --git a/components/spotify/cspot/src/PlayerState.cpp b/components/spotify/cspot/src/PlayerState.cpp index b6c1c34e..00bc889e 100644 --- a/components/spotify/cspot/src/PlayerState.cpp +++ b/components/spotify/cspot/src/PlayerState.cpp @@ -53,8 +53,8 @@ PlayerState::PlayerState(std::shared_ptr timeProvider) } PlayerState::~PlayerState() { - pbFree(Frame_fields, &innerFrame); - pbFree(Frame_fields, &remoteFrame); + pb_release(Frame_fields, innerFrame); + pb_release(Frame_fields, remoteFrame); } void PlayerState::setPlaybackState(const PlaybackState state) diff --git a/components/spotify/cspot/src/Session.cpp b/components/spotify/cspot/src/Session.cpp index 8c84de10..33879c7a 100644 --- a/components/spotify/cspot/src/Session.cpp +++ b/components/spotify/cspot/src/Session.cpp @@ -18,10 +18,10 @@ Session::Session() Session::~Session() { - pbFree(ClientHello_fields, &clientHello); - pbFree(APResponseMessage_fields, &apResponse); - pbFree(ClientResponseEncrypted_fields, &authRequest); - pbFree(ClientResponsePlaintext_fields, &clientResPlaintext); + pb_release(ClientHello_fields, clientHello); + pb_release(APResponseMessage_fields, apResponse); + pb_release(ClientResponseEncrypted_fields, authRequest); + pb_release(ClientResponsePlaintext_fields, clientResPlaintext); } void Session::connect(std::unique_ptr connection) diff --git a/components/spotify/cspot/src/SpotifyTrack.cpp b/components/spotify/cspot/src/SpotifyTrack.cpp index a07796d6..381ff256 100644 --- a/components/spotify/cspot/src/SpotifyTrack.cpp +++ b/components/spotify/cspot/src/SpotifyTrack.cpp @@ -35,8 +35,8 @@ SpotifyTrack::~SpotifyTrack() { this->manager->unregisterMercuryCallback(this->reqSeqNum); this->manager->freeAudioKeyCallback(); - pbFree(Track_fields, &this->trackInfo); - pbFree(Episode_fields, &this->episodeInfo); + pb_release(Track_fields, this->trackInfo); + pb_release(Episode_fields, this->episodeInfo); } bool SpotifyTrack::countryListContains(std::string countryList, std::string country) @@ -142,6 +142,21 @@ void SpotifyTrack::episodeInformationCallback(std::unique_ptr r } } + if (trackInfoReceived != nullptr) + { + auto imageId = pbArrayToVector(episodeInfo.covers->image[0].file_id); + TrackInfo simpleTrackInfo = { + .name = std::string(episodeInfo.name), + .album = "", + .artist = "", + .imageUrl = "https://i.scdn.co/image/" + bytesToHexString(imageId), + .duration = trackInfo.duration, + + }; + + trackInfoReceived(simpleTrackInfo); + } + this->requestAudioKey(pbArrayToVector(episodeInfo.gid), this->fileId, episodeInfo.duration, position_ms, isPaused); } diff --git a/components/spotify/cspot/src/TrackReference.cpp b/components/spotify/cspot/src/TrackReference.cpp index f9376d0f..72eb28e3 100644 --- a/components/spotify/cspot/src/TrackReference.cpp +++ b/components/spotify/cspot/src/TrackReference.cpp @@ -19,7 +19,7 @@ TrackReference::TrackReference(TrackRef *ref) TrackReference::~TrackReference() { - //pbFree(TrackRef_fields, &ref); + pb_release(TrackRef_fields, ref); } std::vector TrackReference::base62Decode(std::string uri) diff --git a/components/tools/CMakeLists.txt b/components/tools/CMakeLists.txt index 6f51e1c0..6a36b20f 100644 --- a/components/tools/CMakeLists.txt +++ b/components/tools/CMakeLists.txt @@ -1,6 +1,6 @@ idf_component_register( SRCS operator.cpp tools.c trace.c - REQUIRES esp_common pthread - INCLUDE_DIRS . + REQUIRES _override esp_common pthread + INCLUDE_DIRS . ) #doing our own implementation of new operator for some pre-compiled binaries diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 50023cb7..11d1029f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register(SRC_DIRS . - PRIV_REQUIRES _override esp_common wifi-manager pthread squeezelite-ota platform_console telnet display + PRIV_REQUIRES esp_common wifi-manager pthread squeezelite-ota platform_console telnet display EMBED_FILES ../server_certs/github.pem LDFRAGMENTS "linker.lf" )