Skip to content

Commit

Permalink
Fix Render Map reading SD Shared SPI BUS
Browse files Browse the repository at this point in the history
  • Loading branch information
jgauchia committed Aug 9, 2024
1 parent 0a2aebc commit d56e77a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
2 changes: 0 additions & 2 deletions lib/gui/src/mainScr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ void getZoomValue(lv_event_t *event)
case LV_DIR_RIGHT:
break;
case LV_DIR_TOP:
tft.endTransaction();
if (!isVectorMap)
{
if (zoom >= minZoom && zoom < maxZoom)
Expand All @@ -229,7 +228,6 @@ void getZoomValue(lv_event_t *event)
lv_obj_send_event(mapTile, LV_EVENT_REFRESH, NULL);
break;
case LV_DIR_BOTTOM:
tft.endTransaction();
if (!isVectorMap)
{
if (zoom <= maxZoom && zoom > minZoom)
Expand Down
13 changes: 13 additions & 0 deletions lib/maps/src/renderMaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ void generateRenderMap()
deleteMapScrSprites();
createMapScrSprites();

#ifdef SPI_SHARED
tft.endTransaction();
tft.waitDisplay();
tft.releaseBus();
initSD();
#endif

mapTempSprite.fillScreen(TFT_BLACK);
isMapFound = mapTempSprite.drawPngFile(SD, currentMapTile.file, tileSize, tileSize);

Expand Down Expand Up @@ -132,6 +139,12 @@ void generateRenderMap()
redrawMap = true;
}

#ifdef SPI_SHARED
SD.end();
tft.initBus();
tft.beginTransaction();
#endif

log_v("TILE: %s", oldMapTile.file);
}
}
1 change: 1 addition & 0 deletions lib/maps/src/renderMaps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ uint32_t lat2tiley(double f_lat, uint8_t zoom);
MapTile getMapTile(double lon, double lat, uint8_t zoomLevel, int16_t offsetX, int16_t offsetY);
void drawMapWidgets();
void generateRenderMap();
void initSD();

#endif
6 changes: 3 additions & 3 deletions lib/panel/ILI9488_FT5x06_SPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ class LGFX : public lgfx::LGFX_Device
{
auto cfg = _bus_instance.config();
#ifdef ARDUINO_ESP32S3_DEV
cfg.spi_host = SPI3_HOST;
cfg.spi_host = SPI2_HOST;
#endif
#ifdef ARDUINO_ESP32_DEV
cfg.spi_host = HSPI_HOST;
#endif
cfg.spi_mode = 0;
cfg.freq_write = 79999999;
cfg.freq_read = 15000000;
cfg.freq_read = 40000000;
cfg.spi_3wire = false;
cfg.use_lock = false;
cfg.dma_channel = SPI_DMA_CH_AUTO;
cfg.dma_channel = 2;
cfg.pin_sclk = TFT_SPI_SCLK;
cfg.pin_mosi = TFT_SPI_MOSI;
cfg.pin_miso = TFT_SPI_MISO;
Expand Down
13 changes: 11 additions & 2 deletions lib/storage/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ extern const int SD_CLK;
*/
void initSD()
{
spiSD.begin(SD_CLK, SD_MISO, SD_MOSI, SD_CS);
bool SDInitOk = false;
pinMode(SD_CS,OUTPUT);
digitalWrite(SD_CS,LOW);
if (!SD.begin(SD_CS, spiSD)) //, sdFreq))

#ifdef SPI_SHARED
SDInitOk = SD.begin(SD_CS);
#endif
#ifndef SPI_SHARED
spiSD.begin(SD_CLK, SD_MISO, SD_MOSI, SD_CS);
SDInitOk = SD.begin(SD_CS, spiSD, sdFreq);
#endif

if (!SDInitOk)
{
log_e("SD Card Mount Failed");
return;
Expand Down
5 changes: 4 additions & 1 deletion lib/storage/storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#include <FS.h>
#include <SD.h>
#include <SPIFFS.h>
#include <LovyanGFX.hpp>
#include <tft.hpp>

#ifdef ARDUINO_ESP32S3_DEV
static SPIClass spiSD = SPIClass();
static SPIClass spiSD = SPIClass(HSPI);
static uint32_t sdFreq = 10000000;
#endif
#ifdef ARDUINO_ESP32_DEV
Expand All @@ -24,6 +26,7 @@ static uint32_t sdFreq = 40000000;

extern bool isSdLoaded;


void initSD();
void initSPIFFS();

Expand Down

0 comments on commit d56e77a

Please sign in to comment.